Skip to content

Commit

Permalink
Fixes for unicode in Web terminal
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gdamore committed Mar 10, 2024
1 parent c9ba0cf commit feef990
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
11 changes: 3 additions & 8 deletions webfiles/tcell.js
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}

Expand Down
13 changes: 9 additions & 4 deletions wscreen.go
Expand Up @@ -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
}
Expand Down

0 comments on commit feef990

Please sign in to comment.