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
11 changes: 11 additions & 0 deletions packages/opencode/src/cli/cmd/tui/attach.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ import { TuiConfig } from "@/config/tui"
import { Instance } from "@/project/instance"
import { existsSync } from "fs"

function resetTerminal() {
if (!process.stdout.isTTY) return
process.stdout.write(
"\x1b[0m" + // reset all attributes (colors, bold, etc.)
"\x1b[?25h" + // show cursor
"\x1b[?1049l" + // exit alternate screen buffer
"\x1b[?7h", // re-enable auto-wrap
)
}

export const AttachCommand = cmd({
command: "attach <url>",
describe: "attach to a running opencode server",
Expand Down Expand Up @@ -83,6 +93,7 @@ export const AttachCommand = cmd({
})
} finally {
unguard?.()
resetTerminal()
}
},
})
14 changes: 14 additions & 0 deletions packages/opencode/src/cli/cmd/tui/thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ declare global {
const OPENCODE_WORKER_PATH: string
}

function resetTerminal() {
if (!process.stdout.isTTY) return
process.stdout.write(
"\x1b[0m" + // reset all attributes (colors, bold, etc.)
"\x1b[?25h" + // show cursor
"\x1b[?1049l" + // exit alternate screen buffer
"\x1b[?7h", // re-enable auto-wrap
)
}

// Backstop: runs even on process.exit() or uncaught crash
process.on("exit", resetTerminal)

type RpcClient = ReturnType<typeof Rpc.client<typeof rpc>>

function createWorkerFetch(client: RpcClient): typeof fetch {
Expand Down Expand Up @@ -226,6 +239,7 @@ export const TuiThreadCommand = cmd({
}
} finally {
unguard?.()
resetTerminal()
}
process.exit(0)
},
Expand Down
Loading