Webasm terminal fixes.

Reverse video, not reverse text.
Provide an XTERM equivalent default palette.
Reset colors should go to silver on black.
Black color 0 should be rendered properly.
This commit is contained in:
Garrett D'Amore 2023-02-20 21:12:03 -08:00
parent d78960c02d
commit 7fe9d5fa9b
3 changed files with 48 additions and 6 deletions

View File

@ -62,14 +62,19 @@ function drawCell(x, y, mainc, combc, fg, bg, attrs) {
var span = document.createElement("span")
var use = false
if (fg) { span.style.color = intToHex(fg); use = true }
if (bg) { span.style.backgroundColor = intToHex(bg); use = true }
if ((attrs & (1<<2)) != 0) { // reverse video
var temp = bg
bg = fg
fg = temp
use = true
}
if (fg != -1) { span.style.color = intToHex(fg); use = true }
if (bg != -1) { span.style.backgroundColor = intToHex(bg); use = true }
if (attrs != 0) {
use = true
if ((attrs & 1) != 0) { span.classList.add("bold") }
if ((attrs & (1<<1)) != 0) { span.classList.add("blink") }
if ((attrs & (1<<2)) != 0) { span.classList.add("reverse") }
if ((attrs & (1<<3)) != 0) { span.classList.add("underline") }
if ((attrs & (1<<4)) != 0) { span.classList.add("dim") }
if ((attrs & (1<<5)) != 0) { span.classList.add("italic") }

View File

@ -25,8 +25,6 @@
.blink { animation: blinker 1s step-start infinite; }
.reverse { unicode-bidi: bidi-override; direction: rtl; }
.underline { text-decoration: underline; }
.dim { filter: brightness(50) }

View File

@ -109,6 +109,39 @@ func (t *wScreen) SetCell(x, y int, style Style, ch ...rune) {
}
}
// paletteColor gives a more natural palette color actually matching
// typical XTerm. We might in the future want to permit styling these
// via CSS.
var palette = map[Color]int32{
ColorBlack: 0x000000,
ColorMaroon: 0xcd0000,
ColorGreen: 0x00cd00,
ColorOlive: 0xcdcd00,
ColorNavy: 0x0000ee,
ColorPurple: 0xcd00cd,
ColorTeal: 0x00cdcd,
ColorSilver: 0xe5e5e5,
ColorGray: 0x7f7f7f,
ColorRed: 0xff0000,
ColorLime: 0x00ff00,
ColorYellow: 0xffff00,
ColorBlue: 0x5c5cff,
ColorFuchsia: 0xff00ff,
ColorAqua: 0x00ffff,
ColorWhite: 0xffffff,
}
func paletteColor(c Color) int32 {
if (c.IsRGB()) {
return int32(c & 0xffffff);
}
if (c >= ColorBlack && c <= ColorWhite) {
return palette[c]
}
return c.Hex()
}
func (t *wScreen) drawCell(x, y int) int {
mainc, combc, style, width := t.cells.GetContent(x, y)
@ -120,7 +153,13 @@ func (t *wScreen) drawCell(x, y int) int {
style = t.style
}
fg, bg := style.fg.Hex(), style.bg.Hex()
fg, bg := paletteColor(style.fg), paletteColor(style.bg)
if (fg == -1) {
fg = 0xe5e5e5;
}
if (bg == -1) {
bg = 0x000000;
}
var combcarr []interface{} = make([]interface{}, len(combc))
for i, c := range combc {