From 81f6648f6436a565b1bd8730eb5c1ad25e97a3fe Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Tue, 5 Mar 2024 02:40:30 -0800 Subject: [PATCH] Underline colors for webassembly. --- webfiles/tcell.js | 25 ++++++++++++++----------- wscreen.go | 9 ++++++++- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/webfiles/tcell.js b/webfiles/tcell.js index d3ec2ce..44c76cc 100644 --- a/webfiles/tcell.js +++ b/webfiles/tcell.js @@ -60,7 +60,7 @@ function clearScreen(fg, bg) { } } -function drawCell(x, y, mainc, combc, fg, bg, attrs) { +function drawCell(x, y, mainc, combc, fg, bg, attrs, us, uc) { var combString = String.fromCharCode(mainc); combc.forEach((char) => { combString += String.fromCharCode(char); @@ -91,9 +91,6 @@ function drawCell(x, y, mainc, combc, fg, bg, attrs) { if ((attrs & 1) != 0) { span.classList.add("bold"); } - if ((attrs & (1 << 3)) != 0) { - span.classList.add("underline"); - } if ((attrs & (1 << 4)) != 0) { span.classList.add("dim"); } @@ -103,19 +100,25 @@ function drawCell(x, y, mainc, combc, fg, bg, attrs) { if ((attrs & (1 << 6)) != 0) { span.classList.add("strikethrough"); } - if ((attrs & (1 << 7)) != 0) { + } + if (us != 0) { + use = true; + if (us == 1) { + span.classList.add("underline"); + } else if (us == 2) { span.classList.add("double_underline"); - } - if ((attrs & (1 << 8)) != 0) { + } else if (us == 3) { span.classList.add("curly_underline"); - } - if ((attrs & (1 << 9)) != 0) { + } else if (us == 4) { span.classList.add("dotted_underline"); - } - if ((attrs & (1 << 10)) != 0) { + } else if (us == 5) { span.classList.add("dashed_underline"); } + if (uc != -1) { + span.style.textDecorationColor = intToHex(uc); + } } + if ((attrs & (1 << 1)) != 0) { var blink = document.createElement("span"); blink.classList.add("blink"); diff --git a/wscreen.go b/wscreen.go index c427f7b..387e48b 100644 --- a/wscreen.go +++ b/wscreen.go @@ -66,6 +66,9 @@ func (t *wScreen) Init() error { t.Unlock() js.Global().Set("onKeyEvent", js.FuncOf(t.onKeyEvent)) + js.Global().Set("onMouseClick", js.FuncOf(t.unset)) + js.Global().Set("onMouseMove", js.FuncOf(t.unset)) + js.Global().Set("onFocus", js.FuncOf(t.unset)) return nil } @@ -133,6 +136,10 @@ func (t *wScreen) drawCell(x, y int) int { if bg == -1 { bg = 0x000000 } + us, uc := style.ulStyle, paletteColor(style.ulColor) + if uc == -1 { + uc = 0x000000 + } var combcarr []interface{} = make([]interface{}, len(combc)) for i, c := range combc { @@ -140,7 +147,7 @@ func (t *wScreen) drawCell(x, y int) int { } t.cells.SetDirty(x, y, false) - js.Global().Call("drawCell", x, y, mainc, combcarr, fg, bg, int(style.attrs)) + js.Global().Call("drawCell", x, y, mainc, combcarr, fg, bg, int(style.attrs), int(us), int(uc)) return width }