From 9666676766bf21364f4fc4d0d1d336e72f2a91b4 Mon Sep 17 00:00:00 2001 From: historia <[not public]> Date: Tue, 6 Oct 2026 12:57:23 -0400 Subject: refactor: split casino.go, dedup helpers, remove audit docs --- internal/color/color.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'internal/color') diff --git a/internal/color/color.go b/internal/color/color.go index ff47a47..8376dde 100644 --- a/internal/color/color.go +++ b/internal/color/color.go @@ -36,7 +36,18 @@ var ansi16RGB = [16][3]int{ var cubeValues = [6]int{0, 95, 135, 175, 215, 255} +// Plain reports whether a color mode renders no color. The empty mode and +// "none" are equivalent (Render treats both as plain), so callers should use +// this instead of open-coding the pair. +func Plain(mode string) bool { return mode == "" || mode == "none" } + func Xterm256ToRGB(index int) (int, int, int) { + if index < 0 { + index = 0 + } + if index > 255 { + index = 255 + } if index < 16 { return ansi16RGB[index][0], ansi16RGB[index][1], ansi16RGB[index][2] } @@ -205,8 +216,14 @@ func TruncateVisible(s string, maxVisible int, unicode bool) string { } var pre, suf string rest := s - if idx := strings.IndexByte(rest, 'm'); idx >= 0 && strings.HasPrefix(rest, "\x1b[") { - pre = rest[:idx+1] + // Render emits style and foreground as separate SGR sequences; peel every + // leading one, not just the first, or the second is counted as visible text. + for strings.HasPrefix(rest, "\x1b[") { + idx := strings.IndexByte(rest, 'm') + if idx < 0 { + break + } + pre += rest[:idx+1] rest = rest[idx+1:] } if strings.HasSuffix(rest, Reset) { -- cgit v1.2.3