MCPcopy Create free account
hub / github.com/codehamr/codehamr / wrapForScrollback

Function wrapForScrollback

internal/tui/render.go:48–64  ·  view source on GitHub ↗

wrapForScrollback hard-wraps every line of s to the terminal width before it goes to tea.Println. bubbletea's standard renderer dumps queued Println lines verbatim - unlike its View paint path it never truncates them - so a line wider than the terminal is soft-wrapped by the terminal into extra phys

(s string, width int)

Source from the content-addressed store, hash-verified

46// wider than the terminal is soft-wrapped by the terminal into extra physical
47// rows the renderer never counted. Its cursor math then drifts and the prior
48// frame's wrapped textarea rows survive un-erased: the duplicated prompt
49// fragment seen when submitting a long prompt. Mirrors the ansi.Wrap the live
50// streaming view already applies. width <= 0 (no WindowSizeMsg yet) is a no-op.
51func wrapForScrollback(s string, width int) string {
52 if width <= 0 {
53 return s
54 }
55 // Terminals advance a literal tab to the next 8-column stop, but ansi.Wrap
56 // counts it as one cell, so a tab-bearing line (glamour preserves tabs
57 // inside code fences; a user echo can carry pasted ones) passes the width
58 // check yet physically overflows - the exact drift this wrap exists to
59 // prevent. Expand before counting; \t never occurs inside an ANSI escape
60 // sequence, so a plain replace is safe on styled strings.
61 s = strings.ReplaceAll(s, "\t", " ")
62 lines := strings.Split(s, "\n")
63 for i, line := range lines {
64 lines[i] = ansi.Wrap(line, width, "")
65 }
66 return strings.Join(lines, "\n")
67}

Calls

no outgoing calls