@neurocode-ai/tui 1.18.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (241) hide show
  1. package/bunfig.toml +4 -0
  2. package/package.json +72 -0
  3. package/src/app.tsx +1134 -0
  4. package/src/attention.ts +260 -0
  5. package/src/audio.d.ts +9 -0
  6. package/src/audio.ts +53 -0
  7. package/src/clipboard.ts +124 -0
  8. package/src/component/bg-pulse-render.ts +436 -0
  9. package/src/component/bg-pulse.tsx +99 -0
  10. package/src/component/command-palette.tsx +79 -0
  11. package/src/component/dialog-agent.tsx +31 -0
  12. package/src/component/dialog-console-org.tsx +135 -0
  13. package/src/component/dialog-debug.tsx +90 -0
  14. package/src/component/dialog-mcp.tsx +85 -0
  15. package/src/component/dialog-model.tsx +197 -0
  16. package/src/component/dialog-move-session.tsx +353 -0
  17. package/src/component/dialog-provider.tsx +469 -0
  18. package/src/component/dialog-retry-action.tsx +160 -0
  19. package/src/component/dialog-session-delete-failed.tsx +99 -0
  20. package/src/component/dialog-session-list.tsx +364 -0
  21. package/src/component/dialog-session-rename.tsx +31 -0
  22. package/src/component/dialog-skill.tsx +70 -0
  23. package/src/component/dialog-stash.tsx +87 -0
  24. package/src/component/dialog-status.tsx +168 -0
  25. package/src/component/dialog-tag.tsx +47 -0
  26. package/src/component/dialog-theme-list.tsx +50 -0
  27. package/src/component/dialog-variant.tsx +39 -0
  28. package/src/component/dialog-workspace-create.tsx +308 -0
  29. package/src/component/dialog-workspace-file-changes.tsx +144 -0
  30. package/src/component/dialog-workspace-list.tsx +112 -0
  31. package/src/component/dialog-workspace-unavailable.tsx +69 -0
  32. package/src/component/error-component.tsx +240 -0
  33. package/src/component/logo.tsx +61 -0
  34. package/src/component/plugin-route-missing.tsx +14 -0
  35. package/src/component/prompt/autocomplete.tsx +781 -0
  36. package/src/component/prompt/cwd.ts +0 -0
  37. package/src/component/prompt/frecency.tsx +1 -0
  38. package/src/component/prompt/history.tsx +1 -0
  39. package/src/component/prompt/index.tsx +1713 -0
  40. package/src/component/prompt/local-attachment.ts +48 -0
  41. package/src/component/prompt/move.tsx +205 -0
  42. package/src/component/prompt/stash.tsx +1 -0
  43. package/src/component/prompt/workspace.tsx +137 -0
  44. package/src/component/register-spinner.ts +6 -0
  45. package/src/component/spinner.tsx +26 -0
  46. package/src/component/startup-loading.tsx +63 -0
  47. package/src/component/todo-item.tsx +32 -0
  48. package/src/component/use-connected.tsx +12 -0
  49. package/src/component/workspace-label.tsx +19 -0
  50. package/src/config/index.tsx +129 -0
  51. package/src/config/keybind.ts +471 -0
  52. package/src/context/args.tsx +16 -0
  53. package/src/context/clipboard.tsx +18 -0
  54. package/src/context/data.tsx +569 -0
  55. package/src/context/directory.ts +17 -0
  56. package/src/context/editor.ts +408 -0
  57. package/src/context/epilogue.tsx +6 -0
  58. package/src/context/event.ts +36 -0
  59. package/src/context/exit.tsx +8 -0
  60. package/src/context/helper.tsx +26 -0
  61. package/src/context/kv.tsx +66 -0
  62. package/src/context/local.tsx +542 -0
  63. package/src/context/location.tsx +14 -0
  64. package/src/context/path-format.tsx +24 -0
  65. package/src/context/permission.tsx +26 -0
  66. package/src/context/project.tsx +115 -0
  67. package/src/context/prompt.tsx +18 -0
  68. package/src/context/route.tsx +60 -0
  69. package/src/context/runtime.tsx +62 -0
  70. package/src/context/sdk.tsx +151 -0
  71. package/src/context/sync.tsx +666 -0
  72. package/src/context/theme.tsx +332 -0
  73. package/src/context/thinking.ts +67 -0
  74. package/src/editor-zed.ts +286 -0
  75. package/src/editor.ts +101 -0
  76. package/src/feature-plugins/builtins.ts +36 -0
  77. package/src/feature-plugins/home/footer.tsx +100 -0
  78. package/src/feature-plugins/home/tips-view.tsx +287 -0
  79. package/src/feature-plugins/home/tips.tsx +59 -0
  80. package/src/feature-plugins/sidebar/context.tsx +65 -0
  81. package/src/feature-plugins/sidebar/files.tsx +70 -0
  82. package/src/feature-plugins/sidebar/footer.tsx +98 -0
  83. package/src/feature-plugins/sidebar/lsp.tsx +65 -0
  84. package/src/feature-plugins/sidebar/mcp.tsx +97 -0
  85. package/src/feature-plugins/sidebar/todo.tsx +49 -0
  86. package/src/feature-plugins/system/diff-viewer-file-tree-utils.ts +232 -0
  87. package/src/feature-plugins/system/diff-viewer-file-tree.tsx +162 -0
  88. package/src/feature-plugins/system/diff-viewer-ui.tsx +103 -0
  89. package/src/feature-plugins/system/diff-viewer.tsx +1077 -0
  90. package/src/feature-plugins/system/notifications.ts +94 -0
  91. package/src/feature-plugins/system/plugins.tsx +269 -0
  92. package/src/feature-plugins/system/which-key.tsx +608 -0
  93. package/src/index.tsx +1 -0
  94. package/src/keymap.tsx +290 -0
  95. package/src/logo.ts +11 -0
  96. package/src/parsers-config.ts +386 -0
  97. package/src/plugin/adapters.tsx +355 -0
  98. package/src/plugin/api.ts +52 -0
  99. package/src/plugin/command-shim.ts +109 -0
  100. package/src/plugin/runtime.tsx +81 -0
  101. package/src/plugin/slots.tsx +65 -0
  102. package/src/prompt/display.ts +48 -0
  103. package/src/prompt/frecency.tsx +80 -0
  104. package/src/prompt/history.tsx +111 -0
  105. package/src/prompt/part.ts +29 -0
  106. package/src/prompt/stash.tsx +89 -0
  107. package/src/prompt/traits.ts +29 -0
  108. package/src/routes/home/session-destination.tsx +41 -0
  109. package/src/routes/home.tsx +95 -0
  110. package/src/routes/session/dialog-fork-from-timeline.tsx +76 -0
  111. package/src/routes/session/dialog-message.tsx +109 -0
  112. package/src/routes/session/dialog-subagent.tsx +26 -0
  113. package/src/routes/session/dialog-timeline.tsx +47 -0
  114. package/src/routes/session/footer.tsx +91 -0
  115. package/src/routes/session/index.tsx +2710 -0
  116. package/src/routes/session/permission.tsx +718 -0
  117. package/src/routes/session/question.tsx +514 -0
  118. package/src/routes/session/sidebar.tsx +103 -0
  119. package/src/routes/session/subagent-footer.tsx +132 -0
  120. package/src/runtime.tsx +9 -0
  121. package/src/terminal-win32.ts +130 -0
  122. package/src/theme/assets/aura.json +69 -0
  123. package/src/theme/assets/ayu.json +80 -0
  124. package/src/theme/assets/carbonfox.json +248 -0
  125. package/src/theme/assets/catppuccin-frappe.json +230 -0
  126. package/src/theme/assets/catppuccin-macchiato.json +230 -0
  127. package/src/theme/assets/catppuccin.json +112 -0
  128. package/src/theme/assets/cobalt2.json +225 -0
  129. package/src/theme/assets/cursor.json +249 -0
  130. package/src/theme/assets/dracula.json +219 -0
  131. package/src/theme/assets/everforest.json +241 -0
  132. package/src/theme/assets/flexoki.json +237 -0
  133. package/src/theme/assets/github.json +233 -0
  134. package/src/theme/assets/gruvbox.json +242 -0
  135. package/src/theme/assets/kanagawa.json +77 -0
  136. package/src/theme/assets/lucent-orng.json +234 -0
  137. package/src/theme/assets/material.json +235 -0
  138. package/src/theme/assets/matrix.json +77 -0
  139. package/src/theme/assets/mercury.json +252 -0
  140. package/src/theme/assets/monokai.json +221 -0
  141. package/src/theme/assets/nightowl.json +221 -0
  142. package/src/theme/assets/nord.json +223 -0
  143. package/src/theme/assets/one-dark.json +84 -0
  144. package/src/theme/assets/opencode.json +245 -0
  145. package/src/theme/assets/orng.json +249 -0
  146. package/src/theme/assets/osaka-jade.json +93 -0
  147. package/src/theme/assets/palenight.json +222 -0
  148. package/src/theme/assets/rosepine.json +234 -0
  149. package/src/theme/assets/solarized.json +223 -0
  150. package/src/theme/assets/synthwave84.json +226 -0
  151. package/src/theme/assets/tokyonight.json +243 -0
  152. package/src/theme/assets/vercel.json +245 -0
  153. package/src/theme/assets/vesper.json +218 -0
  154. package/src/theme/assets/zenburn.json +223 -0
  155. package/src/theme/index.ts +1089 -0
  156. package/src/ui/border.ts +21 -0
  157. package/src/ui/dialog-alert.tsx +66 -0
  158. package/src/ui/dialog-confirm.tsx +108 -0
  159. package/src/ui/dialog-export-options.tsx +217 -0
  160. package/src/ui/dialog-help.tsx +40 -0
  161. package/src/ui/dialog-prompt.tsx +126 -0
  162. package/src/ui/dialog-select.tsx +790 -0
  163. package/src/ui/dialog.tsx +231 -0
  164. package/src/ui/link.tsx +34 -0
  165. package/src/ui/spinner.ts +368 -0
  166. package/src/ui/toast.tsx +102 -0
  167. package/src/util/collapse-tool-output.ts +19 -0
  168. package/src/util/error.ts +182 -0
  169. package/src/util/filetype.ts +130 -0
  170. package/src/util/format.ts +20 -0
  171. package/src/util/layout.ts +25 -0
  172. package/src/util/locale.ts +86 -0
  173. package/src/util/model.ts +28 -0
  174. package/src/util/path.ts +12 -0
  175. package/src/util/persistence.ts +33 -0
  176. package/src/util/presentation.ts +38 -0
  177. package/src/util/provider-origin.ts +7 -0
  178. package/src/util/record.ts +3 -0
  179. package/src/util/renderer.ts +7 -0
  180. package/src/util/revert-diff.ts +18 -0
  181. package/src/util/scroll.ts +27 -0
  182. package/src/util/selection.ts +79 -0
  183. package/src/util/session.ts +3 -0
  184. package/src/util/signal.ts +51 -0
  185. package/src/util/system.ts +20 -0
  186. package/src/util/tool-display.ts +13 -0
  187. package/src/util/transcript.ts +112 -0
  188. package/sst-env.d.ts +10 -0
  189. package/test/app-lifecycle.test.tsx +128 -0
  190. package/test/cli/cmd/tui/dialog-workspace-create.test.ts +28 -0
  191. package/test/cli/cmd/tui/model-options.test.ts +32 -0
  192. package/test/cli/cmd/tui/notifications.test.ts +267 -0
  193. package/test/cli/cmd/tui/provider-options.test.ts +41 -0
  194. package/test/cli/cmd/tui/sync-fixture.tsx +70 -0
  195. package/test/cli/cmd/tui/sync-live-hydration.test.tsx +262 -0
  196. package/test/cli/cmd/tui/sync-undefined-messages.test.tsx +43 -0
  197. package/test/cli/cmd/tui/sync.test.tsx +65 -0
  198. package/test/cli/tui/__snapshots__/inline-tool-wrap-snapshot.test.tsx.snap +92 -0
  199. package/test/cli/tui/data.test.tsx +486 -0
  200. package/test/cli/tui/dialog-prompt.test.tsx +147 -0
  201. package/test/cli/tui/diff-viewer-file-tree.test.tsx +200 -0
  202. package/test/cli/tui/diff-viewer.test.tsx +268 -0
  203. package/test/cli/tui/inline-tool-wrap-snapshot.test.tsx +351 -0
  204. package/test/cli/tui/prompt-submit-race.test.ts +98 -0
  205. package/test/cli/tui/thinking.test.ts +36 -0
  206. package/test/cli/tui/use-event.test.tsx +148 -0
  207. package/test/clipboard.test.ts +19 -0
  208. package/test/component/dialog-session-list.test.ts +46 -0
  209. package/test/config.test.tsx +127 -0
  210. package/test/context/local.test.ts +22 -0
  211. package/test/editor.test.ts +32 -0
  212. package/test/feature-plugins/diff-viewer-file-tree-utils.test.ts +323 -0
  213. package/test/fixture/fixture.ts +13 -0
  214. package/test/fixture/tui-environment.tsx +32 -0
  215. package/test/fixture/tui-plugin.ts +36 -0
  216. package/test/fixture/tui-runtime.ts +12 -0
  217. package/test/fixture/tui-sdk.ts +109 -0
  218. package/test/index.test.tsx +6 -0
  219. package/test/keymap.test.tsx +141 -0
  220. package/test/plugin/runtime.test.ts +50 -0
  221. package/test/plugin/slots.test.tsx +38 -0
  222. package/test/prompt/display.test.ts +33 -0
  223. package/test/prompt/history.test.ts +39 -0
  224. package/test/prompt/jsonl.test.ts +24 -0
  225. package/test/prompt/local-attachment.test.ts +43 -0
  226. package/test/prompt/part.test.ts +53 -0
  227. package/test/prompt/persistence.test.ts +23 -0
  228. package/test/prompt/traits.test.ts +25 -0
  229. package/test/runtime.test.tsx +37 -0
  230. package/test/theme.test.ts +81 -0
  231. package/test/util/error.test.ts +49 -0
  232. package/test/util/filetype.test.ts +16 -0
  233. package/test/util/format.test.ts +59 -0
  234. package/test/util/model.test.ts +9 -0
  235. package/test/util/presentation.test.ts +8 -0
  236. package/test/util/renderer.test.ts +30 -0
  237. package/test/util/revert-diff.test.ts +35 -0
  238. package/test/util/session.test.ts +10 -0
  239. package/test/util/tool-display.test.ts +40 -0
  240. package/test/util/transcript.test.ts +421 -0
  241. package/tsconfig.json +10 -0
