Skip to content

Commit 377e041

Browse files
committed
fix: the new left margin need to be included in width calculations
1 parent 34ea71f commit 377e041

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

packages/cli/src/tests/message-view.test.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,19 @@ test("renderMessageToStdout shows (no content) for empty user messages", () => {
127127
});
128128

129129
test("MessageView echoes submitted user prompts with live prompt wrapping width", () => {
130-
assert.equal(getPromptEchoContentWidth(8), 6);
130+
assert.equal(getPromptEchoContentWidth(8), 5);
131131

132132
const msg = makeSessionMessage({ role: "user", content: "abcdefg" });
133133
const output = renderToString(React.createElement(MessageView, { message: msg, width: 8 }), { columns: 8 });
134134

135-
assert.equal(stripAnsi(output), " > abcdef\n g\n");
135+
const text = stripAnsi(output);
136+
assert.equal(text, " > abcde\n fg\n");
137+
assert.ok(
138+
text
139+
.trimEnd()
140+
.split("\n")
141+
.every((line) => line.length <= 8)
142+
);
136143
});
137144

138145
test("MessageView echoes model changes with submitted prompt wrapping", () => {
@@ -143,7 +150,14 @@ test("MessageView echoes model changes with submitted prompt wrapping", () => {
143150
});
144151
const output = renderToString(React.createElement(MessageView, { message: msg, width: 8 }), { columns: 8 });
145152

146-
assert.equal(stripAnsi(output), " > abcdef\n gh\n");
153+
const text = stripAnsi(output);
154+
assert.equal(text, " > abcde\n fgh\n");
155+
assert.ok(
156+
text
157+
.trimEnd()
158+
.split("\n")
159+
.every((line) => line.length <= 8)
160+
);
147161
});
148162

149163
test("renderMessageToStdout renders assistant non-thinking messages with ✦", () => {

packages/cli/src/ui/components/MessageView/index.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import type { DiffPreviewLine, MessageViewProps } from "./types";
1313
import { RawMode, useRawModeContext } from "../../contexts";
1414

1515
const PROMPT_ECHO_PREFIX_WIDTH = 2;
16+
const PROMPT_ECHO_MARGIN_LEFT = 1;
1617

1718
export function MessageView({ message, collapsed, width = 80 }: MessageViewProps): React.ReactElement | null {
1819
const { mode } = useRawModeContext();
@@ -131,7 +132,7 @@ export function MessageView({ message, collapsed, width = 80 }: MessageViewProps
131132
}
132133

133134
export function getPromptEchoContentWidth(width: number): number {
134-
return Math.max(1, width - PROMPT_ECHO_PREFIX_WIDTH);
135+
return Math.max(1, width - PROMPT_ECHO_MARGIN_LEFT - PROMPT_ECHO_PREFIX_WIDTH);
135136
}
136137

137138
function PromptEchoLine({
@@ -144,8 +145,9 @@ function PromptEchoLine({
144145
attachmentCount?: number;
145146
}): React.ReactElement {
146147
const contentWidth = getPromptEchoContentWidth(width);
148+
const containerWidth = Math.max(1, width - PROMPT_ECHO_MARGIN_LEFT);
147149
return (
148-
<Box marginBottom={1} marginLeft={1} marginY={0} width={Math.max(1, width)} flexDirection="row">
150+
<Box marginBottom={1} marginLeft={PROMPT_ECHO_MARGIN_LEFT} marginY={0} width={containerWidth} flexDirection="row">
149151
<Box width={PROMPT_ECHO_PREFIX_WIDTH}>
150152
<Text color="#229ac3">{"> "}</Text>
151153
</Box>

0 commit comments

Comments
 (0)