From feef990b565cc686893c085e30481f195fa87d20 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sat, 9 Mar 2024 18:15:42 -0800 Subject: [PATCH] Fixes for unicode in Web terminal This is very partial, and my experience shows that the terminal renders these poorly at best; in particular spacing in the DOM model seems to be unpredictable with emoji and some of the esoteric combining characters. Still this represents a significant improvement by actually including the combining characters. Plus it is faster. --- webfiles/tcell.js | 11 +++-------- wscreen.go | 13 +++++++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/webfiles/tcell.js b/webfiles/tcell.js index 5e17b52..0ffaf22 100644 --- a/webfiles/tcell.js +++ b/webfiles/tcell.js @@ -61,12 +61,7 @@ function clearScreen(fg, bg) { } } -function drawCell(x, y, mainc, combc, fg, bg, attrs, us, uc) { - var combString = String.fromCharCode(mainc); - combc.forEach((char) => { - combString += String.fromCharCode(char); - }); - +function drawCell(x, y, s, fg, bg, attrs, us, uc) { var span = document.createElement("span"); var use = false; @@ -123,11 +118,11 @@ function drawCell(x, y, mainc, combc, fg, bg, attrs, us, uc) { if ((attrs & (1 << 1)) != 0) { var blink = document.createElement("span"); blink.classList.add("blink"); - var textnode = document.createTextNode(combString); + var textnode = document.createTextNode(s); blink.appendChild(textnode); span.appendChild(blink); } else { - var textnode = document.createTextNode(combString); + var textnode = document.createTextNode(s); span.appendChild(textnode); } diff --git a/wscreen.go b/wscreen.go index ebcb7e9..8f66079 100644 --- a/wscreen.go +++ b/wscreen.go @@ -143,13 +143,18 @@ func (t *wScreen) drawCell(x, y int) int { uc = 0x000000 } - var combcarr []interface{} = make([]interface{}, len(combc)) - for i, c := range combc { - combcarr[i] = c + s := "" + if len(combc) > 0 { + b := make([]rune, 0, 1 + len(combc)) + b = append(b, mainc) + b = append(b, combc...) + s = string(b) + } else { + s = string(mainc) } t.cells.SetDirty(x, y, false) - js.Global().Call("drawCell", x, y, mainc, combcarr, fg, bg, int(style.attrs), int(us), int(uc)) + js.Global().Call("drawCell", x, y, s, fg, bg, int(style.attrs), int(us), int(uc)) return width }