on main help sign in
chore(ui): standardize truncation message format
4665ad2Ayman Bagabas
internal/ui/chat/assistant.go+6−2
@@ -13,6 +13,10 @@ import (
13 "github.com/charmbracelet/x/ansi"
13 "github.com/charmbracelet/x/ansi"
14)
14)
15
15
16+// assistantMessageTruncateFormat is the text shown when an assistant message is
17+// truncated.
18+const assistantMessageTruncateFormat = "… (%d lines hidden) [click or space to expand]"
19+
16// maxCollapsedThinkingHeight defines the maximum height of the thinking
20// maxCollapsedThinkingHeight defines the maximum height of the thinking
17const maxCollapsedThinkingHeight = 10
21const maxCollapsedThinkingHeight = 10
18
22
@@ -153,9 +157,9 @@ func (a *AssistantMessageItem) renderThinking(thinking string, width int) string
153 if !a.thinkingExpanded && isTruncated {
157 if !a.thinkingExpanded && isTruncated {
154 lines = lines[totalLines-maxCollapsedThinkingHeight:]
158 lines = lines[totalLines-maxCollapsedThinkingHeight:]
155 hint := a.sty.Chat.Message.ThinkingTruncationHint.Render(
159 hint := a.sty.Chat.Message.ThinkingTruncationHint.Render(
156− fmt.Sprintf("… (%d lines hidden) [click or space to expand]", totalLines-maxCollapsedThinkingHeight),
160+ fmt.Sprintf(assistantMessageTruncateFormat, totalLines-maxCollapsedThinkingHeight),
157 )
161 )
158− lines = append(lines, "", hint)
162+ lines = append([]string{hint, ""}, lines...)
159 }
163 }
160
164
161 thinkingStyle := a.sty.Chat.Message.ThinkingBox.Width(width)
165 thinkingStyle := a.sty.Chat.Message.ThinkingBox.Width(width)
internal/ui/chat/tools.go+7−7
@@ -434,7 +434,7 @@ func toolOutputPlainContent(sty *styles.Styles, content string, width int, expan
434 if !expanded && wasTruncated {
434 if !expanded && wasTruncated {
435 out = append(out, sty.Tool.ContentTruncation.
435 out = append(out, sty.Tool.ContentTruncation.
436 Width(width).
436 Width(width).
437− Render(fmt.Sprintf("… (%d lines) [click or space to expand]", len(lines)-responseContextHeight)))
437+ Render(fmt.Sprintf(assistantMessageTruncateFormat, len(lines)-responseContextHeight)))
438 }
438 }
439
439
440 return strings.Join(out, "\n")
440 return strings.Join(out, "\n")
@@ -489,8 +489,8 @@ func toolOutputCodeContent(sty *styles.Styles, path, content string, offset, wid
489 if len(lines) > maxLines && !expanded {
489 if len(lines) > maxLines && !expanded {
490 truncMsg := sty.Tool.ContentCodeTruncation.
490 truncMsg := sty.Tool.ContentCodeTruncation.
491 Width(bodyWidth).
491 Width(bodyWidth).
492− Render(fmt.Sprintf("… (%d lines) [click or space to expand]", len(lines)-maxLines))
492+ Render(fmt.Sprintf(assistantMessageTruncateFormat, len(lines)-maxLines))
493− out = append(out, truncMsg)
493+ out = append([]string{truncMsg}, out...)
494 }
494 }
495
495
496 return sty.Tool.Body.Render(strings.Join(out, "\n"))
496 return sty.Tool.Body.Render(strings.Join(out, "\n"))
@@ -567,8 +567,8 @@ func toolOutputDiffContent(sty *styles.Styles, file, oldContent, newContent stri
567 if len(lines) > maxLines && !expanded {
567 if len(lines) > maxLines && !expanded {
568 truncMsg := sty.Tool.DiffTruncation.
568 truncMsg := sty.Tool.DiffTruncation.
569 Width(bodyWidth).
569 Width(bodyWidth).
570− Render(fmt.Sprintf("… (%d lines) [click or space to expand]", len(lines)-maxLines))
570+ Render(fmt.Sprintf(assistantMessageTruncateFormat, len(lines)-maxLines))
571− formatted = strings.Join(lines[:maxLines], "\n") + "\n" + truncMsg
571+ formatted = truncMsg + "\n" + strings.Join(lines[:maxLines], "\n")
572 }
572 }
573
573
574 return sty.Tool.Body.Render(formatted)
574 return sty.Tool.Body.Render(formatted)
@@ -600,8 +600,8 @@ func toolOutputMultiEditDiffContent(sty *styles.Styles, file string, meta tools.
600 if len(lines) > maxLines && !expanded {
600 if len(lines) > maxLines && !expanded {
601 truncMsg := sty.Tool.DiffTruncation.
601 truncMsg := sty.Tool.DiffTruncation.
602 Width(bodyWidth).
602 Width(bodyWidth).
603− Render(fmt.Sprintf("… (%d lines) [click or space to expand]", len(lines)-maxLines))
603+ Render(fmt.Sprintf(assistantMessageTruncateFormat, len(lines)-maxLines))
604− formatted = strings.Join(lines[:maxLines], "\n") + "\n" + truncMsg
604+ formatted = truncMsg + "\n" + strings.Join(lines[:maxLines], "\n")
605 }
605 }
606
606
607 // Add failed edits note if any exist.
607 // Add failed edits note if any exist.