fix: hard-wrap history output to terminal width
Lines wider than the terminal (wide markdown tables, long code lines) were soft-wrapped by the terminal but counted as one row by Ink's <Static> redraw, desyncing its cursor math and stranding duplicate copies of the status bar and input box in scrollback on every re-render. renderMarkdown now wraps its output to the caller's width via wrap-ansi, and every <Static> item (plus the live streaming line) is held within a width-bounded Box so nothing the terminal would soft-wrap reaches Ink. Also sets cli-table3 header color to yellow (red-on-blue themes made table headers unreadable). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c649fdf6ed
commit
c36b45e9d5
6 files changed
+29
-5
No files matched your search
Generated
+2
-1
@@ -27,6 +27,7 @@
|
||||
"tree-kill": "^1.2.2",
|
||||
"vscode-languageserver-protocol": "^3.18.2",
|
||||
"vscode-uri": "^3.1.0",
|
||||
"wrap-ansi": "^7.0.0",
|
||||
"zod": "^4.4.3"
|
||||
},
|
||||
"bin": {
|
||||
@@ -42,7 +43,7 @@
|
||||
"vitest": "^4.1.11"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=20"
|
||||
"node": ">=22.12.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@alcalzone/ansi-tokenize": {
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
"tree-kill": "^1.2.2",
|
||||
"vscode-languageserver-protocol": "^3.18.2",
|
||||
"vscode-uri": "^3.1.0",
|
||||
"wrap-ansi": "^7.0.0",
|
||||
"zod": "^4.4.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
+14
-2
@@ -185,6 +185,10 @@ export function App({
|
||||
// fixed width on the right — ChatInput can't derive this from its own measured width (see the
|
||||
// comment on its availableColumns prop), so it's computed once here and threaded down.
|
||||
const chatColumns = terminalColumns - (filePanelVisible ? FILE_PANEL_WIDTH : 0);
|
||||
// Width every printed history line is held within, so nothing the terminal would soft-wrap
|
||||
// reaches Ink's <Static> — a soft-wrapped line desyncs Ink's redraw accounting and leaves
|
||||
// stranded copies of the status bar / input box in scrollback (see renderMarkdown).
|
||||
const contentWidth = Math.max(20, chatColumns);
|
||||
|
||||
const flushStreamingText = useCallback(() => {
|
||||
const accumulated = streamingAccumulatorRef.current;
|
||||
@@ -1049,11 +1053,19 @@ export function App({
|
||||
* re-rendered, never height-clipped — which is what makes the terminal's own native mouse
|
||||
* wheel scroll and click-drag text selection/copy work with zero app-side mouse tracking or
|
||||
* virtual-scroll code (see index.tsx for why locode also stays off the alternate screen). */}
|
||||
<Static items={staticItems}>{(item) => <HistoryItemView key={item.id} item={item} />}</Static>
|
||||
<Static items={staticItems}>
|
||||
{(item) => (
|
||||
<Box key={item.id} width={contentWidth} flexShrink={0}>
|
||||
<HistoryItemView item={item} width={contentWidth} />
|
||||
</Box>
|
||||
)}
|
||||
</Static>
|
||||
<Box flexDirection="row" width="100%" alignItems="flex-end">
|
||||
<Box flexDirection="column" flexGrow={1} flexShrink={1}>
|
||||
{streamingText !== null && (
|
||||
<HistoryItemView item={{ id: "streaming", kind: "streaming_text", text: streamingText }} />
|
||||
<Box width={contentWidth} flexShrink={0}>
|
||||
<HistoryItemView item={{ id: "streaming", kind: "streaming_text", text: streamingText }} width={contentWidth} />
|
||||
</Box>
|
||||
)}
|
||||
{isThinking && streamingText === null && !permission && !exportPrompt && (
|
||||
<ThinkingIndicator label={runningToolIsBash ? "thinking... (ctrl+b to background)" : undefined} />
|
||||
|
||||
@@ -54,7 +54,7 @@ function formatDuration(ms: number): string {
|
||||
// "assistant" ones, whose renderMarkdown call is real CPU work) gets its render function
|
||||
// re-invoked on every parent re-render — which happens on every ThinkingIndicator spinner tick
|
||||
// and every throttled streaming-text frame — even though nothing about that item changed.
|
||||
export const HistoryItemView = memo(function HistoryItemView({ item }: { item: HistoryItem }) {
|
||||
export const HistoryItemView = memo(function HistoryItemView({ item, width }: { item: HistoryItem; width?: number }) {
|
||||
switch (item.kind) {
|
||||
case "banner":
|
||||
return (
|
||||
@@ -185,7 +185,7 @@ export const HistoryItemView = memo(function HistoryItemView({ item }: { item: H
|
||||
);
|
||||
|
||||
case "assistant":
|
||||
return <Text>{renderMarkdown(item.text)}</Text>;
|
||||
return <Text>{renderMarkdown(item.text, width)}</Text>;
|
||||
|
||||
case "thinking":
|
||||
// Dimmed, collapsible-style rendering for reasoning/thinking blocks
|
||||
|
||||
Binary file not shown.
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
// wrap-ansi v7 ships no type declarations and has no @types package (types were added upstream in
|
||||
// v8, which is ESM-only). This project pins v7 to share the copy Ink already installs.
|
||||
declare module "wrap-ansi" {
|
||||
interface Options {
|
||||
readonly hard?: boolean;
|
||||
readonly wordWrap?: boolean;
|
||||
readonly trim?: boolean;
|
||||
}
|
||||
export default function wrapAnsi(input: string, columns: number, options?: Options): string;
|
||||
}
|
||||
Reference in new issue
Block a user