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

Function StyleViewText

internal/app/theme.go:393–425  ·  view source on GitHub ↗

StyleViewText applies styleRune to a pre-rendered string while passing through ANSI CSI escape sequences untouched. Useful when post-processing the output of a third-party widget (e.g. bubbles/textarea) so the visible glyphs reflect the board's font without breaking cursor highlighting.

(s string, mode TextStyleMode)

Source from the content-addressed store, hash-verified

391// the output of a third-party widget (e.g. bubbles/textarea) so the visible
392// glyphs reflect the board's font without breaking cursor highlighting.
393func StyleViewText(s string, mode TextStyleMode) string {
394 if mode == TextPlain {
395 return s
396 }
397 var b strings.Builder
398 b.Grow(len(s) * 4)
399 i := 0
400 for i < len(s) {
401 if s[i] == '\x1b' && i+1 < len(s) {
402 j := i + 2
403 for j < len(s) {
404 ch := s[j]
405 if (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') {
406 j++
407 break
408 }
409 j++
410 }
411 b.WriteString(s[i:j])
412 i = j
413 continue
414 }
415 r, size := utf8Decode(s[i:])
416 if size == 0 {
417 b.WriteByte(s[i])
418 i++
419 continue
420 }
421 b.WriteRune(styleRune(r, mode))
422 i += size
423 }
424 return b.String()
425}
426
427// styleRune — Unicode block offsets:
428//

Callers 1

ViewMethod · 0.85

Calls 2

utf8DecodeFunction · 0.85
styleRuneFunction · 0.85

Tested by

no test coverage detected