@@ -7,6 +7,7 @@ import path from "node:path" |
7 | 7 | import { onCleanup } from "solid-js" |
8 | 8 | import { emptyThemeSource, tmpdir } from "../../fixture/fixture" |
9 | 9 | import { createTuiResolvedConfig } from "../../fixture/tui-runtime" |
| 10 | +import type { Config } from "../../../src/config" |
10 | 11 | import type { TuiKeybind } from "../../../src/config/keybind" |
11 | 12 | import { TestTuiContexts } from "../../fixture/tui-environment" |
12 | 13 |
|
@@ -21,12 +22,14 @@ async function wait(fn: () => boolean, timeout = 2000) { |
21 | 22 | async function mountPrompt(input: { |
22 | 23 | root: string |
23 | 24 | keybinds: Partial<TuiKeybind.Keybinds> |
| 25 | + cursor?: Config.Info["cursor"] |
| 26 | + service?: Config.Interface |
24 | 27 | onConfirm: (value: string) => void |
25 | 28 | }) { |
26 | 29 | const state = path.join(input.root, "state") |
27 | 30 | await mkdir(state, { recursive: true }) |
28 | 31 |
|
29 | | - const [{ DialogProvider }, { DialogPrompt }, { ThemeProvider }, { ConfigProvider }, { ToastProvider }, { Keymap }] = |
| 32 | + const [{ DialogProvider }, { DialogPrompt }, { ThemeProvider }, { Config }, { ToastProvider }, { Keymap }] = |
30 | 33 | await Promise.all([ |
31 | 34 | import("../../../src/ui/dialog"), |
32 | 35 | import("../../../src/ui/dialog-prompt"), |
@@ -36,13 +39,17 @@ async function mountPrompt(input: { |
36 | 39 | import("../../../src/context/keymap"), |
37 | 40 | ]) |
38 | 41 |
|
| 42 | + let config: ReturnType<typeof Config.useConfig> | undefined |
| 43 | + |
39 | 44 | function Harness() { |
40 | 45 | const resolvedConfig = createTuiResolvedConfig({ |
41 | 46 | keybinds: input.keybinds, |
42 | 47 | leader: { timeout: 1000 }, |
| 48 | + cursor: input.cursor, |
43 | 49 | }) |
44 | 50 |
|
45 | 51 | function Prompt() { |
| 52 | + config = Config.useConfig() |
46 | 53 | onCleanup(Keymap.use().mode.push("modal")) |
47 | 54 | return <DialogPrompt title="Rename Session" value="draft" onConfirm={input.onConfirm} /> |
48 | 55 | } |
@@ -56,7 +63,7 @@ async function mountPrompt(input: { |
56 | 63 | worktree: input.root, |
57 | 64 | }} |
58 | 65 | > |
59 | | - <ConfigProvider config={resolvedConfig}> |
| 66 | + <Config.ConfigProvider config={resolvedConfig} service={input.service}> |
60 | 67 | <Keymap.Provider> |
61 | 68 | <ThemeProvider mode="dark" source={emptyThemeSource}> |
62 | 69 | <ToastProvider> |
@@ -66,15 +73,19 @@ async function mountPrompt(input: { |
66 | 73 | </ToastProvider> |
67 | 74 | </ThemeProvider> |
68 | 75 | </Keymap.Provider> |
69 | | - </ConfigProvider> |
| 76 | + </Config.ConfigProvider> |
70 | 77 | </TestTuiContexts> |
71 | 78 | ) |
72 | 79 | } |
73 | 80 |
|
74 | | - const app = await testRender(() => <Harness />, { kittyKeyboard: true }) |
| 81 | + const app = await testRender(() => <Harness />, { width: 80, height: 24, kittyKeyboard: true }) |
75 | 82 | app.renderer.start() |
76 | 83 | return { |
77 | 84 | app, |
| 85 | + get config() { |
| 86 | + if (!config) throw new Error("expected config context") |
| 87 | + return config |
| 88 | + }, |
78 | 89 | async cleanup() { |
79 | 90 | app.renderer.destroy() |
80 | 91 | }, |
@@ -184,3 +195,59 @@ test("dialog prompt submit can be disabled", async () => { |
184 | 195 | await prompt.cleanup() |
185 | 196 | } |
186 | 197 | }) |
| 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 | +}) |