Skip to content

Commit 8bf5062

Browse files
feat(tui): add cursor style configuration (#32295)
Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com>
1 parent 20750c3 commit 8bf5062

10 files changed

Lines changed: 58 additions & 3 deletions

File tree

packages/tui/src/component/prompt/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ export function Prompt(props: PromptProps) {
251251
if (!input || input.isDestroyed) return
252252
if (props.disabled) input.cursorColor = theme.backgroundElement
253253
if (!props.disabled) input.cursorColor = theme.text
254+
if (tuiConfig.cursor) input.cursorStyle = tuiConfig.cursor
254255
})
255256

256257
const lastUserMessage = createMemo(() => {
@@ -1431,11 +1432,13 @@ export function Prompt(props: PromptProps) {
14311432
// setTimeout is a workaround and needs to be addressed properly
14321433
if (!input || input.isDestroyed) return
14331434
input.cursorColor = theme.text
1435+
if (tuiConfig.cursor) input.cursorStyle = tuiConfig.cursor
14341436
}, 0)
14351437
}}
14361438
onMouseDown={(r: MouseEvent) => r.target?.focus()}
14371439
focusedBackgroundColor={theme.backgroundElement}
14381440
cursorColor={props.disabled ? theme.backgroundElement : theme.text}
1441+
cursorStyle={tuiConfig.cursor}
14391442
syntaxStyle={syntax()}
14401443
/>
14411444
<box flexDirection="row" flexShrink={0} paddingTop={1} gap={1} justifyContent="space-between">

