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
1 change: 1 addition & 0 deletions packages/opencode/src/cli/cmd/run/runtime.boot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ function runTuiConfig(config: Config | undefined): RunTuiConfig {
keybinds: config.keybinds,
leader_timeout: config.leader_timeout,
diff_style: config.diff_style ?? "auto",
kitty_keyboard: config.kitty_keyboard,
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/opencode/src/cli/cmd/run/runtime.lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export async function createRuntimeLifecycle(input: LifecycleInput): Promise<Lif
autoFocus: false,
openConsoleOnError: false,
exitOnCtrlC: false,
useKittyKeyboard: { events: process.platform === "win32" },
useKittyKeyboard: { events: process.platform === "win32" || input.tuiConfig.kitty_keyboard.events },
screenMode: "split-footer",
footerHeight: FOOTER_HEIGHT,
externalOutputMode: "capture-stdout",
Expand Down
2 changes: 1 addition & 1 deletion packages/opencode/src/cli/cmd/run/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ export type QuestionReply = Parameters<OpencodeClient["question"]["reply"]>[0]

export type QuestionReject = Parameters<OpencodeClient["question"]["reject"]>[0]

export type RunTuiConfig = Pick<TuiConfig.Resolved, "keybinds" | "leader_timeout" | "diff_style">
export type RunTuiConfig = Pick<TuiConfig.Resolved, "keybinds" | "leader_timeout" | "diff_style" | "kitty_keyboard">

// Lifecycle phase of a scrollback entry. "start" opens the entry, "progress"
// appends content (coalesced in the footer queue), "final" closes it.
Expand Down
2 changes: 1 addition & 1 deletion packages/tui/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export const run = Effect.fn("Tui.run")(function* (input: TuiInput) {
targetFps: 60,
gatherStats: false,
exitOnCtrlC: false,
useKittyKeyboard: {},
useKittyKeyboard: { events: input.config.kitty_keyboard.events },
autoFocus: false,
openConsoleOnError: false,
useMouse: !Flag.OPENCODE_DISABLE_MOUSE && input.config.mouse,
Expand Down
18 changes: 17 additions & 1 deletion packages/tui/src/config/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ export const Cursor = Schema.Struct({
}),
}).annotate({ description: "Terminal cursor settings" })

export const KittyKeyboard = Schema.Struct({
events: Schema.optional(Schema.Boolean).annotate({
description: "Request Kitty keyboard press, repeat, and release events. Enable only in terminals that support it.",
}),
}).annotate({ description: "Kitty keyboard protocol settings" })

export const AttentionSounds = Schema.Record(AttentionSoundName, Schema.optionalKey(Schema.String))
export type AttentionSoundPaths = Schema.Schema.Type<typeof AttentionSounds>
export const Attention = Schema.Struct({
Expand Down Expand Up @@ -72,10 +78,14 @@ export const Info = Schema.Struct({
diff_style: Schema.optional(DiffStyle),
cursor: Schema.optional(Cursor),
mouse: Schema.optional(Schema.Boolean).annotate({ description: "Enable or disable mouse capture (default: true)" }),
kitty_keyboard: Schema.optional(KittyKeyboard),
})
export type Info = Schema.Schema.Type<typeof Info>

export type Resolved = Omit<Info, "attention" | "keybinds" | "leader_timeout" | "mouse" | "cursor"> & {
export type Resolved = Omit<
Info,
"attention" | "keybinds" | "leader_timeout" | "mouse" | "cursor" | "kitty_keyboard"
> & {
attention: {
enabled: boolean
notifications: boolean
Expand All @@ -91,6 +101,9 @@ export type Resolved = Omit<Info, "attention" | "keybinds" | "leader_timeout" |
style: "block" | "underline" | "line" | "default"
blinking: boolean
}
kitty_keyboard: {
events: boolean
}
}

export const ResolveOptions = Schema.Struct({
Expand Down Expand Up @@ -126,6 +139,9 @@ export function resolve(input: Info, options: ResolveOptions): Resolved {
}),
leader_timeout: input.leader_timeout ?? LeaderTimeoutDefault,
mouse: input.mouse ?? true,
kitty_keyboard: {
events: input.kitty_keyboard?.events ?? false,
},
cursor: input.cursor
? {
style: input.cursor.style ?? "block",
Expand Down
5 changes: 5 additions & 0 deletions packages/tui/test/config.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ test("validates config constraints", () => {
scroll_speed: 0.001,
diff_style: "stacked",
cursor: { blinking: false },
kitty_keyboard: { events: true },
plugin: ["example-plugin"],
}),
).toMatchObject({
leader_timeout: 250,
attention: { volume: 1 },
diff_style: "stacked",
cursor: { blinking: false },
kitty_keyboard: { events: true },
})
expect(() => decodeInfo({ leader_timeout: 0 })).toThrow()
expect(() => decodeInfo({ attention: { volume: 1.1 } })).toThrow()
Expand All @@ -64,6 +66,7 @@ test("resolves host-neutral defaults", () => {
expect(config.keybinds.has("terminal.suspend")).toBe(true)
expect(config.keybinds.has("session.list")).toBe(true)
expect(config.cursor).toBeUndefined()
expect(config.kitty_keyboard).toEqual({ events: false })
})

test("resolves overrides without mutating input", () => {
Expand All @@ -81,6 +84,7 @@ test("resolves overrides without mutating input", () => {
},
keybinds: { session_list: "ctrl+l" },
cursor: { blinking: false },
kitty_keyboard: { events: true },
}
const config = resolve(input, { terminalSuspend: true })

Expand All @@ -90,6 +94,7 @@ test("resolves overrides without mutating input", () => {
leader_timeout: 750,
attention: input.attention,
cursor: { style: "block", blinking: false },
kitty_keyboard: { events: true },
})
expect(config.keybinds.get("session.list")).toHaveLength(1)
expect(input.keybinds).toEqual({ session_list: "ctrl+l" })
Expand Down
2 changes: 2 additions & 0 deletions packages/web/src/content/docs/config.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ Use `OPENCODE_TUI_CONFIG` to point to a custom TUI config file.

When `cursor.style` is `"default"`, the terminal default cursor is restored, so `cursor.blinking` has no effect.

Set `kitty_keyboard.events` to `true` only when your terminal reliably supports the Kitty keyboard protocol. It enables press, repeat, and release events; some xterm.js-based terminals report releases incorrectly.

Set `attention.enabled` to turn on TUI desktop notifications and sounds. See [TUI attention](/docs/tui#attention).

Legacy `theme`, `keybinds`, and `tui` keys in `opencode.json` are deprecated and automatically migrated when possible.
Expand Down
15 changes: 15 additions & 0 deletions packages/web/src/content/docs/tui.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -401,10 +401,25 @@ This is separate from `opencode.json`, which configures server/runtime behavior.
- `diff_style` - Controls diff rendering. `"auto"` adapts to terminal width, `"stacked"` always shows a single-column layout.
- `cursor` - Controls the terminal cursor in TUI input fields. `style` defaults to `"block"`, can be `"underline"`, `"line"`, or `"default"`; `blinking` defaults to `true`. When `style` is `"default"`, the terminal default cursor is restored, so `blinking` has no effect.
- `mouse` - Enable or disable mouse capture in the TUI (default: `true`). When disabled, the terminal's native mouse selection/scrolling behavior is preserved.
- `kitty_keyboard.events` - Request Kitty keyboard press, repeat, and release events. Disabled by default. Enable it only in terminals with reliable Kitty keyboard support; some xterm.js-based terminals report release events incorrectly.
- `attention` - Configures TUI desktop notifications and sounds. Disabled by default.

Use `OPENCODE_TUI_CONFIG` to load a custom TUI config path.

### Kitty keyboard events

To receive Kitty keyboard press, repeat, and release events, add this opt-in setting:

```json title="tui.json"
{
"kitty_keyboard": {
"events": true
}
}
```

Enable it only in terminals with reliable Kitty keyboard support. Some xterm.js-based terminals report release events incorrectly.

### Attention

The TUI can request attention for questions, permissions, session errors, and completed sessions. Enable it with `attention.enabled`; built-in events play sounds when triggered, and non-subagent events request desktop notifications only when the terminal is blurred.
Expand Down
Loading