MCPcopy Create free account
hub / github.com/B33pBeeps/redthread / effectiveStyleAt

Function effectiveStyleAt

internal/app/render.go:328–359  ·  view source on GitHub ↗

effectiveStyleAt returns the SGR sequence active at visual column `col` within string `s` — i.e., the last CSI seen before that column. An empty return means no style was active (terminal default).

(s string, col int)

Source from the content-addressed store, hash-verified

326// within string `s` — i.e., the last CSI seen before that column. An
327// empty return means no style was active (terminal default).
328func effectiveStyleAt(s string, col int) string {
329 last := ""
330 visible := 0
331 i := 0
332 for i < len(s) {
333 if s[i] == '\x1b' && i+1 < len(s) {
334 j := i + 2
335 for j < len(s) {
336 ch := s[j]
337 if (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') {
338 j++
339 break
340 }
341 j++
342 }
343 last = s[i:j]
344 i = j
345 continue
346 }
347 if visible >= col {
348 break
349 }
350 _, size := utf8Decode(s[i:])
351 if size == 0 {
352 i++
353 continue
354 }
355 i += size
356 visible++
357 }
358 return last
359}
360
361// SpliceOverlay splices `overlay` onto `bg` at visual cell position
362// (x, y). Both strings are newline-separated; ANSI CSI escapes are

Callers 1

SpliceOverlayFunction · 0.85

Calls 1

utf8DecodeFunction · 0.85

Tested by

no test coverage detected