packages/tui/src/config/index.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ export const ScrollAcceleration = Schema.Struct({
3030
export const DiffStyle = Schema.Literals(["auto", "stacked"]).annotate({
3131
description: "Control diff rendering style: 'auto' adapts to terminal width, 'stacked' always shows single column",
3232
})
33+
export const Cursor = Schema.Struct({
34+
style: Schema.optional(Schema.Literals(["block", "underline", "line", "default"])).annotate({
35+
description: "Cursor shape. Use 'default' to preserve the terminal setting",
36+
}),
37+
blinking: Schema.optional(Schema.Boolean).annotate({
38+
description: "Whether the cursor blinks. Has no effect when style is 'default'",
39+
}),
40+
}).annotate({ description: "Terminal cursor settings" })
3341

3442
export const AttentionSounds = Schema.Record(AttentionSoundName, Schema.optionalKey(Schema.String))
3543
export type AttentionSoundPaths = Schema.Schema.Type<typeof AttentionSounds>
@@ -62,11 +70,12 @@ export const Info = Schema.Struct({
6270
scroll_speed: Schema.optional(ScrollSpeed).annotate({ description: "TUI scroll speed" }),
6371
scroll_acceleration: Schema.optional(ScrollAcceleration),
6472
diff_style: Schema.optional(DiffStyle),
73+
cursor: Schema.optional(Cursor),
6574
mouse: Schema.optional(Schema.Boolean).annotate({ description: "Enable or disable mouse capture (default: true)" }),
6675
})
6776
export type Info = Schema.Schema.Type<typeof Info>
6877

69-
export type Resolved = Omit<Info, "attention" | "keybinds" | "leader_timeout" | "mouse"> & {
78+
export type Resolved = Omit<Info, "attention" | "keybinds" | "leader_timeout" | "mouse" | "cursor"> & {
7079
attention: {
7180
enabled: boolean
7281
notifications: boolean
@@ -78,6 +87,10 @@ export type Resolved = Omit<Info, "attention" | "keybinds" | "leader_timeout" |
7887
keybinds: TuiKeybind.BindingLookupView
7988
leader_timeout: number
8089
mouse: boolean
90+
cursor?: {
91+
style: "block" | "underline" | "line" | "default"
92+
blinking: boolean
93+
}
8194
}
8295

8396
export const ResolveOptions = Schema.Struct({
@@ -113,6 +126,12 @@ export function resolve(input: Info, options: ResolveOptions): Resolved {
113126
}),
114127
leader_timeout: input.leader_timeout ?? LeaderTimeoutDefault,
115128
mouse: input.mouse ?? true,
129+
cursor: input.cursor
130+
? {
131+
style: input.cursor.style ?? "block",
132+
blinking: input.cursor.blinking ?? true,
133+
}
134+
: undefined,
116135
}
117136
}
118137

packages/tui/src/routes/session/permission.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,7 @@ function RejectPrompt(props: { onConfirm: (message: string) => void; onCancel: (
507507
textColor={theme.text}
508508
focusedTextColor={theme.text}
509509
cursorColor={theme.primary}
510+
cursorStyle={tuiConfig.cursor}
510511
/>
511512
<box flexDirection="row" gap={2} flexShrink={0}>
512513
<text fg={theme.text}>

packages/tui/src/routes/session/question.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ export function QuestionPrompt(props: { request: QuestionRequest; directory?: st
441441
textColor={theme.text}
442442
focusedTextColor={theme.text}
443443
cursorColor={theme.primary}
444+
cursorStyle={tuiConfig.cursor}
444445
/>
445446
</box>
446447
</Show>

packages/tui/src/ui/dialog-export-options.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { useTheme } from "../context/theme"
33
import { useDialog, type DialogContext } from "./dialog"
44
import { createStore } from "solid-js/store"
55
import { onMount, Show } from "solid-js"
6+
import { useTuiConfig } from "../config"
67
import { useBindings } from "../keymap"
78

89
export type DialogExportOptionsProps = {
@@ -24,6 +25,7 @@ export type DialogExportOptionsProps = {
2425
export function DialogExportOptions(props: DialogExportOptionsProps) {
2526
const dialog = useDialog()
2627
const { theme } = useTheme()
28+
const tuiConfig = useTuiConfig()
2729
let textarea: TextareaRenderable
2830
const [store, setStore] = createStore({
2931
thinking: props.defaultThinking,
@@ -116,6 +118,7 @@ export function DialogExportOptions(props: DialogExportOptionsProps) {
116118
textColor={theme.text}
117119
focusedTextColor={theme.text}
118120
cursorColor={theme.text}
121+
cursorStyle={tuiConfig.cursor}
119122
/>
120123
</box>
121124
<box flexDirection="column">

packages/tui/src/ui/dialog-prompt.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ export function DialogPrompt(props: DialogPromptProps) {
9696
textColor={props.busy ? theme.textMuted : theme.text}
9797
focusedTextColor={props.busy ? theme.textMuted : theme.text}
9898
cursorColor={props.busy ? theme.backgroundElement : theme.text}
99+
cursorStyle={tuiConfig.cursor}
99100
/>
100101
<Show when={props.busy}>
101102
<Spinner color={theme.textMuted}>{props.busyText ?? "Working..."}</Spinner>

packages/tui/src/ui/dialog-select.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,7 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
579579
}}
580580
focusedBackgroundColor={theme.backgroundPanel}
581581
cursorColor={theme.primary}
582+
cursorStyle={tuiConfig.cursor}
582583
focusedTextColor={theme.textMuted}
583584
ref={(r) => {
584585
input = r

packages/tui/test/config.test.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,20 @@ test("validates config constraints", () => {
3131
prompt: { max_height: 10, max_width: "auto" },
3232
scroll_speed: 0.001,
3333
diff_style: "stacked",
34+
cursor: { blinking: false },
3435
plugin: ["example-plugin"],
3536
}),
36-
).toMatchObject({ leader_timeout: 250, attention: { volume: 1 }, diff_style: "stacked" })
37+
).toMatchObject({
38+
leader_timeout: 250,
39+
attention: { volume: 1 },
40+
diff_style: "stacked",
41+
cursor: { blinking: false },
42+
})
3743
expect(() => decodeInfo({ leader_timeout: 0 })).toThrow()
3844
expect(() => decodeInfo({ attention: { volume: 1.1 } })).toThrow()
3945
expect(() => decodeInfo({ prompt: { max_width: 0 } })).toThrow()
4046
expect(() => decodeInfo({ scroll_speed: 0 })).toThrow()
47+
expect(() => decodeInfo({ cursor: { style: "beam" } })).toThrow()
4148
expect(decodeInfo({ attention: { sounds: { unknown: "sound.wav" } } })).toEqual({ attention: { sounds: {} } })
4249
})
4350

@@ -56,6 +63,7 @@ test("resolves host-neutral defaults", () => {
5663
expect(config.mouse).toBe(true)
5764
expect(config.keybinds.has("terminal.suspend")).toBe(true)
5865
expect(config.keybinds.has("session.list")).toBe(true)
66+
expect(config.cursor).toBeUndefined()
5967
})
6068

6169
test("resolves overrides without mutating input", () => {
@@ -72,10 +80,17 @@ test("resolves overrides without mutating input", () => {
7280
sounds: { question: "/sounds/question.wav" },
7381
},
7482
keybinds: { session_list: "ctrl+l" },
83+
cursor: { blinking: false },
7584
}
7685
const config = resolve(input, { terminalSuspend: true })
7786

78-
expect(config).toMatchObject({ theme: "custom", mouse: false, leader_timeout: 750, attention: input.attention })
87+
expect(config).toMatchObject({
88+
theme: "custom",
89+
mouse: false,
90+
leader_timeout: 750,
91+
attention: input.attention,
92+
cursor: { style: "block", blinking: false },
93+
})
7994
expect(config.keybinds.get("session.list")).toHaveLength(1)
8095
expect(input.keybinds).toEqual({ session_list: "ctrl+l" })
8196
})

packages/web/src/content/docs/config.mdx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,10 @@ Use a dedicated `tui.json` (or `tui.jsonc`) file for TUI-specific settings.
273273
"enabled": true
274274
},
275275
"diff_style": "auto",
276+
"cursor": {
277+
"style": "block",
278+
"blinking": true
279+
},
276280
"mouse": true,
277281
"attention": {
278282
"enabled": true,
@@ -285,6 +289,8 @@ Use a dedicated `tui.json` (or `tui.jsonc`) file for TUI-specific settings.
285289

286290
Use `OPENCODE_TUI_CONFIG` to point to a custom TUI config file.
287291

292+
When `cursor.style` is `"default"`, the terminal default cursor is restored, so `cursor.blinking` has no effect.
293+
288294
Set `attention.enabled` to turn on TUI desktop notifications and sounds. See [TUI attention](/docs/tui#attention).
289295

290296
Legacy `theme`, `keybinds`, and `tui` keys in `opencode.json` are deprecated and automatically migrated when possible.

packages/web/src/content/docs/tui.mdx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,10 @@ You can customize TUI behavior through `tui.json` (or `tui.jsonc`).
369369
"enabled": false
370370
},
371371
"diff_style": "auto",
372+
"cursor": {
373+
"style": "block",
374+
"blinking": true
375+
},
372376
"mouse": true,
373377
"attention": {
374378
"enabled": true,
@@ -395,6 +399,7 @@ This is separate from `opencode.json`, which configures server/runtime behavior.
395399
- `scroll_acceleration.enabled` - Enable macOS-style scroll acceleration for smooth, natural scrolling. When enabled, scroll speed increases with rapid scrolling gestures and stays precise for slower movements. **This setting takes precedence over `scroll_speed` and overrides it when enabled.**
396400
- `scroll_speed` - Controls how fast the TUI scrolls when using scroll commands (minimum: `0.001`, supports decimal values). Defaults to `3`. **Note: This is ignored if `scroll_acceleration.enabled` is set to `true`.**
397401
- `diff_style` - Controls diff rendering. `"auto"` adapts to terminal width, `"stacked"` always shows a single-column layout.
402+
- `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.
398403
- `mouse` - Enable or disable mouse capture in the TUI (default: `true`). When disabled, the terminal's native mouse selection/scrolling behavior is preserved.
399404
- `attention` - Configures TUI desktop notifications and sounds. Disabled by default.
400405

0 commit comments

Comments
 (0)