Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/app/src/context/terminal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@ function createTerminalSession(sdk: ReturnType<typeof useSDK>, dir: string, sess
}),
)

sdk.event.on("pty.exited", (event) => {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

listens for when a terminal process exits and cleans up ui :)

const id = event.properties.id
if (!store.all.some((x) => x.id === id)) return
batch(() => {
setStore(
"all",
store.all.filter((x) => x.id !== id),
)
if (store.active === id) {
const remaining = store.all.filter((x) => x.id !== id)
setStore("active", remaining[0]?.id)
}
})
})

return {
ready,
all: createMemo(() => Object.values(store.all)),
Expand Down
13 changes: 13 additions & 0 deletions packages/app/src/pages/session.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,19 @@ export default function Page() {
terminal.new()
})

createEffect(
on(
() => terminal.all().length,
(count, prevCount) => {
if (prevCount !== undefined && prevCount > 0 && count === 0) {
if (view().terminal.opened()) {
view().terminal.toggle()
}
}
},
),
)

createEffect(
on(
() => visibleUserMessages().at(-1)?.id,
Expand Down
3 changes: 3 additions & 0 deletions packages/opencode/src/pty/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ export namespace Pty {
log.info("session exited", { id, exitCode })
session.info.status = "exited"
Bus.publish(Event.Exited, { id, exitCode })
for (const ws of session.subscribers) {
ws.close()
}
state().delete(id)
})
Bus.publish(Event.Created, { info })
Expand Down