Skip to content

Commit 3ec34ee

Browse files
authored
feat(tui): add dynamic terminal window title (#5112)
1 parent 2e5c2d5 commit 3ec34ee

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

packages/opencode/src/cli/cmd/tui/app.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,26 @@ function App() {
169169
console.log(JSON.stringify(route.data))
170170
})
171171

172+
// Update terminal window title based on current route and session
173+
createEffect(() => {
174+
if (route.data.type === "home") {
175+
renderer.setTerminalTitle("opencode")
176+
return
177+
}
178+
179+
if (route.data.type === "session") {
180+
const session = sync.session.get(route.data.sessionID)
181+
if (!session || SessionApi.isDefaultTitle(session.title)) {
182+
renderer.setTerminalTitle("opencode")
183+
return
184+
}
185+
186+
// Truncate title to 40 chars max
187+
const title = session.title.length > 40 ? session.title.slice(0, 37) + "..." : session.title
188+
renderer.setTerminalTitle(`oc | ${title}`)
189+
}
190+
})
191+
172192
const args = useArgs()
173193
onMount(() => {
174194
batch(() => {

packages/opencode/src/cli/cmd/tui/context/exit.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ export const { use: useExit, provider: ExitProvider } = createSimpleContext({
77
init: (input: { onExit?: () => Promise<void> }) => {
88
const renderer = useRenderer()
99
return async (reason?: any) => {
10+
// Reset window title before destroying renderer
11+
renderer.setTerminalTitle("")
1012
renderer.destroy()
1113
await input.onExit?.()
1214
if (reason) {

0 commit comments

Comments
 (0)