Skip to content

Commit 038317e

Browse files
committed
fix: truncate feed pane lines to prevent terminal wrapping
Three changes to stop the right pane from pushing the header off-screen: 1. joinPanesHorizontally: clamp maxLines to left-pane count so the feed can never make the output taller than the left pane, and truncate right-pane lines to rightW via ansiTruncate. 2. padAndJoinLines: truncate any line wider than width before padding, preventing over-wide styled content from wrapping. 3. renderFeed: use lipgloss.Width + ansiTruncate for task and result line truncation instead of byte-length len(), which mis-measures strings containing multi-byte characters or ANSI codes.
1 parent 88021b7 commit 038317e

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

cmd/kubeclaw/main.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3997,8 +3997,8 @@ func (m tuiModel) renderFeed(width, height int) string {
39973997
if maxTaskW < 10 {
39983998
maxTaskW = 10
39993999
}
4000-
if len(task) > maxTaskW {
4001-
task = task[:maxTaskW-3] + "..."
4000+
if lipgloss.Width(task) > maxTaskW {
4001+
task = ansiTruncate(task, maxTaskW-3) + "..."
40024002
}
40034003
allLines = append(allLines, tuiFeedPromptStyle.Render(" ▸ "+task))
40044004

@@ -4020,8 +4020,8 @@ func (m tuiModel) renderFeed(width, height int) string {
40204020
break
40214021
}
40224022
rl = strings.TrimRight(rl, " \t\r")
4023-
if len(rl) > width-5 {
4024-
rl = rl[:width-8] + "..."
4023+
if lipgloss.Width(rl) > width-5 {
4024+
rl = ansiTruncate(rl, width-8) + "..."
40254025
}
40264026
allLines = append(allLines, tuiSuccessStyle.Render(" "+rl))
40274027
shown++
@@ -4109,8 +4109,8 @@ func (m tuiModel) renderFeedFullscreen() string {
41094109
if maxTaskW < 10 {
41104110
maxTaskW = 10
41114111
}
4112-
if len(task) > maxTaskW {
4113-
task = task[:maxTaskW-3] + "..."
4112+
if lipgloss.Width(task) > maxTaskW {
4113+
task = ansiTruncate(task, maxTaskW-3) + "..."
41144114
}
41154115
allLines = append(allLines, tuiFeedPromptStyle.Render(" ▸ "+task))
41164116

@@ -4225,6 +4225,10 @@ func padAndJoinLines(lines []string, width int) string {
42254225
var b strings.Builder
42264226
for i, line := range lines {
42274227
w := lipgloss.Width(line)
4228+
if w > width {
4229+
line = ansiTruncate(line, width)
4230+
w = lipgloss.Width(line)
4231+
}
42284232
if w < width {
42294233
line += strings.Repeat(" ", width-w)
42304234
}
@@ -5482,10 +5486,8 @@ func joinPanesHorizontally(left, right string, leftW, rightW int) string {
54825486

54835487
sepStr := lipgloss.NewStyle().Foreground(lipgloss.Color("#313244")).Render("│")
54845488

5489+
// Never let the right pane make the output taller than the left.
54855490
maxLines := len(leftLines)
5486-
if len(rightLines) > maxLines {
5487-
maxLines = len(rightLines)
5488-
}
54895491

54905492
var b strings.Builder
54915493
for i := 0; i < maxLines; i++ {
@@ -5496,8 +5498,7 @@ func joinPanesHorizontally(left, right string, leftW, rightW int) string {
54965498
if i < len(rightLines) {
54975499
r = rightLines[i]
54985500
}
5499-
// Truncate left line if it exceeds leftW (table rows may be wider),
5500-
// preserving ANSI escape codes so styles (selected row, etc.) survive.
5501+
// Truncate left line if it exceeds leftW.
55015502
lw := lipgloss.Width(l)
55025503
if lw > leftW {
55035504
l = ansiTruncate(l, leftW)
@@ -5506,6 +5507,11 @@ func joinPanesHorizontally(left, right string, leftW, rightW int) string {
55065507
if lw < leftW {
55075508
l += strings.Repeat(" ", leftW-lw)
55085509
}
5510+
// Truncate right line if it exceeds rightW to prevent terminal wrapping.
5511+
rw := lipgloss.Width(r)
5512+
if rw > rightW {
5513+
r = ansiTruncate(r, rightW)
5514+
}
55095515
b.WriteString(l + sepStr + r)
55105516
if i < maxLines-1 {
55115517
b.WriteString("\n")

0 commit comments

Comments
 (0)