Files
barnard/uiterm/label.go
T
Brandon McGintyandClaude Opus 5 17a4662c6c strip terminal control sequences from server-supplied text
Remove control, DEL, and bidi characters before display.
HTML escaping was the only filter, which leaves ANSI and OSC escape
sequences intact. A remote user could move the cursor, recolour the
screen, or reorder what was shown by putting escape codes in a
message, a nickname, or a channel name. Names rendered in the channel
tree go through the same filter now.

Keep the text box cursor and the prompt on rune boundaries.
Both indexed by byte, so editing a line containing multi-byte
characters could split one and render replacement characters.

Handle text view lines that carry no timestamp.
Toggling timestamps assumed every stored line had one and sliced past
the end of lines that did not.

Ignore key events on an empty tree.
The handlers indexed the item list before checking that it had any
items.

Remove the beep helpers.
They shelled out to an optional "beep" binary and panicked when it was
absent.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-20 14:42:52 -04:00

55 lines
844 B
Go

package uiterm
import (
"strings"
"github.com/nsf/termbox-go"
)
type Label struct {
Text string
Fg, Bg Attribute
ui *Ui
x0, y0, x1, y1 int
}
func (l *Label) uiInitialize(ui *Ui) {
l.ui = ui
}
func (l *Label) uiSetActive(active bool) {
}
func (l *Label) uiSetBounds(x0, y0, x1, y1 int) {
l.x0 = x0
l.y0 = y0
l.x1 = x1
l.y1 = y1
l.uiDraw()
}
func (l *Label) uiDraw() {
l.ui.beginDraw()
defer l.ui.endDraw()
reader := strings.NewReader(l.Text)
for y := l.y0; y < l.y1; y++ {
for x := l.x0; x < l.x1; x++ {
var chr rune
if ch, _, err := reader.ReadRune(); err != nil {
chr = ' '
} else {
chr = safeRune(ch)
}
termbox.SetCell(x, y, chr, termbox.Attribute(l.Fg), termbox.Attribute(l.Bg))
}
}
}
func (l *Label) uiKeyEvent(key Key) {
}
func (l *Label) uiCharacterEvent(chr rune) {
}