diff options
| author | historia <[not public]> | 2026-10-06 12:57:23 -0400 |
|---|---|---|
| committer | historia <[not public]> | 2026-10-06 12:57:23 -0400 |
| commit | 9666676766bf21364f4fc4d0d1d336e72f2a91b4 (patch) | |
| tree | 0cade34091d7602790dc38cd44053f0b74bbadf2 /internal/color | |
| parent | 4bc1daaf259e0c19c5fe4a12ec8bc7f6e5a735c1 (diff) | |
| download | thehouseoficarus-9666676766bf21364f4fc4d0d1d336e72f2a91b4.tar.gz | |
refactor: split casino.go, dedup helpers, remove audit docs
Diffstat (limited to 'internal/color')
| -rw-r--r-- | internal/color/color.go | 21 |
1 files changed, 19 insertions, 2 deletions
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) { |
