Skip to content

Commit 27d6920

Browse files
committed
fix(tui): preserve spacing after tool blocks
1 parent dd4aa2a commit 27d6920

3 files changed

Lines changed: 52 additions & 3 deletions

File tree

packages/opencode/src/cli/cmd/tui/routes/session/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1793,7 +1793,7 @@ function InlineTool(props: {
17931793
const children = parent.getChildren()
17941794
const index = children.indexOf(el)
17951795
const previous = children[index - 1]
1796-
setMargin(previous?.id.startsWith("text-") ? 1 : 0)
1796+
setMargin(previous?.id.startsWith("text-") || previous?.id.startsWith("tool-block-") ? 1 : 0)
17971797
}}
17981798
>
17991799
<Switch>
@@ -1850,6 +1850,7 @@ function BlockTool(props: {
18501850
const error = createMemo(() => (props.part?.state.status === "error" ? props.part.state.error : undefined))
18511851
return (
18521852
<box
1853+
id={props.part ? "tool-block-" + props.part.id : undefined}
18531854
border={["left"]}
18541855
paddingTop={1}
18551856
paddingBottom={1}

packages/opencode/test/cli/tui/__snapshots__/inline-tool-wrap-snapshot.test.tsx.snap

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,22 @@ exports[`TUI inline tool wrapping snapshots expanded tool errors under the tool
2020
✱ Grep "export const OPENCODE_DB|OPENCODE_DB|OPENCODE_DEV|Global\\.
2121
Path\\.data|data =" in packages/opencode/src (115 matches)"
2222
`;
23+
24+
exports[`TUI inline tool wrapping keeps separation after a shell output block 1`] = `
25+
"
26+
27+
# List files
28+
29+
$ ls
30+
31+
file.ts
32+
33+
34+
✱ Grep "OPENCODE.*DB|database|sqlite|drizzle|dev.*db|data.
35+
*dir|xdg|APPDATA" in packages/opencode/src (151 matches)
36+
✱ Glob "**/*db*" in packages/opencode (6 matches)
37+
→ Read packages/opencode/src/storage/db.ts [offset=1, limit=130]
38+
→ Read packages/opencode/src/index.ts [offset=1, limit=100]
39+
✱ Grep "export const OPENCODE_DB|OPENCODE_DB|OPENCODE_DEV|Global\\.
40+
Path\\.data|data =" in packages/opencode/src (115 matches)"
41+
`;

packages/opencode/test/cli/tui/inline-tool-wrap-snapshot.test.tsx

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ function InlineToolRow(props: { item: ToolFixture; errorExpanded?: boolean }) {
4949
renderBefore={function () {
5050
const parent = this.parent
5151
if (!parent) return
52-
setMargin(parent.getChildren()[parent.getChildren().indexOf(this) - 1]?.id.startsWith("text-") ? 1 : 0)
52+
const previous = parent.getChildren()[parent.getChildren().indexOf(this) - 1]
53+
setMargin(previous?.id.startsWith("text-") || previous?.id.startsWith("tool-block-") ? 1 : 0)
5354
}}
5455
>
5556
<box flexDirection="row">
@@ -65,10 +66,23 @@ function InlineToolRow(props: { item: ToolFixture; errorExpanded?: boolean }) {
6566
)
6667
}
6768

68-
function Fixture(props: { errorExpanded?: boolean }) {
69+
function ShellOutput() {
70+
return (
71+
<box id="tool-block-shell" marginTop={1} paddingTop={1} paddingBottom={1} paddingLeft={2} gap={1}>
72+
<text paddingLeft={3}># List files</text>
73+
<box gap={1}>
74+
<text>$ ls</text>
75+
<text>file.ts</text>
76+
</box>
77+
</box>
78+
)
79+
}
80+
81+
function Fixture(props: { errorExpanded?: boolean; shellOutput?: boolean }) {
6982
return (
7083
<box flexDirection="column" width={72}>
7184
<box flexDirection="column">
85+
{props.shellOutput && <ShellOutput />}
7286
<For each={tools}>{(item) => <InlineToolRow item={item} errorExpanded={props.errorExpanded} />}</For>
7387
</box>
7488
</box>
@@ -105,4 +119,19 @@ describe("TUI inline tool wrapping", () => {
105119
.trimEnd(),
106120
).toMatchSnapshot()
107121
})
122+
123+
test("keeps separation after a shell output block", async () => {
124+
testSetup = await testRender(() => <Fixture shellOutput />, { width: 72, height: 16 })
125+
await testSetup.renderOnce()
126+
await testSetup.renderOnce()
127+
128+
expect(
129+
testSetup
130+
.captureCharFrame()
131+
.split("\n")
132+
.map((line) => line.trimEnd())
133+
.join("\n")
134+
.trimEnd(),
135+
).toMatchSnapshot()
136+
})
108137
})

0 commit comments

Comments
 (0)