Skip to content

Commit d71a743

Browse files
author
Harish C
committed
fix(tui): apply cursor style config on reload
Port of anomalyco/opencode#60302. Cursor config resolves to a defined default and consumers spread it, so a config reload produces a fresh object and the terminal applies the change instead of keeping the first shared reference. Baseline: new config-v2 assertions fail without the fix (20 pass/1 fail); 21 pass/0 fail with it. Typecheck clean (tui). Upstream's dialog-prompt hot-reload render test not yet ported (harness refactor; HC ConfigProvider already supports service+update, so it is portable in a later pass).
1 parent 3965829 commit d71a743

7 files changed

Lines changed: 22 additions & 15 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ export function Prompt(props: PromptProps) {
353353
createEffect(() => {
354354
if (!input || input.isDestroyed) return
355355
input.cursorColor = disabled() ? theme.background.raised.base : theme.text.base
356-
if (config.cursor) input.cursorStyle = config.cursor
356+
input.cursorStyle = config.cursor
357357
})
358358

359359
const [store, setStore] = createStore<{
@@ -1773,7 +1773,7 @@ export function Prompt(props: PromptProps) {
17731773
focusedTextColor={muted() ? theme.text.muted : theme.text.base}
17741774
minHeight={1}
17751775
maxHeight={maxHeight()}
1776-
cursorStyle={config.cursor}
1776+
cursorStyle={{ ...config.cursor }}
17771777
onContentChange={() => {
17781778
const value = input.plainText
17791779
setStore("prompt", "text", value)
@@ -1832,7 +1832,7 @@ export function Prompt(props: PromptProps) {
18321832
// setTimeout is a workaround and needs to be addressed properly
18331833
if (!input || input.isDestroyed) return
18341834
input.cursorColor = disabled() ? theme.background.raised.base : theme.text.base
1835-
if (config.cursor) input.cursorStyle = config.cursor
1835+
input.cursorStyle = config.cursor
18361836
}, 0)
18371837
}}
18381838
onMouseDown={(r: MouseEvent) => {

‎packages/tui/src/config/index.tsx‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ export type Resolved = Omit<Info, "attention" | "cursor" | "keybinds" | "leader"
267267
keybinds: TuiKeybind.BindingLookupView
268268
leader: { timeout: number }
269269
mouse: boolean
270-
cursor?: {
270+
cursor: {
271271
style: "block" | "underline" | "line" | "default"
272272
blinking: boolean
273273
}
@@ -315,12 +315,10 @@ export function resolve(
315315
}),
316316
leader: { timeout: input.leader?.timeout ?? 2000 },
317317
mouse: input.mouse ?? true,
318-
cursor: input.cursor
319-
? {
320-
style: input.cursor.style ?? "block",
321-
blinking: input.cursor.blinking ?? true,
322-
}
323-
: undefined,
318+
cursor: {
319+
style: input.cursor?.style ?? "block",
320+
blinking: input.cursor?.blinking ?? true,
321+
},
324322
session: {
325323
...input.session,
326324
new_location: input.session?.new_location ?? "launch",

‎packages/tui/src/routes/session/form.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ export function FormPrompt(props: { form: FormWithLocation }) {
885885
<Show when={textual() ? answerField()!.key : undefined} keyed>
886886
<box paddingLeft={1}>
887887
<textarea
888-
cursorStyle={config.cursor}
888+
cursorStyle={{ ...config.cursor }}
889889
ref={(val: TextareaRenderable) => {
890890
textarea = val
891891
val.traits = { status: "ANSWER" }
@@ -1025,7 +1025,7 @@ export function FormPrompt(props: { form: FormWithLocation }) {
10251025
>
10261026
<textarea
10271027
flexGrow={1}
1028-
cursorStyle={config.cursor}
1028+
cursorStyle={{ ...config.cursor }}
10291029
ref={(val: TextareaRenderable) => {
10301030
textarea = val
10311031
val.traits = { status: "ANSWER" }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ function RejectPrompt(props: {
357357
textColor={theme.text.base}
358358
focusedTextColor={theme.text.base}
359359
cursorColor={theme.text.base}
360-
cursorStyle={config.cursor}
360+
cursorStyle={{ ...config.cursor }}
361361
/>
362362
<box
363363
id="session.permission.reject.actions"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ export function DialogPrompt(props: DialogPromptProps) {
173173
textColor={props.busy ? theme.text.formfield.disabled : theme.text.formfield.base}
174174
focusedTextColor={props.busy ? theme.text.formfield.disabled : theme.text.formfield.base}
175175
cursorColor={props.busy ? theme.background.formfield.disabled : theme.text.base}
176-
cursorStyle={config.cursor}
176+
cursorStyle={{ ...config.cursor }}
177177
/>
178178
<Show when={props.busy}>
179179
<Spinner color={theme.text.muted}>{props.busyText ?? "Working…"}</Spinner>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
665665
}}
666666
focusedBackgroundColor={theme.background.formfield.focused}
667667
cursorColor={newDesigns() ? theme.text.base : theme.text.formfield.focused}
668-
cursorStyle={config.cursor}
668+
cursorStyle={{ ...config.cursor }}
669669
focusedTextColor={newDesigns() ? theme.text.formfield.base : theme.text.formfield.focused}
670670
ref={(r) => {
671671
input = r

‎packages/tui/test/config-v2.test.tsx‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ test("resolves nested config and keybind defaults", () => {
7373
})
7474
expect(config.session.new_location).toBe("launch")
7575
expect(config.session.tps).toBe(true)
76+
expect(config.cursor).toEqual({ style: "block", blinking: true })
77+
expect(resolve({ cursor: { style: "line" } }, { terminalSuspend: true }).cursor).toEqual({
78+
style: "line",
79+
blinking: true,
80+
})
81+
expect(resolve({ cursor: { blinking: false } }, { terminalSuspend: true }).cursor).toEqual({
82+
style: "block",
83+
blinking: false,
84+
})
7685
})
7786

7887
test("resolves automatic tabs from the terminal environment", () => {

0 commit comments

Comments
 (0)