@@ -0,0 +1,21 @@
1
+ export const EmptyBorder = {
2
+ topLeft: "",
3
+ bottomLeft: "",
4
+ vertical: "",
5
+ topRight: "",
6
+ bottomRight: "",
7
+ horizontal: " ",
8
+ bottomT: "",
9
+ topT: "",
10
+ cross: "",
11
+ leftT: "",
12
+ rightT: "",
13
+ }
14
+
15
+ export const SplitBorder = {
16
+ border: ["left" as const, "right" as const],
17
+ customBorderChars: {
18
+ ...EmptyBorder,
19
+ vertical: "┃",
20
+ },
21
+ }
@@ -0,0 +1,66 @@
1
+ import { TextAttributes } from "@opentui/core"
2
+ import { useTheme } from "../context/theme"
3
+ import { useDialog, type DialogContext } from "./dialog"
4
+ import { useBindings } from "../keymap"
5
+
6
+ export type DialogAlertProps = {
7
+ title: string
8
+ message: string
9
+ onConfirm?: () => void
10
+ }
11
+
12
+ export function DialogAlert(props: DialogAlertProps) {
13
+ const dialog = useDialog()
14
+ const { theme } = useTheme()
15
+
16
+ useBindings(() => ({
17
+ bindings: [
18
+ {
19
+ key: "return",
20
+ desc: "Confirm alert",
21
+ group: "Dialog",
22
+ cmd: () => {
23
+ props.onConfirm?.()
24
+ dialog.clear()
25
+ },
26
+ },
27
+ ],
28
+ }))
29
+ return (
30
+ <box paddingLeft={2} paddingRight={2} gap={1}>
31
+ <box flexDirection="row" justifyContent="space-between">
32
+ <text attributes={TextAttributes.BOLD} fg={theme.text}>
33
+ {props.title}
34
+ </text>
35
+ <text fg={theme.textMuted} onMouseUp={() => dialog.clear()}>
36
+ esc
37
+ </text>
38
+ </box>
39
+ <box paddingBottom={1}>
40
+ <text fg={theme.textMuted}>{props.message}</text>
41
+ </box>
42
+ <box flexDirection="row" justifyContent="flex-end" paddingBottom={1}>
43
+ <box
44
+ paddingLeft={3}
45
+ paddingRight={3}
46
+ backgroundColor={theme.primary}
47
+ onMouseUp={() => {
48
+ props.onConfirm?.()
49
+ dialog.clear()
50
+ }}
51
+ >
52
+ <text fg={theme.selectedListItemText}>ok</text>
53
+ </box>
54
+ </box>
55
+ </box>
56
+ )
57
+ }
58
+
59
+ DialogAlert.show = (dialog: DialogContext, title: string, message: string) => {
60
+ return new Promise<void>((resolve) => {
61
+ dialog.replace(
62
+ () => <DialogAlert title={title} message={message} onConfirm={() => resolve()} />,
63
+ () => resolve(),
64
+ )
65
+ })
66
+ }
@@ -0,0 +1,108 @@
1
+ import { TextAttributes } from "@opentui/core"
2
+ import { useTheme } from "../context/theme"
3
+ import { useDialog, type DialogContext } from "./dialog"
4
+ import { createStore } from "solid-js/store"
5
+ import { For } from "solid-js"
6
+ import { Locale } from "../util/locale"
7
+ import { useBindings } from "../keymap"
8
+
9
+ export type DialogConfirmProps = {
10
+ title: string
11
+ message: string
12
+ onConfirm?: () => void
13
+ onCancel?: () => void
14
+ label?: string
15
+ }
16
+
17
+ export type DialogConfirmResult = boolean | undefined
18
+
19
+ export function DialogConfirm(props: DialogConfirmProps) {
20
+ const dialog = useDialog()
21
+ const { theme } = useTheme()
22
+ const [store, setStore] = createStore({
23
+ active: "confirm" as "confirm" | "cancel",
24
+ })
25
+
26
+ useBindings(() => ({
27
+ bindings: [
28
+ {
29
+ key: "return",
30
+ desc: "Confirm dialog selection",
31
+ group: "Dialog",
32
+ cmd: () => {
33
+ if (store.active === "confirm") props.onConfirm?.()
34
+ if (store.active === "cancel") props.onCancel?.()
35
+ dialog.clear()
36
+ },
37
+ },
38
+ {
39
+ key: "left",
40
+ desc: "Previous dialog option",
41
+ group: "Dialog",
42
+ cmd: () => {
43
+ setStore("active", store.active === "confirm" ? "cancel" : "confirm")
44
+ },
45
+ },
46
+ {
47
+ key: "right",
48
+ desc: "Next dialog option",
49
+ group: "Dialog",
50
+ cmd: () => {
51
+ setStore("active", store.active === "confirm" ? "cancel" : "confirm")
52
+ },
53
+ },
54
+ ],
55
+ }))
56
+ return (
57
+ <box paddingLeft={2} paddingRight={2} gap={1}>
58
+ <box flexDirection="row" justifyContent="space-between">
59
+ <text attributes={TextAttributes.BOLD} fg={theme.text}>
60
+ {props.title}
61
+ </text>
62
+ <text fg={theme.textMuted} onMouseUp={() => dialog.clear()}>
63
+ esc
64
+ </text>
65
+ </box>
66
+ <box paddingBottom={1}>
67
+ <text fg={theme.textMuted}>{props.message}</text>
68
+ </box>
69
+ <box flexDirection="row" justifyContent="flex-end" paddingBottom={1}>
70
+ <For each={["cancel", "confirm"] as const}>
71
+ {(key) => (
72
+ <box
73
+ paddingLeft={1}
74
+ paddingRight={1}
75
+ backgroundColor={key === store.active ? theme.primary : undefined}
76
+ onMouseUp={() => {
77
+ if (key === "confirm") props.onConfirm?.()
78
+ if (key === "cancel") props.onCancel?.()
79
+ dialog.clear()
80
+ }}
81
+ >
82
+ <text fg={key === store.active ? theme.selectedListItemText : theme.textMuted}>
83
+ {Locale.titlecase(key === "cancel" ? (props.label ?? key) : key)}
84
+ </text>
85
+ </box>
86
+ )}
87
+ </For>
88
+ </box>
89
+ </box>
90
+ )
91
+ }
92
+
93
+ DialogConfirm.show = (dialog: DialogContext, title: string, message: string, label?: string) => {
94
+ return new Promise<DialogConfirmResult>((resolve) => {
95
+ dialog.replace(
96
+ () => (
97
+ <DialogConfirm
98
+ title={title}
99
+ message={message}
100
+ onConfirm={() => resolve(true)}
101
+ onCancel={() => resolve(false)}
102
+ label={label}
103
+ />
104
+ ),
105
+ () => resolve(undefined),
106
+ )
107
+ })
108
+ }
@@ -0,0 +1,217 @@
1
+ import { TextareaRenderable, TextAttributes } from "@opentui/core"
2
+ import { useTheme } from "../context/theme"
3
+ import { useDialog, type DialogContext } from "./dialog"
4
+ import { createStore } from "solid-js/store"
5
+ import { onMount, Show } from "solid-js"
6
+ import { useBindings } from "../keymap"
7
+
8
+ export type DialogExportOptionsProps = {
9
+ defaultFilename: string
10
+ defaultThinking: boolean
11
+ defaultToolDetails: boolean
12
+ defaultAssistantMetadata: boolean
13
+ defaultOpenWithoutSaving: boolean
14
+ onConfirm?: (options: {
15
+ filename: string
16
+ thinking: boolean
17
+ toolDetails: boolean
18
+ assistantMetadata: boolean
19
+ openWithoutSaving: boolean
20
+ }) => void
21
+ onCancel?: () => void
22
+ }
23
+
24
+ export function DialogExportOptions(props: DialogExportOptionsProps) {
25
+ const dialog = useDialog()
26
+ const { theme } = useTheme()
27
+ let textarea: TextareaRenderable
28
+ const [store, setStore] = createStore({
29
+ thinking: props.defaultThinking,
30
+ toolDetails: props.defaultToolDetails,
31
+ assistantMetadata: props.defaultAssistantMetadata,
32
+ openWithoutSaving: props.defaultOpenWithoutSaving,
33
+ active: "filename" as "filename" | "thinking" | "toolDetails" | "assistantMetadata" | "openWithoutSaving",
34
+ })
35
+
36
+ useBindings(() => ({
37
+ bindings: [
38
+ {
39
+ key: "tab",
40
+ desc: "Next export option",
41
+ group: "Dialog",
42
+ cmd: () => {
43
+ const order: Array<"filename" | "thinking" | "toolDetails" | "assistantMetadata" | "openWithoutSaving"> = [
44
+ "filename",
45
+ "thinking",
46
+ "toolDetails",
47
+ "assistantMetadata",
48
+ "openWithoutSaving",
49
+ ]
50
+ const currentIndex = order.indexOf(store.active)
51
+ const nextIndex = (currentIndex + 1) % order.length
52
+ setStore("active", order[nextIndex])
53
+ },
54
+ },
55
+ ],
56
+ }))
57
+
58
+ useBindings(() => ({
59
+ enabled: store.active !== "filename",
60
+ bindings: [
61
+ {
62
+ key: "space",
63
+ desc: "Toggle export option",
64
+ group: "Dialog",
65
+ cmd: () => {
66
+ if (store.active === "thinking") setStore("thinking", !store.thinking)
67
+ if (store.active === "toolDetails") setStore("toolDetails", !store.toolDetails)
68
+ if (store.active === "assistantMetadata") setStore("assistantMetadata", !store.assistantMetadata)
69
+ if (store.active === "openWithoutSaving") setStore("openWithoutSaving", !store.openWithoutSaving)
70
+ },
71
+ },
72
+ ],
73
+ }))
74
+
75
+ onMount(() => {
76
+ dialog.setSize("medium")
77
+ setTimeout(() => {
78
+ if (!textarea || textarea.isDestroyed) return
79
+ textarea.focus()
80
+ }, 1)
81
+ textarea.gotoLineEnd()
82
+ })
83
+
84
+ return (
85
+ <box paddingLeft={2} paddingRight={2} gap={1}>
86
+ <box flexDirection="row" justifyContent="space-between">
87
+ <text attributes={TextAttributes.BOLD} fg={theme.text}>
88
+ Export Options
89
+ </text>
90
+ <text fg={theme.textMuted} onMouseUp={() => dialog.clear()}>
91
+ esc
92
+ </text>
93
+ </box>
94
+ <box gap={1}>
95
+ <box>
96
+ <text fg={theme.text}>Filename:</text>
97
+ </box>
98
+ <textarea
99
+ onSubmit={() => {
100
+ props.onConfirm?.({
101
+ filename: textarea.plainText,
102
+ thinking: store.thinking,
103
+ toolDetails: store.toolDetails,
104
+ assistantMetadata: store.assistantMetadata,
105
+ openWithoutSaving: store.openWithoutSaving,
106
+ })
107
+ }}
108
+ height={3}
109
+ ref={(val: TextareaRenderable) => {
110
+ textarea = val
111
+ val.traits = { status: "FILENAME" }
112
+ }}
113
+ initialValue={props.defaultFilename}
114
+ placeholder="Enter filename"
115
+ placeholderColor={theme.textMuted}
116
+ textColor={theme.text}
117
+ focusedTextColor={theme.text}
118
+ cursorColor={theme.text}
119
+ />
120
+ </box>
121
+ <box flexDirection="column">
122
+ <box
123
+ flexDirection="row"
124
+ gap={2}
125
+ paddingLeft={1}
126
+ backgroundColor={store.active === "thinking" ? theme.backgroundElement : undefined}
127
+ onMouseUp={() => setStore("active", "thinking")}
128
+ >
129
+ <text fg={store.active === "thinking" ? theme.primary : theme.textMuted}>
130
+ {store.thinking ? "[x]" : "[ ]"}
131
+ </text>
132
+ <text fg={store.active === "thinking" ? theme.primary : theme.text}>Include thinking</text>
133
+ </box>
134
+ <box
135
+ flexDirection="row"
136
+ gap={2}
137
+ paddingLeft={1}
138
+ backgroundColor={store.active === "toolDetails" ? theme.backgroundElement : undefined}
139
+ onMouseUp={() => setStore("active", "toolDetails")}
140
+ >
141
+ <text fg={store.active === "toolDetails" ? theme.primary : theme.textMuted}>
142
+ {store.toolDetails ? "[x]" : "[ ]"}
143
+ </text>
144
+ <text fg={store.active === "toolDetails" ? theme.primary : theme.text}>Include tool details</text>
145
+ </box>
146
+ <box
147
+ flexDirection="row"
148
+ gap={2}
149
+ paddingLeft={1}
150
+ backgroundColor={store.active === "assistantMetadata" ? theme.backgroundElement : undefined}
151
+ onMouseUp={() => setStore("active", "assistantMetadata")}
152
+ >
153
+ <text fg={store.active === "assistantMetadata" ? theme.primary : theme.textMuted}>
154
+ {store.assistantMetadata ? "[x]" : "[ ]"}
155
+ </text>
156
+ <text fg={store.active === "assistantMetadata" ? theme.primary : theme.text}>Include assistant metadata</text>
157
+ </box>
158
+ <box
159
+ flexDirection="row"
160
+ gap={2}
161
+ paddingLeft={1}
162
+ backgroundColor={store.active === "openWithoutSaving" ? theme.backgroundElement : undefined}
163
+ onMouseUp={() => setStore("active", "openWithoutSaving")}
164
+ >
165
+ <text fg={store.active === "openWithoutSaving" ? theme.primary : theme.textMuted}>
166
+ {store.openWithoutSaving ? "[x]" : "[ ]"}
167
+ </text>
168
+ <text fg={store.active === "openWithoutSaving" ? theme.primary : theme.text}>Open without saving</text>
169
+ </box>
170
+ </box>
171
+ <Show when={store.active !== "filename"}>
172
+ <text fg={theme.textMuted} paddingBottom={1}>
173
+ Press <span style={{ fg: theme.text }}>space</span> to toggle, <span style={{ fg: theme.text }}>return</span>{" "}
174
+ to confirm
175
+ </text>
176
+ </Show>
177
+ <Show when={store.active === "filename"}>
178
+ <text fg={theme.textMuted} paddingBottom={1}>
179
+ Press <span style={{ fg: theme.text }}>return</span> to confirm, <span style={{ fg: theme.text }}>tab</span>{" "}
180
+ for options
181
+ </text>
182
+ </Show>
183
+ </box>
184
+ )
185
+ }
186
+
187
+ DialogExportOptions.show = (
188
+ dialog: DialogContext,
189
+ defaultFilename: string,
190
+ defaultThinking: boolean,
191
+ defaultToolDetails: boolean,
192
+ defaultAssistantMetadata: boolean,
193
+ defaultOpenWithoutSaving: boolean,
194
+ ) => {
195
+ return new Promise<{
196
+ filename: string
197
+ thinking: boolean
198
+ toolDetails: boolean
199
+ assistantMetadata: boolean
200
+ openWithoutSaving: boolean
201
+ } | null>((resolve) => {
202
+ dialog.replace(
203
+ () => (
204
+ <DialogExportOptions
205
+ defaultFilename={defaultFilename}
206
+ defaultThinking={defaultThinking}
207
+ defaultToolDetails={defaultToolDetails}
208
+ defaultAssistantMetadata={defaultAssistantMetadata}
209
+ defaultOpenWithoutSaving={defaultOpenWithoutSaving}
210
+ onConfirm={(options) => resolve(options)}
211
+ onCancel={() => resolve(null)}
212
+ />
213
+ ),
214
+ () => resolve(null),
215
+ )
216
+ })
217
+ }
@@ -0,0 +1,40 @@
1
+ import { TextAttributes } from "@opentui/core"
2
+ import { useTheme } from "../context/theme"
3
+ import { useDialog } from "./dialog"
4
+ import { useBindings, useCommandShortcut } from "../keymap"
5
+
6
+ export function DialogHelp() {
7
+ const dialog = useDialog()
8
+ const { theme } = useTheme()
9
+ const commandShortcut = useCommandShortcut("command.palette.show")
10
+
11
+ useBindings(() => ({
12
+ bindings: [
13
+ { key: "return", desc: "Close help", group: "Dialog", cmd: () => dialog.clear() },
14
+ { key: "escape", desc: "Close help", group: "Dialog", cmd: () => dialog.clear() },
15
+ ],
16
+ }))
17
+
18
+ return (
19
+ <box paddingLeft={2} paddingRight={2} gap={1}>
20
+ <box flexDirection="row" justifyContent="space-between">
21
+ <text attributes={TextAttributes.BOLD} fg={theme.text}>
22
+ Help
23
+ </text>
24
+ <text fg={theme.textMuted} onMouseUp={() => dialog.clear()}>
25
+ esc/enter
26
+ </text>
27
+ </box>
28
+ <box paddingBottom={1}>
29
+ <text fg={theme.textMuted}>
30
+ Press {commandShortcut()} to see all available actions and commands in any context.
31
+ </text>
32
+ </box>
33
+ <box flexDirection="row" justifyContent="flex-end" paddingBottom={1}>
34
+ <box paddingLeft={3} paddingRight={3} backgroundColor={theme.primary} onMouseUp={() => dialog.clear()}>
35
+ <text fg={theme.selectedListItemText}>ok</text>
36
+ </box>
37
+ </box>
38
+ </box>
39
+ )
40
+ }
@@ -0,0 +1,126 @@
1
+ import { TextareaRenderable, TextAttributes } from "@opentui/core"
2
+ import { useTheme } from "../context/theme"
3
+ import { useDialog, type DialogContext } from "./dialog"
4
+ import { Show, createEffect, createSignal, onMount, type JSX } from "solid-js"
5
+ import { Spinner } from "../component/spinner"
6
+ import { useTuiConfig } from "../config"
7
+ import { useBindings, useCommandShortcut } from "../keymap"
8
+
9
+ export type DialogPromptProps = {
10
+ title: string
11
+ description?: () => JSX.Element
12
+ placeholder?: string
13
+ value?: string
14
+ busy?: boolean
15
+ busyText?: string
16
+ onConfirm?: (value: string) => void
17
+ onCancel?: () => void
18
+ }
19
+
20
+ export function DialogPrompt(props: DialogPromptProps) {
21
+ const dialog = useDialog()
22
+ const { theme } = useTheme()
23
+ const tuiConfig = useTuiConfig()
24
+ const submitShortcut = useCommandShortcut("dialog.prompt.submit")
25
+ const [textareaTarget, setTextareaTarget] = createSignal<TextareaRenderable>()
26
+ let textarea: TextareaRenderable
27
+
28
+ function confirm() {
29
+ if (props.busy) return
30
+ props.onConfirm?.(textarea.plainText)
31
+ }
32
+
33
+ useBindings(() => ({
34
+ target: textareaTarget,
35
+ enabled: textareaTarget() !== undefined && !props.busy,
36
+ // Dialog form semantics must win over the global managed textarea input layer.
37
+ priority: 1,
38
+ commands: [
39
+ {
40
+ name: "dialog.prompt.submit",
41
+ title: "Submit dialog prompt",
42
+ category: "Dialog",
43
+ run: confirm,
44
+ },
45
+ ],
46
+ bindings: tuiConfig.keybinds.gather("dialog.prompt", ["dialog.prompt.submit"]),
47
+ }))
48
+
49
+ onMount(() => {
50
+ dialog.setSize("medium")
51
+ setTimeout(() => {
52
+ if (!textarea || textarea.isDestroyed) return
53
+ if (props.busy) return
54
+ textarea.focus()
55
+ }, 1)
56
+ textarea.gotoLineEnd()
57
+ })
58
+
59
+ createEffect(() => {
60
+ if (!textarea || textarea.isDestroyed) return
61
+ const traits = props.busy
62
+ ? {
63
+ suspend: true,
64
+ status: "BUSY",
65
+ }
66
+ : {}
67
+ textarea.traits = traits
68
+ if (props.busy) {
69
+ textarea.blur()
70
+ return
71
+ }
72
+ textarea.focus()
73
+ })
74
+
75
+ return (
76
+ <box paddingLeft={2} paddingRight={2} gap={1}>
77
+ <box flexDirection="row" justifyContent="space-between">
78
+ <text attributes={TextAttributes.BOLD} fg={theme.text}>
79
+ {props.title}
80
+ </text>
81
+ <text fg={theme.textMuted} onMouseUp={() => dialog.clear()}>
82
+ esc
83
+ </text>
84
+ </box>
85
+ <box gap={1}>
86
+ {props.description?.()}
87
+ <textarea
88
+ height={3}
89
+ ref={(val: TextareaRenderable) => {
90
+ textarea = val
91
+ setTextareaTarget(val)
92
+ }}
93
+ initialValue={props.value}
94
+ placeholder={props.placeholder ?? "Enter text"}
95
+ placeholderColor={theme.textMuted}
96
+ textColor={props.busy ? theme.textMuted : theme.text}
97
+ focusedTextColor={props.busy ? theme.textMuted : theme.text}
98
+ cursorColor={props.busy ? theme.backgroundElement : theme.text}
99
+ />
100
+ <Show when={props.busy}>
101
+ <Spinner color={theme.textMuted}>{props.busyText ?? "Working..."}</Spinner>
102
+ </Show>
103
+ </box>
104
+ <box paddingBottom={1} gap={1} flexDirection="row">
105
+ <Show when={!props.busy} fallback={<text fg={theme.textMuted}>processing...</text>}>
106
+ <Show when={submitShortcut()}>
107
+ <text fg={theme.text}>
108
+ {submitShortcut()} <span style={{ fg: theme.textMuted }}>submit</span>
109
+ </text>
110
+ </Show>
111
+ </Show>
112
+ </box>
113
+ </box>
114
+ )
115
+ }
116
+
117
+ DialogPrompt.show = (dialog: DialogContext, title: string, options?: Omit<DialogPromptProps, "title">) => {
118
+ return new Promise<string | null>((resolve) => {
119
+ dialog.replace(
120
+ () => (
121
+ <DialogPrompt title={title} {...options} onConfirm={(value) => resolve(value)} onCancel={() => resolve(null)} />
122
+ ),
123
+ () => resolve(null),
124
+ )
125
+ })
126
+ }