From 7fe9d5fa9b715b1b25f71757c8e862ef9b2ba3ab Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Mon, 20 Feb 2023 21:12:03 -0800 Subject: [PATCH] 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. --- webfiles/tcell.js | 11 ++++++++--- webfiles/termstyle.css | 2 -- wscreen.go | 41 ++++++++++++++++++++++++++++++++++++++++- 3 files changed, 48 insertions(+), 6 deletions(-) diff --git a/webfiles/tcell.js b/webfiles/tcell.js index 67acd72..9cadd72 100644 --- a/webfiles/tcell.js +++ b/webfiles/tcell.js @@ -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") } diff --git a/webfiles/termstyle.css b/webfiles/termstyle.css index 5ec1d13..b5c6502 100644 --- a/webfiles/termstyle.css +++ b/webfiles/termstyle.css @@ -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) } diff --git a/wscreen.go b/wscreen.go index de6cd22..0804720 100644 --- a/wscreen.go +++ b/wscreen.go @@ -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 {