Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Clipboard } from "@tui/util/clipboard"
import { createSignal } from "solid-js"
import { Installation } from "@/installation"
import { win32FlushInputBuffer } from "../win32"
import { Terminal } from "../util/terminal"

export function ErrorComponent(props: {
error: Error
Expand All @@ -18,7 +19,9 @@ export function ErrorComponent(props: {
const handleExit = async () => {
await props.onBeforeExit?.()
renderer.setTerminalTitle("")
Terminal.restore()
renderer.destroy()
Terminal.restore()
win32FlushInputBuffer()
await props.onExit()
}
Expand Down
3 changes: 3 additions & 0 deletions packages/opencode/src/cli/cmd/tui/context/exit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useRenderer } from "@opentui/solid"
import { createSimpleContext } from "./helper"
import { FormatError, FormatUnknownError } from "@/cli/error"
import { win32FlushInputBuffer } from "../win32"
import { Terminal } from "../util/terminal"
type Exit = ((reason?: unknown) => Promise<void>) & {
message: {
set: (value?: string) => () => void
Expand Down Expand Up @@ -36,7 +37,9 @@ export const { use: useExit, provider: ExitProvider } = createSimpleContext({
await input.onBeforeExit?.()
// Reset window title before destroying renderer
renderer.setTerminalTitle("")
Terminal.restore()
renderer.destroy()
Terminal.restore()
win32FlushInputBuffer()
if (reason) {
const formatted = FormatError(reason) ?? FormatUnknownError(reason)
Expand Down
9 changes: 9 additions & 0 deletions packages/opencode/src/cli/cmd/tui/util/terminal.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import { RGBA } from "@opentui/core"

export namespace Terminal {
const RESET =
"\x1b[?1000l\x1b[?1002l\x1b[?1003l\x1b[?1004l\x1b[?1005l\x1b[?1006l\x1b[?1015l\x1b[?1016l\x1b[?2004l\x1b[?25h"

export type Colors = Awaited<ReturnType<typeof colors>>

export function restore() {
if (!process.stdout.isTTY) return
process.stdout.write(RESET)
}

/**
* Query terminal colors including background, foreground, and palette (0-15).
* Uses OSC escape sequences to retrieve actual terminal color values.
Expand Down
Loading