GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(tui): resolve default cursor style across config reloads (#60302) · jonBoone/opencode@085d6f7

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/tui
    • src
      • component/prompt
        • index.tsx
      • config
        • index.tsx
      • routes/session
        • form.tsx
        • permission.tsx
      • ui
        • dialog-prompt.tsx
        • dialog-select.tsx
    • test
      • cli/tui
        • dialog-prompt.test.tsx
      • config-v2.test.tsx
Expand file treeCollapse file tree
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: packages/tui/src/component/prompt/index.tsx
+3-3Lines 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) => {
Collapse file

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

Copy file name to clipboardExpand all lines: packages/tui/src/config/index.tsx
+5-7Lines 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",
Collapse file

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

Copy file name to clipboardExpand all lines: packages/tui/src/routes/session/form.tsx
+2-2Lines 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" }
Collapse file

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

Copy file name to clipboardExpand all lines: packages/tui/src/routes/session/permission.tsx
+1-1Lines 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"
Collapse file

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

Copy file name to clipboardExpand all lines: packages/tui/src/ui/dialog-prompt.tsx
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ export function DialogPrompt(props: DialogPromptProps) {
172172
textColor={props.busy ? theme.text.formfield.disabled : theme.text.formfield.base}
173173
focusedTextColor={props.busy ? theme.text.formfield.disabled : theme.text.formfield.base}
174174
cursorColor={props.busy ? theme.background.formfield.disabled : theme.text.base}
175-
cursorStyle={config.cursor}
175+
cursorStyle={{ ...config.cursor }}
176176
/>
177177
<Show when={props.busy}>
178178
<Spinner color={theme.text.muted}>{props.busyText ?? "Working…"}</Spinner>
Collapse file

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

Copy file name to clipboardExpand all lines: packages/tui/src/ui/dialog-select.tsx
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ export function DialogSelect<T>(props: DialogSelectProps<T>) {
672672
}}
673673
focusedBackgroundColor={theme.background.formfield.focused}
674674
cursorColor={searchCursorColor()}
675-
cursorStyle={config.cursor}
675+
cursorStyle={{ ...config.cursor }}
676676
focusedTextColor={newDesigns() ? theme.text.formfield.base : theme.text.formfield.focused}
677677
ref={(r) => {
678678
input = r
Collapse file

‎packages/tui/test/cli/tui/dialog-prompt.test.tsx‎

Copy file name to clipboardExpand all lines: packages/tui/test/cli/tui/dialog-prompt.test.tsx
+71-4Lines changed: 71 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import path from "node:path"
77
import { onCleanup } from "solid-js"
88
import { emptyThemeSource, tmpdir } from "../../fixture/fixture"
99
import { createTuiResolvedConfig } from "../../fixture/tui-runtime"
10+
import type { Config } from "../../../src/config"
1011
import type { TuiKeybind } from "../../../src/config/keybind"
1112
import { TestTuiContexts } from "../../fixture/tui-environment"
1213

@@ -21,12 +22,14 @@ async function wait(fn: () => boolean, timeout = 2000) {
2122
async function mountPrompt(input: {
2223
root: string
2324
keybinds: Partial<TuiKeybind.Keybinds>
25+
cursor?: Config.Info["cursor"]
26+
service?: Config.Interface
2427
onConfirm: (value: string) => void
2528
}) {
2629
const state = path.join(input.root, "state")
2730
await mkdir(state, { recursive: true })
2831

29-
const [{ DialogProvider }, { DialogPrompt }, { ThemeProvider }, { ConfigProvider }, { ToastProvider }, { Keymap }] =
32+
const [{ DialogProvider }, { DialogPrompt }, { ThemeProvider }, { Config }, { ToastProvider }, { Keymap }] =
3033
await Promise.all([
3134
import("../../../src/ui/dialog"),
3235
import("../../../src/ui/dialog-prompt"),
@@ -36,13 +39,17 @@ async function mountPrompt(input: {
3639
import("../../../src/context/keymap"),
3740
])
3841

42+
let config: ReturnType<typeof Config.useConfig> | undefined
43+
3944
function Harness() {
4045
const resolvedConfig = createTuiResolvedConfig({
4146
keybinds: input.keybinds,
4247
leader: { timeout: 1000 },
48+
cursor: input.cursor,
4349
})
4450

4551
function Prompt() {
52+
config = Config.useConfig()
4653
onCleanup(Keymap.use().mode.push("modal"))
4754
return <DialogPrompt title="Rename Session" value="draft" onConfirm={input.onConfirm} />
4855
}
@@ -56,7 +63,7 @@ async function mountPrompt(input: {
5663
worktree: input.root,
5764
}}
5865
>
59-
<ConfigProvider config={resolvedConfig}>
66+
<Config.ConfigProvider config={resolvedConfig} service={input.service}>
6067
<Keymap.Provider>
6168
<ThemeProvider mode="dark" source={emptyThemeSource}>
6269
<ToastProvider>
@@ -66,15 +73,19 @@ async function mountPrompt(input: {
6673
</ToastProvider>
6774
</ThemeProvider>
6875
</Keymap.Provider>
69-
</ConfigProvider>
76+
</Config.ConfigProvider>
7077
</TestTuiContexts>
7178
)
7279
}
7380

74-
const app = await testRender(() => <Harness />, { kittyKeyboard: true })
81+
const app = await testRender(() => <Harness />, { width: 80, height: 24, kittyKeyboard: true })
7582
app.renderer.start()
7683
return {
7784
app,
85+
get config() {
86+
if (!config) throw new Error("expected config context")
87+
return config
88+
},
7889
async cleanup() {
7990
app.renderer.destroy()
8091
},
@@ -184,3 +195,59 @@ test("dialog prompt submit can be disabled", async () => {
184195
await prompt.cleanup()
185196
}
186197
})
198+
199+
test("dialog prompt renders block cursor and survives cursor hot reloads", async () => {
200+
await using tmp = await tmpdir()
201+
let current: Config.Info = { cursor: { style: "block", blinking: true } }
202+
const service: Config.Interface = {
203+
get: async () => current,
204+
update: async (fn) => {
205+
const next = structuredClone(current)
206+
fn(next)
207+
current = next
208+
return current
209+
},
210+
}
211+
const prompt = await mountPrompt({
212+
root: tmp.path,
213+
keybinds: {},
214+
cursor: current.cursor,
215+
service,
216+
onConfirm: () => {},
217+
})
218+
219+
try {
220+
await wait(() => prompt.app.renderer.currentFocusedEditor instanceof TextareaRenderable)
221+
const textarea = prompt.app.renderer.currentFocusedEditor
222+
if (!(textarea instanceof TextareaRenderable)) throw new Error("expected focused dialog textarea")
223+
224+
await prompt.app.renderOnce()
225+
expect(prompt.app.captureCharFrame()).toContain("Rename Session")
226+
expect(textarea.cursorStyle).toMatchObject({ style: "block", blinking: true })
227+
228+
await prompt.config.update((draft) => {
229+
delete draft.cursor
230+
})
231+
await prompt.app.renderOnce()
232+
expect(textarea.cursorStyle).toMatchObject({ style: "block", blinking: true })
233+
234+
const cases = (["block", "underline", "default", "line"] as const).flatMap((style) =>
235+
([true, false] as const).map((blinking) => ({ style, blinking })),
236+
)
237+
for (const cursor of cases) {
238+
await prompt.config.update((draft) => {
239+
draft.cursor = cursor
240+
})
241+
await prompt.app.renderOnce()
242+
expect(textarea.cursorStyle).toMatchObject(cursor)
243+
}
244+
245+
await prompt.config.update((draft) => {
246+
delete draft.cursor
247+
})
248+
await prompt.app.renderOnce()
249+
expect(textarea.cursorStyle).toMatchObject({ style: "block", blinking: true })
250+
} finally {
251+
await prompt.cleanup()
252+
}
253+
})
Collapse file

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

Copy file name to clipboardExpand all lines: packages/tui/test/config-v2.test.tsx
+9Lines 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 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.