on main help sign in
chore(ui): standardize truncation message format
commit4665ad27daeb777fe519f7d8057c4dfea7923e9d authorAyman Bagabas <ayman.bagabas@gmail.com> dateFri 19 Dec 2025, 12:07 (1 year ago) parentee7137e
2 files changed+13−9
internal/ui/chat/assistant.go+6−2 internal/ui/chat/tools.go+7−7
internal/ui/chat/assistant.go+6−2
@@ -13,6 +13,10 @@ import (
1313 "github.com/charmbracelet/x/ansi"
1414)
1515
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+
1620// maxCollapsedThinkingHeight defines the maximum height of the thinking
1721const maxCollapsedThinkingHeight = 10
1822
@@ -153,9 +157,9 @@ func (a *AssistantMessageItem) renderThinking(thinking string, width int) string
153157 if !a.thinkingExpanded && isTruncated {
154158 lines = lines[totalLines-maxCollapsedThinkingHeight:]
155159 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),
157161 )
158− lines = append(lines, "", hint)
162+ lines = append([]string{hint, ""}, lines...)
159163 }
160164
161165 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
434434 if !expanded && wasTruncated {
435435 out = append(out, sty.Tool.ContentTruncation.
436436 Width(width).
437− Render(fmt.Sprintf("… (%d lines) [click or space to expand]", len(lines)-responseContextHeight)))
437+ Render(fmt.Sprintf(assistantMessageTruncateFormat, len(lines)-responseContextHeight)))
438438 }
439439
440440 return strings.Join(out, "\n")
@@ -489,8 +489,8 @@ func toolOutputCodeContent(sty *styles.Styles, path, content string, offset, wid
489489 if len(lines) > maxLines && !expanded {
490490 truncMsg := sty.Tool.ContentCodeTruncation.
491491 Width(bodyWidth).
492− Render(fmt.Sprintf("… (%d lines) [click or space to expand]", len(lines)-maxLines))
493− out = append(out, truncMsg)
492+ Render(fmt.Sprintf(assistantMessageTruncateFormat, len(lines)-maxLines))
493+ out = append([]string{truncMsg}, out...)
494494 }
495495
496496 return sty.Tool.Body.Render(strings.Join(out, "\n"))
@@ -567,8 +567,8 @@ func toolOutputDiffContent(sty *styles.Styles, file, oldContent, newContent stri
567567 if len(lines) > maxLines && !expanded {
568568 truncMsg := sty.Tool.DiffTruncation.
569569 Width(bodyWidth).
570− Render(fmt.Sprintf("… (%d lines) [click or space to expand]", len(lines)-maxLines))
571− formatted = strings.Join(lines[:maxLines], "\n") + "\n" + truncMsg
570+ Render(fmt.Sprintf(assistantMessageTruncateFormat, len(lines)-maxLines))
571+ formatted = truncMsg + "\n" + strings.Join(lines[:maxLines], "\n")
572572 }
573573
574574 return sty.Tool.Body.Render(formatted)
@@ -600,8 +600,8 @@ func toolOutputMultiEditDiffContent(sty *styles.Styles, file string, meta tools.
600600 if len(lines) > maxLines && !expanded {
601601 truncMsg := sty.Tool.DiffTruncation.
602602 Width(bodyWidth).
603− Render(fmt.Sprintf("… (%d lines) [click or space to expand]", len(lines)-maxLines))
604− formatted = strings.Join(lines[:maxLines], "\n") + "\n" + truncMsg
603+ Render(fmt.Sprintf(assistantMessageTruncateFormat, len(lines)-maxLines))
604+ formatted = truncMsg + "\n" + strings.Join(lines[:maxLines], "\n")
605605 }
606606
607607 // Add failed edits note if any exist.