@uncarved/jade 0.1.3 → 0.2.0
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.
- package/bin/jade.js +5 -27
- package/dist/api.d.ts +266 -0
- package/dist/api.js +38 -0
- package/dist/api.js.map +1 -0
- package/dist/config.d.ts +13 -32
- package/dist/config.js +39 -121
- package/dist/config.js.map +1 -1
- package/dist/fetch.d.ts +20 -0
- package/dist/fetch.js +190 -0
- package/dist/fetch.js.map +1 -0
- package/dist/hash.d.ts +2 -0
- package/dist/hash.js +42 -0
- package/dist/hash.js.map +1 -0
- package/dist/host.d.ts +71 -0
- package/dist/host.js +400 -0
- package/dist/host.js.map +1 -0
- package/dist/index.d.ts +11 -30
- package/dist/index.js +11 -30
- package/dist/index.js.map +1 -1
- package/dist/install.d.ts +78 -0
- package/dist/install.js +292 -0
- package/dist/install.js.map +1 -0
- package/dist/main.d.ts +1 -2
- package/dist/main.js +159 -1362
- package/dist/main.js.map +1 -1
- package/dist/manifest.d.ts +23 -0
- package/dist/manifest.js +159 -0
- package/dist/manifest.js.map +1 -0
- package/dist/membrane.d.ts +33 -0
- package/dist/membrane.js +140 -0
- package/dist/membrane.js.map +1 -0
- package/dist/remote.d.ts +10 -0
- package/dist/remote.js +292 -0
- package/dist/remote.js.map +1 -0
- package/dist/rescue.d.ts +10 -0
- package/dist/rescue.js +216 -0
- package/dist/rescue.js.map +1 -0
- package/dist/resolve.d.ts +34 -0
- package/dist/resolve.js +178 -0
- package/dist/resolve.js.map +1 -0
- package/dist/rpc.d.ts +26 -0
- package/dist/rpc.js +144 -0
- package/dist/rpc.js.map +1 -0
- package/dist/secrets.d.ts +12 -0
- package/dist/secrets.js +125 -0
- package/dist/secrets.js.map +1 -0
- package/dist/session.d.ts +45 -0
- package/dist/session.js +401 -0
- package/dist/session.js.map +1 -0
- package/dist/source.d.ts +12 -0
- package/dist/source.js +72 -0
- package/dist/source.js.map +1 -0
- package/dist/state.d.ts +37 -0
- package/dist/state.js +93 -0
- package/dist/state.js.map +1 -0
- package/dist/update.d.ts +2 -0
- package/dist/update.js +6 -3
- package/dist/update.js.map +1 -1
- package/package.json +10 -8
- package/plugins/approval/index.ts +297 -0
- package/plugins/approval/plugin.json +18 -0
- package/{src/plugins → plugins/approval}/policy.ts +21 -100
- package/{src/plugins → plugins/approval}/review.ts +62 -16
- package/plugins/ask/index.ts +159 -0
- package/plugins/ask/plugin.json +8 -0
- package/plugins/budget/index.ts +38 -0
- package/plugins/budget/plugin.json +13 -0
- package/{src/plugins → plugins/checks}/checks.ts +48 -38
- package/plugins/checks/index.ts +158 -0
- package/plugins/checks/plugin.json +14 -0
- package/plugins/checks/project.ts +81 -0
- package/plugins/commands/index.ts +76 -0
- package/plugins/commands/plugin.json +7 -0
- package/{src/plugins → plugins/compact}/compact.ts +73 -38
- package/plugins/compact/index.ts +115 -0
- package/plugins/compact/plugin.json +17 -0
- package/plugins/compact/style.ts +17 -0
- package/plugins/continue/index.ts +58 -0
- package/plugins/continue/plugin.json +13 -0
- package/{src/ui → plugins/fs}/diff.ts +2 -2
- package/{src/tools → plugins/fs}/fs.ts +19 -42
- package/{src/tools → plugins/fs}/grep.ts +1 -1
- package/plugins/fs/index.ts +34 -0
- package/plugins/fs/plugin.json +7 -0
- package/{src/ui → plugins/fs}/renderers.ts +25 -70
- package/plugins/fs/style.ts +18 -0
- package/plugins/fs/sys.ts +81 -0
- package/plugins/keys/index.ts +53 -0
- package/plugins/keys/plugin.json +7 -0
- package/plugins/mcp/index.ts +192 -0
- package/{src → plugins/mcp}/mcp.ts +32 -32
- package/plugins/mcp/plugin.json +7 -0
- package/plugins/mcp/project.ts +93 -0
- package/plugins/memory/index.ts +105 -0
- package/{src → plugins/memory}/memory.ts +20 -2
- package/plugins/memory/notes.ts +43 -0
- package/plugins/memory/plugin.json +7 -0
- package/plugins/memory/style.ts +17 -0
- package/plugins/mentions/attach.ts +127 -0
- package/plugins/mentions/index.ts +79 -0
- package/plugins/mentions/plugin.json +7 -0
- package/plugins/mentions/style.ts +17 -0
- package/plugins/models/config.ts +53 -0
- package/plugins/models/configure.ts +455 -0
- package/plugins/models/context.ts +32 -0
- package/plugins/models/index.ts +198 -0
- package/plugins/models/plugin.json +8 -0
- package/{src → plugins/models}/provider.ts +16 -119
- package/plugins/models/saved.ts +94 -0
- package/plugins/modes/index.ts +222 -0
- package/plugins/modes/plugin.json +9 -0
- package/plugins/plugins/index.ts +38 -0
- package/plugins/plugins/plugin.json +7 -0
- package/plugins/print/index.ts +142 -0
- package/plugins/print/plugin.json +8 -0
- package/plugins/prompts/index.ts +83 -0
- package/plugins/prompts/plugin.json +8 -0
- package/plugins/prompts/prompts.ts +253 -0
- package/plugins/prompts/sys.ts +72 -0
- package/plugins/renderers/index.ts +78 -0
- package/plugins/renderers/plugin.json +7 -0
- package/plugins/repeats/index.ts +165 -0
- package/plugins/repeats/plugin.json +6 -0
- package/plugins/schedule/cron.ts +74 -0
- package/plugins/schedule/index.ts +292 -0
- package/plugins/schedule/plugin.json +13 -0
- package/plugins/schedule/store.ts +149 -0
- package/plugins/scratch/index.ts +31 -0
- package/plugins/scratch/plugin.json +7 -0
- package/plugins/screenshot/index.ts +40 -0
- package/plugins/screenshot/plugin.json +7 -0
- package/plugins/screenshot/sys.ts +84 -0
- package/{src/tools/screenshot.ts → plugins/screenshot/tool.ts} +6 -6
- package/plugins/sessions/index.ts +148 -0
- package/plugins/sessions/plugin.json +8 -0
- package/plugins/shell/index.ts +33 -0
- package/plugins/shell/plugin.json +17 -0
- package/plugins/shell/renderers.ts +45 -0
- package/plugins/shell/service.ts +44 -0
- package/{src/tools → plugins/shell}/shell.ts +31 -20
- package/{src → plugins/shell}/sys.ts +2 -43
- package/plugins/skills/index.ts +96 -0
- package/plugins/skills/plugin.json +7 -0
- package/plugins/skills/project.ts +49 -0
- package/{src → plugins/skills}/skills.ts +4 -11
- package/plugins/suggest/index.ts +286 -0
- package/plugins/suggest/plugin.json +18 -0
- package/plugins/task/index.ts +167 -0
- package/plugins/task/plugin.json +15 -0
- package/plugins/task/style.ts +17 -0
- package/plugins/task/subagent.ts +257 -0
- package/{src/tools/todo.ts → plugins/todo/index.ts} +33 -7
- package/plugins/todo/plugin.json +7 -0
- package/{src/ui → plugins/tui}/editor.ts +3 -0
- package/plugins/tui/frontend.ts +596 -0
- package/plugins/tui/index.ts +37 -0
- package/plugins/tui/mentions.ts +113 -0
- package/plugins/tui/plugin.json +10 -0
- package/{src/ui → plugins/tui}/render.ts +8 -2
- package/{src/ui → plugins/tui}/screen.ts +8 -3
- package/{src/ui → plugins/tui}/transcript.ts +74 -99
- package/{src/ui/tui.tsx → plugins/tui/tui.ts} +358 -387
- package/{src/tools → plugins/undo}/checkpoint.ts +21 -60
- package/plugins/undo/index.ts +139 -0
- package/plugins/undo/notes.ts +43 -0
- package/plugins/undo/plugin.json +7 -0
- package/plugins/undo/style.ts +17 -0
- package/plugins/update/index.ts +40 -0
- package/plugins/update/plugin.json +13 -0
- package/plugins/web/env.ts +78 -0
- package/plugins/web/index.ts +133 -0
- package/plugins/web/plugin.json +15 -0
- package/plugins/web/renderers.ts +11 -0
- package/{src/tools → plugins/web}/web.ts +58 -26
- package/plugins-dist/approval/index.js +271 -0
- package/plugins-dist/approval/plugin.json +24 -0
- package/{dist/plugins → plugins-dist/approval}/policy.js +15 -81
- package/{dist/plugins → plugins-dist/approval}/review.js +56 -10
- package/{dist/plugins → plugins-dist/approval}/schema.js +0 -1
- package/plugins-dist/ask/index.js +145 -0
- package/plugins-dist/ask/plugin.json +12 -0
- package/plugins-dist/budget/index.js +37 -0
- package/plugins-dist/budget/plugin.json +15 -0
- package/{dist/plugins → plugins-dist/checks}/checks.js +46 -35
- package/plugins-dist/checks/index.js +150 -0
- package/plugins-dist/checks/plugin.json +21 -0
- package/plugins-dist/checks/project.js +76 -0
- package/plugins-dist/commands/index.js +33 -0
- package/plugins-dist/commands/plugin.json +9 -0
- package/{dist/plugins → plugins-dist/compact}/compact.js +51 -33
- package/plugins-dist/compact/index.js +100 -0
- package/plugins-dist/compact/plugin.json +25 -0
- package/plugins-dist/compact/style.js +14 -0
- package/plugins-dist/continue/index.js +57 -0
- package/plugins-dist/continue/plugin.json +15 -0
- package/{dist/ui → plugins-dist/fs}/diff.js +2 -3
- package/{dist/tools → plugins-dist/fs}/fs.js +17 -42
- package/{dist/tools → plugins-dist/fs}/grep.js +1 -2
- package/plugins-dist/fs/index.js +36 -0
- package/plugins-dist/fs/plugin.json +10 -0
- package/{dist/ui → plugins-dist/fs}/renderers.js +24 -61
- package/plugins-dist/fs/style.js +15 -0
- package/plugins-dist/fs/sys.js +54 -0
- package/plugins-dist/keys/index.js +36 -0
- package/plugins-dist/keys/plugin.json +9 -0
- package/plugins-dist/mcp/index.js +187 -0
- package/{dist → plugins-dist/mcp}/mcp.js +34 -30
- package/plugins-dist/mcp/plugin.json +12 -0
- package/plugins-dist/mcp/project.js +90 -0
- package/plugins-dist/memory/index.js +94 -0
- package/{dist → plugins-dist/memory}/memory.js +21 -3
- package/plugins-dist/memory/notes.js +36 -0
- package/plugins-dist/memory/plugin.json +11 -0
- package/plugins-dist/memory/style.js +14 -0
- package/plugins-dist/mentions/attach.js +120 -0
- package/plugins-dist/mentions/index.js +69 -0
- package/plugins-dist/mentions/plugin.json +9 -0
- package/plugins-dist/mentions/style.js +14 -0
- package/plugins-dist/models/config.js +53 -0
- package/plugins-dist/models/configure.js +415 -0
- package/plugins-dist/models/context.js +27 -0
- package/plugins-dist/models/index.js +167 -0
- package/plugins-dist/models/plugin.json +14 -0
- package/{dist → plugins-dist/models}/provider.js +18 -81
- package/plugins-dist/models/saved.js +80 -0
- package/plugins-dist/modes/index.js +190 -0
- package/plugins-dist/modes/plugin.json +18 -0
- package/plugins-dist/plugins/index.js +37 -0
- package/plugins-dist/plugins/plugin.json +10 -0
- package/plugins-dist/print/index.js +153 -0
- package/plugins-dist/print/plugin.json +14 -0
- package/plugins-dist/prompts/index.js +57 -0
- package/plugins-dist/prompts/plugin.json +13 -0
- package/plugins-dist/prompts/prompts.js +227 -0
- package/plugins-dist/prompts/sys.js +46 -0
- package/plugins-dist/renderers/index.js +36 -0
- package/plugins-dist/renderers/plugin.json +9 -0
- package/plugins-dist/repeats/index.js +165 -0
- package/plugins-dist/repeats/plugin.json +6 -0
- package/plugins-dist/schedule/cron.js +67 -0
- package/plugins-dist/schedule/index.js +281 -0
- package/plugins-dist/schedule/plugin.json +16 -0
- package/plugins-dist/schedule/store.js +125 -0
- package/plugins-dist/scratch/index.js +26 -0
- package/plugins-dist/scratch/plugin.json +10 -0
- package/plugins-dist/screenshot/index.js +35 -0
- package/plugins-dist/screenshot/plugin.json +11 -0
- package/plugins-dist/screenshot/sys.js +76 -0
- package/{dist/tools/screenshot.js → plugins-dist/screenshot/tool.js} +5 -4
- package/plugins-dist/sessions/index.js +136 -0
- package/plugins-dist/sessions/plugin.json +12 -0
- package/plugins-dist/shell/index.js +33 -0
- package/plugins-dist/shell/plugin.json +19 -0
- package/plugins-dist/shell/renderers.js +40 -0
- package/plugins-dist/shell/service.js +29 -0
- package/{dist/tools → plugins-dist/shell}/shell.js +31 -22
- package/{dist → plugins-dist/shell}/sys.js +2 -43
- package/plugins-dist/skills/index.js +90 -0
- package/plugins-dist/skills/plugin.json +12 -0
- package/plugins-dist/skills/project.js +47 -0
- package/{dist → plugins-dist/skills}/skills.js +3 -7
- package/plugins-dist/suggest/index.js +282 -0
- package/plugins-dist/suggest/plugin.json +23 -0
- package/plugins-dist/task/index.js +151 -0
- package/plugins-dist/task/plugin.json +23 -0
- package/plugins-dist/task/style.js +14 -0
- package/plugins-dist/task/subagent.js +208 -0
- package/{dist/tools/todo.js → plugins-dist/todo/index.js} +29 -7
- package/plugins-dist/todo/plugin.json +9 -0
- package/{dist/ui → plugins-dist/tui}/editor.js +3 -1
- package/plugins-dist/tui/frontend.js +586 -0
- package/{dist → plugins-dist/tui}/history.js +0 -1
- package/plugins-dist/tui/index.js +21 -0
- package/{dist/ui → plugins-dist/tui}/markdown.js +0 -1
- package/plugins-dist/tui/mentions.js +115 -0
- package/plugins-dist/tui/plugin.json +25 -0
- package/{dist/ui → plugins-dist/tui}/render.js +7 -3
- package/{dist/ui → plugins-dist/tui}/screen.js +6 -2
- package/{dist/ui → plugins-dist/tui}/transcript.js +76 -98
- package/{dist/ui → plugins-dist/tui}/tui.js +185 -53
- package/{dist/tools → plugins-dist/undo}/checkpoint.js +21 -55
- package/plugins-dist/undo/index.js +140 -0
- package/plugins-dist/undo/notes.js +36 -0
- package/plugins-dist/undo/plugin.json +9 -0
- package/plugins-dist/undo/style.js +14 -0
- package/plugins-dist/update/index.js +34 -0
- package/plugins-dist/update/plugin.json +15 -0
- package/plugins-dist/web/env.js +80 -0
- package/plugins-dist/web/index.js +124 -0
- package/plugins-dist/web/plugin.json +21 -0
- package/plugins-dist/web/renderers.js +7 -0
- package/{dist/tools → plugins-dist/web}/web.js +50 -24
- package/sdk/python/__pycache__/jade_plugin.cpython-312.pyc +0 -0
- package/sdk/python/jade_plugin.py +380 -0
- package/src/api.ts +298 -0
- package/src/config.ts +32 -134
- package/src/fetch.ts +216 -0
- package/src/hash.ts +39 -0
- package/src/host.ts +429 -0
- package/src/index.ts +23 -30
- package/src/install.ts +355 -0
- package/src/main.ts +155 -1387
- package/src/manifest.ts +160 -0
- package/src/membrane.ts +142 -0
- package/src/remote.ts +288 -0
- package/src/rescue.ts +217 -0
- package/src/resolve.ts +199 -0
- package/src/rpc.ts +144 -0
- package/src/secrets.ts +122 -0
- package/src/session.ts +458 -0
- package/src/source.ts +83 -0
- package/src/state.ts +120 -0
- package/src/update.ts +265 -262
- package/LICENSE +0 -21
- package/README.md +0 -204
- package/dist/commands.d.ts +0 -50
- package/dist/commands.js +0 -126
- package/dist/commands.js.map +0 -1
- package/dist/context.d.ts +0 -17
- package/dist/context.js +0 -53
- package/dist/context.js.map +0 -1
- package/dist/distro.d.ts +0 -141
- package/dist/distro.js +0 -462
- package/dist/distro.js.map +0 -1
- package/dist/history.d.ts +0 -10
- package/dist/history.js.map +0 -1
- package/dist/mcp.d.ts +0 -114
- package/dist/mcp.js.map +0 -1
- package/dist/memory.d.ts +0 -19
- package/dist/memory.js.map +0 -1
- package/dist/mentions.d.ts +0 -35
- package/dist/mentions.js +0 -130
- package/dist/mentions.js.map +0 -1
- package/dist/plugin-cli.d.ts +0 -16
- package/dist/plugin-cli.js +0 -294
- package/dist/plugin-cli.js.map +0 -1
- package/dist/plugins/budget.d.ts +0 -9
- package/dist/plugins/budget.js +0 -30
- package/dist/plugins/budget.js.map +0 -1
- package/dist/plugins/builtins.d.ts +0 -10
- package/dist/plugins/builtins.js +0 -25
- package/dist/plugins/builtins.js.map +0 -1
- package/dist/plugins/checks.d.ts +0 -71
- package/dist/plugins/checks.js.map +0 -1
- package/dist/plugins/compact.d.ts +0 -26
- package/dist/plugins/compact.js.map +0 -1
- package/dist/plugins/core.d.ts +0 -47
- package/dist/plugins/core.js +0 -229
- package/dist/plugins/core.js.map +0 -1
- package/dist/plugins/host.d.ts +0 -52
- package/dist/plugins/host.js +0 -115
- package/dist/plugins/host.js.map +0 -1
- package/dist/plugins/install.d.ts +0 -68
- package/dist/plugins/install.js +0 -377
- package/dist/plugins/install.js.map +0 -1
- package/dist/plugins/loader.d.ts +0 -410
- package/dist/plugins/loader.js +0 -407
- package/dist/plugins/loader.js.map +0 -1
- package/dist/plugins/policy.d.ts +0 -98
- package/dist/plugins/policy.js.map +0 -1
- package/dist/plugins/prompts.d.ts +0 -43
- package/dist/plugins/prompts.js +0 -284
- package/dist/plugins/prompts.js.map +0 -1
- package/dist/plugins/repeats.d.ts +0 -16
- package/dist/plugins/repeats.js +0 -151
- package/dist/plugins/repeats.js.map +0 -1
- package/dist/plugins/review.d.ts +0 -18
- package/dist/plugins/review.js.map +0 -1
- package/dist/plugins/schema.d.ts +0 -2
- package/dist/plugins/schema.js.map +0 -1
- package/dist/plugins/sessions.d.ts +0 -7
- package/dist/plugins/sessions.js +0 -110
- package/dist/plugins/sessions.js.map +0 -1
- package/dist/provider.d.ts +0 -165
- package/dist/provider.js.map +0 -1
- package/dist/session-lifecycle.d.ts +0 -61
- package/dist/session-lifecycle.js +0 -167
- package/dist/session-lifecycle.js.map +0 -1
- package/dist/session-scope.d.ts +0 -53
- package/dist/session-scope.js +0 -116
- package/dist/session-scope.js.map +0 -1
- package/dist/sessions.d.ts +0 -28
- package/dist/sessions.js +0 -73
- package/dist/sessions.js.map +0 -1
- package/dist/skills.d.ts +0 -37
- package/dist/skills.js.map +0 -1
- package/dist/sys.d.ts +0 -51
- package/dist/sys.js.map +0 -1
- package/dist/tools/ask.d.ts +0 -11
- package/dist/tools/ask.js +0 -62
- package/dist/tools/ask.js.map +0 -1
- package/dist/tools/checkpoint.d.ts +0 -43
- package/dist/tools/checkpoint.js.map +0 -1
- package/dist/tools/fs.d.ts +0 -39
- package/dist/tools/fs.js.map +0 -1
- package/dist/tools/grep.d.ts +0 -6
- package/dist/tools/grep.js.map +0 -1
- package/dist/tools/screenshot.d.ts +0 -15
- package/dist/tools/screenshot.js.map +0 -1
- package/dist/tools/shell.d.ts +0 -55
- package/dist/tools/shell.js.map +0 -1
- package/dist/tools/task.d.ts +0 -39
- package/dist/tools/task.js +0 -117
- package/dist/tools/task.js.map +0 -1
- package/dist/tools/todo.d.ts +0 -10
- package/dist/tools/todo.js.map +0 -1
- package/dist/tools/web.d.ts +0 -53
- package/dist/tools/web.js.map +0 -1
- package/dist/ui/configure.d.ts +0 -20
- package/dist/ui/configure.js +0 -447
- package/dist/ui/configure.js.map +0 -1
- package/dist/ui/diff.d.ts +0 -20
- package/dist/ui/diff.js.map +0 -1
- package/dist/ui/editor.d.ts +0 -41
- package/dist/ui/editor.js.map +0 -1
- package/dist/ui/markdown.d.ts +0 -22
- package/dist/ui/markdown.js.map +0 -1
- package/dist/ui/render.d.ts +0 -14
- package/dist/ui/render.js.map +0 -1
- package/dist/ui/renderers.d.ts +0 -8
- package/dist/ui/renderers.js.map +0 -1
- package/dist/ui/screen.d.ts +0 -118
- package/dist/ui/screen.js.map +0 -1
- package/dist/ui/transcript.d.ts +0 -46
- package/dist/ui/transcript.js.map +0 -1
- package/dist/ui/tui.d.ts +0 -47
- package/dist/ui/tui.js.map +0 -1
- package/src/commands.ts +0 -144
- package/src/context.ts +0 -64
- package/src/distro.ts +0 -577
- package/src/mentions.ts +0 -135
- package/src/plugin-cli.ts +0 -278
- package/src/plugins/budget.ts +0 -37
- package/src/plugins/builtins.ts +0 -34
- package/src/plugins/core.ts +0 -257
- package/src/plugins/host.ts +0 -146
- package/src/plugins/install.ts +0 -429
- package/src/plugins/loader.ts +0 -742
- package/src/plugins/prompts.ts +0 -327
- package/src/plugins/repeats.ts +0 -157
- package/src/plugins/sessions.ts +0 -109
- package/src/session-lifecycle.ts +0 -194
- package/src/session-scope.ts +0 -135
- package/src/sessions.ts +0 -78
- package/src/tools/ask.ts +0 -72
- package/src/tools/task.ts +0 -149
- package/src/ui/configure.ts +0 -471
- /package/{src/plugins → plugins/approval}/schema.ts +0 -0
- /package/{src → plugins/tui}/history.ts +0 -0
- /package/{src/ui → plugins/tui}/markdown.ts +0 -0
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// 终端界面(Ink):全屏(备用屏幕缓冲区)分三块——顶部标题(版本、模型、目录),中间是对话,
|
|
2
2
|
// 自己滚动(滚轮、PgUp/PgDn),底部固定显示运行状态、排队的消息、输入框(或对话框)和状态栏。
|
|
3
3
|
// 运行中也能输入:提交的内容由宿主决定立即执行还是排队。
|
|
4
|
+
//
|
|
5
|
+
// 不用 JSX:插件以 .ts 源码加载,Node 的类型剥离不处理 .tsx,所以组件用 createElement(h)写。
|
|
4
6
|
|
|
5
7
|
import { writeSync } from "node:fs";
|
|
6
8
|
import {
|
|
@@ -17,6 +19,7 @@ import {
|
|
|
17
19
|
} from "ink";
|
|
18
20
|
import {
|
|
19
21
|
createContext,
|
|
22
|
+
createElement as h,
|
|
20
23
|
useContext,
|
|
21
24
|
useEffect,
|
|
22
25
|
useReducer,
|
|
@@ -26,7 +29,7 @@ import {
|
|
|
26
29
|
} from "react";
|
|
27
30
|
import stringWidth from "string-width";
|
|
28
31
|
import wrapAnsi from "wrap-ansi";
|
|
29
|
-
import { mentionAt, mentionText, rankPaths } from "
|
|
32
|
+
import { mentionAt, mentionText, rankPaths } from "./mentions.ts";
|
|
30
33
|
import { charWidth, edit, empty, layout, moveRow, offsetAt, type EditState } from "./editor.ts";
|
|
31
34
|
import { expandTabs, markdownStream, type MdLine } from "./markdown.ts";
|
|
32
35
|
import {
|
|
@@ -52,6 +55,8 @@ export interface TuiHandlers {
|
|
|
52
55
|
submit(text: string): void;
|
|
53
56
|
/** 运行中按 Esc 或 Ctrl+C */
|
|
54
57
|
interrupt(): void;
|
|
58
|
+
/** 输入框第一行按 ↑:把排队的消息放回输入框;没有排队的消息时返回 false,↑ 照常翻历史 */
|
|
59
|
+
unqueue?(): boolean;
|
|
55
60
|
/** 空闲时连按两次 Ctrl+C */
|
|
56
61
|
exit(): void;
|
|
57
62
|
/** 输入 @ 时补全用的路径(目录以 / 结尾);每次开始输入一个新的 @ 引用时取一次 */
|
|
@@ -104,6 +109,8 @@ interface UiState {
|
|
|
104
109
|
queued: string[];
|
|
105
110
|
dialogs: Dialog[];
|
|
106
111
|
status: StatusInfo;
|
|
112
|
+
/** 插件设置的灰色提示(ctx.input.hint):输入框为空时显示,Tab 或 → 接受 */
|
|
113
|
+
hint?: string;
|
|
107
114
|
}
|
|
108
115
|
|
|
109
116
|
/** 对话最多保留这么多行(折行前),超出时丢掉最早的一段 */
|
|
@@ -352,7 +359,7 @@ class Store {
|
|
|
352
359
|
this.#owners = [];
|
|
353
360
|
this.#named.clear();
|
|
354
361
|
this.update(
|
|
355
|
-
{ version: this.state.version + 1, live: undefined, progress: [], scroll: 0 },
|
|
362
|
+
{ version: this.state.version + 1, live: undefined, progress: [], scroll: 0, hint: undefined },
|
|
356
363
|
true,
|
|
357
364
|
);
|
|
358
365
|
}
|
|
@@ -375,7 +382,8 @@ export interface TuiOptions {
|
|
|
375
382
|
status: StatusInfo;
|
|
376
383
|
/** 标题里显示的版本号 */
|
|
377
384
|
version: string;
|
|
378
|
-
|
|
385
|
+
/** 斜杠命令菜单的内容;命令随会话的插件增减时传函数,每次显示菜单时取最新的 */
|
|
386
|
+
commands: CommandInfo[] | (() => CommandInfo[]);
|
|
379
387
|
handlers: TuiHandlers;
|
|
380
388
|
/** 之前提交过的输入(旧的在前),↑/↓ 和 Ctrl+R 用 */
|
|
381
389
|
history?: string[];
|
|
@@ -468,7 +476,7 @@ export function tuiScreen(opts: TuiOptions): Screen {
|
|
|
468
476
|
};
|
|
469
477
|
|
|
470
478
|
/** signal 中止时关掉对话框,返回 undefined */
|
|
471
|
-
const ask = <T
|
|
479
|
+
const ask = <T>(dialog: Dialog, signal?: AbortSignal) =>
|
|
472
480
|
new Promise<T>((resolve) => {
|
|
473
481
|
if (signal?.aborted) return resolve(undefined as T);
|
|
474
482
|
const close = () => d.resolve(undefined);
|
|
@@ -490,16 +498,17 @@ export function tuiScreen(opts: TuiOptions): Screen {
|
|
|
490
498
|
// 切到备用屏幕后光标还停在原来的位置(不少终端不会自动归位),Ink 从那里往下画第一帧会让屏幕滚动,
|
|
491
499
|
// 之后每帧只重写变化的行,整个界面就错位了。所以先自己切过去、清屏、把光标移到左上角
|
|
492
500
|
stdout.write("\x1b[?1049h\x1b[2J\x1b[H");
|
|
501
|
+
const commands = opts.commands;
|
|
493
502
|
const instance = render(
|
|
494
|
-
|
|
495
|
-
store
|
|
496
|
-
copy
|
|
497
|
-
version
|
|
498
|
-
commands
|
|
499
|
-
handlers
|
|
500
|
-
history
|
|
501
|
-
draft
|
|
502
|
-
|
|
503
|
+
h(App, {
|
|
504
|
+
store,
|
|
505
|
+
copy: (text: string) => void stdout.write(osc52(text)),
|
|
506
|
+
version: opts.version,
|
|
507
|
+
commands: typeof commands === "function" ? commands : () => commands,
|
|
508
|
+
handlers: opts.handlers,
|
|
509
|
+
history: opts.history ?? [],
|
|
510
|
+
draft,
|
|
511
|
+
}),
|
|
503
512
|
{
|
|
504
513
|
exitOnCtrlC: false,
|
|
505
514
|
alternateScreen: true,
|
|
@@ -603,8 +612,9 @@ export function tuiScreen(opts: TuiOptions): Screen {
|
|
|
603
612
|
const value = text.replace(/\r\n?/g, "\n");
|
|
604
613
|
draft.current?.apply(() => ({ value, cursor: value.length }));
|
|
605
614
|
},
|
|
615
|
+
hint: (text) => store.update({ hint: text ? text.replace(/\r\n?/g, "\n") : undefined }),
|
|
606
616
|
},
|
|
607
|
-
select: <T
|
|
617
|
+
select: <T>(title: string, choices: Choice<T>[], o?: { body?: string; signal?: AbortSignal }) => {
|
|
608
618
|
if (longBusy()) notify(title);
|
|
609
619
|
return ask<T | undefined>(
|
|
610
620
|
{
|
|
@@ -773,7 +783,7 @@ function App({
|
|
|
773
783
|
/** 把选中的文字放进剪贴板 */
|
|
774
784
|
copy(text: string): void;
|
|
775
785
|
version: string;
|
|
776
|
-
commands: CommandInfo[];
|
|
786
|
+
commands: () => CommandInfo[];
|
|
777
787
|
handlers: TuiHandlers;
|
|
778
788
|
history: string[];
|
|
779
789
|
draft: DraftBridge;
|
|
@@ -845,10 +855,16 @@ function App({
|
|
|
845
855
|
};
|
|
846
856
|
|
|
847
857
|
// Ink 增量渲染只用相对光标移动,第一帧起点一旦偏了(启动时终端尺寸还没稳定、窗口缩放、别的输出插进来),
|
|
848
|
-
//
|
|
858
|
+
// 之后每帧都会画错行。尺寸变化后和按 Ctrl+L 时让一帧比终端高,Ink 会清屏从左上角整帧重画(包在同步输出里),下一帧再恢复。
|
|
859
|
+
// 启动时不重画:第一帧之前已经清屏、光标在左上角;这两次清屏在不支持同步输出的终端上(Windows 上常见)看得出闪一下
|
|
849
860
|
const [redraws, setRedraws] = useState(0);
|
|
850
861
|
const [repaint, setRepaint] = useState(false);
|
|
862
|
+
const mounted = useRef(false);
|
|
851
863
|
useEffect(() => {
|
|
864
|
+
if (!mounted.current) {
|
|
865
|
+
mounted.current = true;
|
|
866
|
+
return;
|
|
867
|
+
}
|
|
852
868
|
const t = setTimeout(() => setRepaint(true), 100);
|
|
853
869
|
return () => clearTimeout(t);
|
|
854
870
|
}, [columns, rows, redraws]);
|
|
@@ -904,77 +920,75 @@ function App({
|
|
|
904
920
|
// 总高度要比终端少一行,否则 Ink 认为输出占满了屏幕,每帧清屏重画。
|
|
905
921
|
// 重画那一帧上下各垫一行空白:终端把顶上那行滚出去后,看到的和平时逐行一样,所以不会闪。
|
|
906
922
|
// 只做纵向裁剪:每行都已按宽度折好或截断,横向裁剪会让 Ink 每帧对每一行再切一遍 ANSI 字符串
|
|
907
|
-
return (
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
<
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
923
|
+
return h(
|
|
924
|
+
SelectionContext.Provider,
|
|
925
|
+
{ value: selectionApi },
|
|
926
|
+
h(
|
|
927
|
+
Box,
|
|
928
|
+
{
|
|
929
|
+
flexDirection: "column",
|
|
930
|
+
width: columns,
|
|
931
|
+
height: repaint ? rows + 1 : Math.max(1, rows - 1),
|
|
932
|
+
paddingY: repaint ? 1 : 0,
|
|
933
|
+
overflowY: "hidden",
|
|
934
|
+
},
|
|
935
|
+
// 垫的空白放在外层:里面这层在重画那一帧和平时一样高,对话区的 top(相对父节点)不变,点击换算的行号不会差一行
|
|
936
|
+
h(
|
|
937
|
+
Box,
|
|
938
|
+
{ flexDirection: "column", flexGrow: 1, overflowY: "hidden" },
|
|
939
|
+
h(Header, { status: state.status, version, compact: rows < COMPACT_ROWS }),
|
|
940
|
+
h(
|
|
941
|
+
Box,
|
|
942
|
+
{
|
|
943
|
+
ref,
|
|
944
|
+
flexDirection: "column",
|
|
945
|
+
flexGrow: 1,
|
|
946
|
+
flexShrink: 1,
|
|
947
|
+
flexBasis: 0,
|
|
948
|
+
overflowY: "hidden",
|
|
949
|
+
paddingX: 1,
|
|
950
|
+
},
|
|
951
|
+
shown.map((l, i) => {
|
|
933
952
|
const cols = selection && selectedCols(selection, start + i);
|
|
934
|
-
return (
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
{
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
{
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
<StatusBar status={state.status} width={Math.max(10, columns - 2)} />
|
|
974
|
-
</Box>
|
|
975
|
-
</Box>
|
|
976
|
-
</Box>
|
|
977
|
-
</SelectionContext.Provider>
|
|
953
|
+
return h(Text, { key: i, wrap: "truncate-end" }, cols ? highlight(l || " ", ...cols) : l || " ");
|
|
954
|
+
}),
|
|
955
|
+
scrolled
|
|
956
|
+
? h(
|
|
957
|
+
Text,
|
|
958
|
+
{ dimColor: true, wrap: "truncate-end" },
|
|
959
|
+
`── ↓ ${scroll} more lines · wheel / PgDn to scroll · ctrl+end to jump to the bottom ──`,
|
|
960
|
+
)
|
|
961
|
+
: null,
|
|
962
|
+
),
|
|
963
|
+
h(
|
|
964
|
+
Box,
|
|
965
|
+
{ flexDirection: "column", flexShrink: 0 },
|
|
966
|
+
state.busy && !dialog ? h(Spinner, { label: state.busy.label, since: state.busy.since }) : null,
|
|
967
|
+
state.queued.map((q, i) =>
|
|
968
|
+
h(Text, { key: i, dimColor: true, wrap: "truncate-end" }, " ↳ queued: ", q.replace(/\s+/g, " ")),
|
|
969
|
+
),
|
|
970
|
+
dialog
|
|
971
|
+
? dialog.kind === "select"
|
|
972
|
+
? h(SelectDialog, { key: dialogKey(dialog), dialog })
|
|
973
|
+
: h(InputDialog, { key: dialogKey(dialog), dialog })
|
|
974
|
+
: null,
|
|
975
|
+
h(Prompt, {
|
|
976
|
+
commands,
|
|
977
|
+
handlers,
|
|
978
|
+
history,
|
|
979
|
+
bridge: draft,
|
|
980
|
+
hint: state.hint,
|
|
981
|
+
onHintDone: () => store.update({ hint: undefined }),
|
|
982
|
+
busy: Boolean(state.busy),
|
|
983
|
+
queued: state.queued.length > 0,
|
|
984
|
+
active: !dialog,
|
|
985
|
+
onSubmit: () => store.scrollBy(-max, max),
|
|
986
|
+
flash: copied,
|
|
987
|
+
}),
|
|
988
|
+
h(StatusBar, { status: state.status, width: Math.max(10, columns - 2) }),
|
|
989
|
+
),
|
|
990
|
+
),
|
|
991
|
+
),
|
|
978
992
|
);
|
|
979
993
|
}
|
|
980
994
|
|
|
@@ -986,18 +1000,12 @@ const SHINE = "#b6f2d4";
|
|
|
986
1000
|
* 每个字符上下两个像素;眼睛是玉上挖空的两格,左上角一点高光让它看起来像玉
|
|
987
1001
|
*/
|
|
988
1002
|
function Bot() {
|
|
989
|
-
return (
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
</Text>
|
|
996
|
-
{"████▄"}
|
|
997
|
-
</Text>
|
|
998
|
-
<Text color={JADE}>██ ███ ██</Text>
|
|
999
|
-
<Text color={JADE}>▀███████▀</Text>
|
|
1000
|
-
</Box>
|
|
1003
|
+
return h(
|
|
1004
|
+
Box,
|
|
1005
|
+
{ flexDirection: "column", flexShrink: 0, marginRight: 2 },
|
|
1006
|
+
h(Text, { color: JADE }, " ▄", h(Text, { color: SHINE, backgroundColor: JADE }, "▄"), "████▄"),
|
|
1007
|
+
h(Text, { color: JADE }, "██ ███ ██"),
|
|
1008
|
+
h(Text, { color: JADE }, "▀███████▀"),
|
|
1001
1009
|
);
|
|
1002
1010
|
}
|
|
1003
1011
|
|
|
@@ -1012,49 +1020,37 @@ function Header({
|
|
|
1012
1020
|
compact: boolean;
|
|
1013
1021
|
}) {
|
|
1014
1022
|
const { columns } = useScreenSize();
|
|
1023
|
+
// 模型 · 目录 (分支)
|
|
1024
|
+
const where = [
|
|
1025
|
+
h(Text, { key: "model", color: "cyan" }, status.model),
|
|
1026
|
+
h(Text, { key: "sep", dimColor: true }, " · "),
|
|
1027
|
+
h(Text, { key: "cwd" }, status.cwd),
|
|
1028
|
+
status.branch ? h(Text, { key: "branch", color: "magenta" }, ` (${status.branch})`) : null,
|
|
1029
|
+
];
|
|
1030
|
+
const name = h(Text, { key: "name", color: "cyan", bold: true }, "jade");
|
|
1015
1031
|
if (compact)
|
|
1016
|
-
return (
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
jade
|
|
1021
|
-
</Text>
|
|
1022
|
-
<Text dimColor> · </Text>
|
|
1023
|
-
<Text color="cyan">{status.model}</Text>
|
|
1024
|
-
<Text dimColor> · </Text>
|
|
1025
|
-
<Text>{status.cwd}</Text>
|
|
1026
|
-
{status.branch ? (
|
|
1027
|
-
<Text color="magenta"> ({status.branch})</Text>
|
|
1028
|
-
) : null}
|
|
1029
|
-
</Text>
|
|
1030
|
-
</Box>
|
|
1032
|
+
return h(
|
|
1033
|
+
Box,
|
|
1034
|
+
{ flexShrink: 0, paddingX: 1 },
|
|
1035
|
+
h(Text, { wrap: "truncate-end" }, name, h(Text, { key: "dot", dimColor: true }, " · "), ...where),
|
|
1031
1036
|
);
|
|
1032
|
-
return (
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
{status.branch ? (
|
|
1050
|
-
<Text color="magenta"> ({status.branch})</Text>
|
|
1051
|
-
) : null}
|
|
1052
|
-
</Text>
|
|
1053
|
-
<Text dimColor wrap="truncate-end">
|
|
1054
|
-
/help for commands · @ to attach files
|
|
1055
|
-
</Text>
|
|
1056
|
-
</Box>
|
|
1057
|
-
</Box>
|
|
1037
|
+
return h(
|
|
1038
|
+
Box,
|
|
1039
|
+
{ flexShrink: 0, borderStyle: "round", borderColor: "cyan", paddingX: 1 },
|
|
1040
|
+
columns >= 50 ? h(Bot) : null,
|
|
1041
|
+
h(
|
|
1042
|
+
Box,
|
|
1043
|
+
{ flexDirection: "column", flexGrow: 1, flexShrink: 1 },
|
|
1044
|
+
h(
|
|
1045
|
+
Text,
|
|
1046
|
+
{ wrap: "truncate-end" },
|
|
1047
|
+
name,
|
|
1048
|
+
h(Text, { dimColor: true }, ` v${version}`),
|
|
1049
|
+
status.session ? h(Text, { dimColor: true }, ` · session ${status.session}`) : null,
|
|
1050
|
+
),
|
|
1051
|
+
h(Text, { wrap: "truncate-end" }, ...where),
|
|
1052
|
+
h(Text, { dimColor: true, wrap: "truncate-end" }, "/help for commands · @ to attach files"),
|
|
1053
|
+
),
|
|
1058
1054
|
);
|
|
1059
1055
|
}
|
|
1060
1056
|
|
|
@@ -1071,14 +1067,16 @@ const FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "
|
|
|
1071
1067
|
function Spinner({ label, since }: { label: string; since: number }) {
|
|
1072
1068
|
const now = Date.now();
|
|
1073
1069
|
const seconds = Math.floor((now - since) / 1000);
|
|
1074
|
-
return (
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1070
|
+
return h(
|
|
1071
|
+
Box,
|
|
1072
|
+
{ marginTop: 1 },
|
|
1073
|
+
h(
|
|
1074
|
+
Text,
|
|
1075
|
+
{ wrap: "truncate-end" },
|
|
1076
|
+
h(Text, { color: "cyan" }, `${FRAMES[Math.floor(now / 100) % FRAMES.length]} `),
|
|
1077
|
+
h(Text, null, `${label}… `),
|
|
1078
|
+
h(Text, { dimColor: true }, `(${seconds}s · esc to interrupt)`),
|
|
1079
|
+
),
|
|
1082
1080
|
);
|
|
1083
1081
|
}
|
|
1084
1082
|
|
|
@@ -1181,19 +1179,16 @@ function StatusBar({ status, width }: { status: StatusInfo; width: number }) {
|
|
|
1181
1179
|
},
|
|
1182
1180
|
];
|
|
1183
1181
|
const shown = fitSegments(segments, width);
|
|
1184
|
-
return (
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
))}
|
|
1195
|
-
</Text>
|
|
1196
|
-
</Box>
|
|
1182
|
+
return h(
|
|
1183
|
+
Box,
|
|
1184
|
+
{ paddingX: 1 },
|
|
1185
|
+
h(
|
|
1186
|
+
Text,
|
|
1187
|
+
{ wrap: "truncate-end" },
|
|
1188
|
+
shown.map((s, i) =>
|
|
1189
|
+
h(Text, { key: i }, i ? h(Text, { dimColor: true }, " · ") : null, h(Text, { color: s.color, dimColor: s.dim }, s.text)),
|
|
1190
|
+
),
|
|
1191
|
+
),
|
|
1197
1192
|
);
|
|
1198
1193
|
}
|
|
1199
1194
|
|
|
@@ -1201,11 +1196,7 @@ function StatusBar({ status, width }: { status: StatusInfo; width: number }) {
|
|
|
1201
1196
|
function Hint({ variants, width }: { variants: string[]; width: number }) {
|
|
1202
1197
|
const text =
|
|
1203
1198
|
variants.find((v) => stringWidth(v) <= width) ?? variants.at(-1)!;
|
|
1204
|
-
return (
|
|
1205
|
-
<Text dimColor wrap="truncate-end">
|
|
1206
|
-
{text}
|
|
1207
|
-
</Text>
|
|
1208
|
-
);
|
|
1199
|
+
return h(Text, { dimColor: true, wrap: "truncate-end" }, text);
|
|
1209
1200
|
}
|
|
1210
1201
|
|
|
1211
1202
|
const tokens = (n: number) =>
|
|
@@ -1241,6 +1232,8 @@ function editKey(s: EditState, input: string, key: Key): EditState | undefined {
|
|
|
1241
1232
|
if (key.backspace) return key.meta ? edit.deleteWord(s) : edit.backspace(s);
|
|
1242
1233
|
if (key.delete || (key.ctrl && input === "d")) return edit.del(s);
|
|
1243
1234
|
if (key.ctrl && input === "w") return edit.deleteWord(s);
|
|
1235
|
+
if (key.meta && !key.ctrl && input === "f") return edit.wordRight(s);
|
|
1236
|
+
if (key.meta && !key.ctrl && input === "b") return edit.wordLeft(s);
|
|
1244
1237
|
if (key.ctrl && input === "u") return edit.killBefore(s);
|
|
1245
1238
|
if (key.ctrl && input === "k") return edit.killAfter(s);
|
|
1246
1239
|
if (
|
|
@@ -1325,29 +1318,24 @@ function EditableText({
|
|
|
1325
1318
|
if (now.x !== at.x || now.y !== at.y) recheck();
|
|
1326
1319
|
});
|
|
1327
1320
|
|
|
1328
|
-
return (
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
{
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
{r}
|
|
1347
|
-
</Text>
|
|
1348
|
-
))
|
|
1349
|
-
)}
|
|
1350
|
-
</Box>
|
|
1321
|
+
return h(
|
|
1322
|
+
Box,
|
|
1323
|
+
{ ref, flexDirection: "column" },
|
|
1324
|
+
active ? h(CursorAt, { position }) : null,
|
|
1325
|
+
state.value === "" && placeholder
|
|
1326
|
+
? h(Text, { wrap: "truncate-end" }, h(Text, { color: "cyan" }, prefix), h(Text, { dimColor: true }, placeholder))
|
|
1327
|
+
: rows.map((r, i) =>
|
|
1328
|
+
h(
|
|
1329
|
+
Text,
|
|
1330
|
+
{ key: first + i, wrap: "truncate-end" },
|
|
1331
|
+
h(
|
|
1332
|
+
Text,
|
|
1333
|
+
{ color: "cyan" },
|
|
1334
|
+
first + i === 0 ? prefix : i === 0 ? "↑".padEnd(prefix.length) : " ".repeat(prefix.length),
|
|
1335
|
+
),
|
|
1336
|
+
r,
|
|
1337
|
+
),
|
|
1338
|
+
),
|
|
1351
1339
|
);
|
|
1352
1340
|
}
|
|
1353
1341
|
|
|
@@ -1377,17 +1365,27 @@ function Prompt({
|
|
|
1377
1365
|
handlers,
|
|
1378
1366
|
history: initial,
|
|
1379
1367
|
bridge,
|
|
1368
|
+
hint,
|
|
1369
|
+
onHintDone,
|
|
1380
1370
|
busy,
|
|
1371
|
+
queued,
|
|
1381
1372
|
active,
|
|
1382
1373
|
onSubmit,
|
|
1383
1374
|
flash,
|
|
1384
1375
|
}: {
|
|
1385
|
-
|
|
1376
|
+
/** 当前的命令(随会话的插件增减),每次算菜单时取 */
|
|
1377
|
+
commands: () => CommandInfo[];
|
|
1386
1378
|
handlers: TuiHandlers;
|
|
1387
1379
|
history: string[];
|
|
1388
1380
|
/** 让 tuiScreen 的 draft 读写输入框 */
|
|
1389
1381
|
bridge: DraftBridge;
|
|
1382
|
+
/** 插件设置的灰色提示 */
|
|
1383
|
+
hint?: string;
|
|
1384
|
+
/** 提示被接受了,或者用户开始打字了:去掉它 */
|
|
1385
|
+
onHintDone(): void;
|
|
1390
1386
|
busy: boolean;
|
|
1387
|
+
/** 有排队等待发送的消息 */
|
|
1388
|
+
queued: boolean;
|
|
1391
1389
|
active: boolean;
|
|
1392
1390
|
/** 提交后对话区回到底部 */
|
|
1393
1391
|
onSubmit(): void;
|
|
@@ -1424,7 +1422,7 @@ function Prompt({
|
|
|
1424
1422
|
>(undefined);
|
|
1425
1423
|
|
|
1426
1424
|
const usageOf = (c: CommandInfo) => `/${c.name}${c.args ? ` ${c.args}` : ""}`;
|
|
1427
|
-
const column = Math.max(...commands.map((c) => usageOf(c).length)) + 2;
|
|
1425
|
+
const column = Math.max(...commands().map((c) => usageOf(c).length)) + 2;
|
|
1428
1426
|
|
|
1429
1427
|
/** 由最新的输入算出补全菜单和搜索结果;渲染和按键处理都用它 */
|
|
1430
1428
|
const derive = () => {
|
|
@@ -1439,7 +1437,7 @@ function Prompt({
|
|
|
1439
1437
|
const naming =
|
|
1440
1438
|
!recalled && state.value.startsWith("/") && !/\s/.test(state.value);
|
|
1441
1439
|
const matches = naming
|
|
1442
|
-
? commands.filter((c) => `/${c.name}`.startsWith(state.value))
|
|
1440
|
+
? commands().filter((c) => `/${c.name}`.startsWith(state.value))
|
|
1443
1441
|
: [];
|
|
1444
1442
|
const pick = matches[Math.min(selected, matches.length - 1)];
|
|
1445
1443
|
// @ 引用:光标处正在输入的路径和补全候选
|
|
@@ -1501,7 +1499,11 @@ function Prompt({
|
|
|
1501
1499
|
const firstMatch = around(Math.max(0, matches.indexOf(pick!)), matches.length, menuRows);
|
|
1502
1500
|
const firstFound = around(Math.max(0, found.indexOf(file!)), found.length, menuRows);
|
|
1503
1501
|
|
|
1502
|
+
/** 提示只在空闲、输入框为空、没有在搜索历史时显示,也只有这时能接受 */
|
|
1503
|
+
const hinting = () => hint !== undefined && !busy && current().value === "" && !getSearch();
|
|
1504
1504
|
const set = (s: EditState) => {
|
|
1505
|
+
// 用户开始打字(或者插件改了输入框):提示作废
|
|
1506
|
+
if (s.value && hint !== undefined) onHintDone();
|
|
1505
1507
|
setState(s);
|
|
1506
1508
|
setSelected(0);
|
|
1507
1509
|
setNotice(undefined);
|
|
@@ -1651,6 +1653,12 @@ function Prompt({
|
|
|
1651
1653
|
if (file) return complete(file);
|
|
1652
1654
|
return submit(state.value.trim());
|
|
1653
1655
|
}
|
|
1656
|
+
// Tab 或 →:把提示变成输入框里的文字,接着可以改
|
|
1657
|
+
if (((key.tab && !key.shift) || key.rightArrow) && hinting()) {
|
|
1658
|
+
onHintDone();
|
|
1659
|
+
browsing.current = -1;
|
|
1660
|
+
return set({ value: hint!, cursor: hint!.length });
|
|
1661
|
+
}
|
|
1654
1662
|
if (key.tab && key.shift) return handlers.cycleMode?.();
|
|
1655
1663
|
if (key.tab) {
|
|
1656
1664
|
const { pick, file } = derive();
|
|
@@ -1668,6 +1676,11 @@ function Prompt({
|
|
|
1668
1676
|
// 按折行后的屏幕行移动:一大段没有换行的文字也能上下走,到了第一行才翻历史
|
|
1669
1677
|
const up = moveRow(state, textWidth, -1);
|
|
1670
1678
|
if (up) return setState(up);
|
|
1679
|
+
// 先取回排队的消息,取完了再翻历史
|
|
1680
|
+
if (handlers.unqueue?.()) {
|
|
1681
|
+
browsing.current = -1;
|
|
1682
|
+
return;
|
|
1683
|
+
}
|
|
1671
1684
|
if (browsing.current + 1 < history.current.length) {
|
|
1672
1685
|
if (browsing.current === -1) draft.current = state.value;
|
|
1673
1686
|
recall(browsing.current + 1);
|
|
@@ -1691,132 +1704,116 @@ function Prompt({
|
|
|
1691
1704
|
);
|
|
1692
1705
|
|
|
1693
1706
|
// 对话框打开时隐藏但不卸载,输入到一半的内容和历史都保留
|
|
1694
|
-
return (
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1707
|
+
return h(
|
|
1708
|
+
Box,
|
|
1709
|
+
{ flexDirection: "column", marginTop: 1, display: active ? "flex" : "none" },
|
|
1710
|
+
h(
|
|
1711
|
+
Box,
|
|
1712
|
+
{ borderStyle: "round", borderColor: busy ? "gray" : "cyan", paddingX: 1 },
|
|
1713
|
+
search
|
|
1714
|
+
? h(EditableText, {
|
|
1715
|
+
state: { value: search.query, cursor: search.query.length },
|
|
1716
|
+
width: Math.max(10, columns - 5),
|
|
1717
|
+
prefix: "search history› ",
|
|
1718
|
+
placeholder: "type to filter",
|
|
1719
|
+
active,
|
|
1720
|
+
maxRows: inputRows,
|
|
1721
|
+
})
|
|
1722
|
+
: h(EditableText, {
|
|
1723
|
+
state,
|
|
1724
|
+
width: Math.max(10, columns - 5),
|
|
1725
|
+
prefix: "› ",
|
|
1726
|
+
placeholder: hinting()
|
|
1727
|
+
? hintLine(hint!)
|
|
1728
|
+
: queued
|
|
1729
|
+
? "↑ to edit queued messages · esc to interrupt"
|
|
1730
|
+
: busy
|
|
1731
|
+
? "Type to queue a message · esc to interrupt"
|
|
1732
|
+
: columns >= 70
|
|
1733
|
+
? "Message jade · / commands · @ files · ↑ or ctrl+r for history"
|
|
1734
|
+
: "Message jade · / commands · @ files",
|
|
1735
|
+
active,
|
|
1736
|
+
maxRows: inputRows,
|
|
1737
|
+
place,
|
|
1738
|
+
}),
|
|
1739
|
+
),
|
|
1740
|
+
search
|
|
1741
|
+
? h(
|
|
1742
|
+
Box,
|
|
1743
|
+
{ flexDirection: "column", paddingX: 2 },
|
|
1744
|
+
results.length
|
|
1745
|
+
? results.slice(first, first + menuRows).map((item, i) => {
|
|
1746
|
+
const on = first + i === hit;
|
|
1747
|
+
return h(
|
|
1748
|
+
Text,
|
|
1749
|
+
{ key: first + i, wrap: "truncate-end", color: on ? "cyan" : undefined, bold: on },
|
|
1750
|
+
on ? "❯ " : " ",
|
|
1751
|
+
item.replace(/\s*\n\s*/g, " ⏎ "),
|
|
1752
|
+
);
|
|
1753
|
+
})
|
|
1754
|
+
: h(Text, { dimColor: true }, " no match"),
|
|
1755
|
+
h(Hint, {
|
|
1756
|
+
width: hintWidth,
|
|
1757
|
+
variants: [" ↑↓ or ctrl+r select · enter/tab put in the input · esc cancel", " ↑↓ select · enter use · esc cancel"],
|
|
1758
|
+
}),
|
|
1759
|
+
)
|
|
1760
|
+
: matches.length
|
|
1761
|
+
? h(
|
|
1762
|
+
Box,
|
|
1763
|
+
{ flexDirection: "column", paddingX: 2 },
|
|
1764
|
+
matches.slice(firstMatch, firstMatch + menuRows).map((c) => {
|
|
1765
|
+
const on = c === pick;
|
|
1766
|
+
return h(
|
|
1767
|
+
Text,
|
|
1768
|
+
{ key: c.name, wrap: "truncate-end" },
|
|
1769
|
+
h(Text, { color: on ? "cyan" : undefined, bold: on }, on ? "❯ " : " ", usageOf(c).padEnd(column)),
|
|
1770
|
+
h(Text, { dimColor: true }, c.about),
|
|
1747
1771
|
);
|
|
1748
|
-
})
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
{found.slice(firstFound, firstFound + menuRows).map((p) => {
|
|
1785
|
-
const on = p === file;
|
|
1786
|
-
return (
|
|
1787
|
-
<Text
|
|
1788
|
-
key={p}
|
|
1789
|
-
wrap="truncate-middle"
|
|
1790
|
-
color={on ? "cyan" : p.endsWith("/") ? "blue" : undefined}
|
|
1791
|
-
bold={on}
|
|
1792
|
-
>
|
|
1793
|
-
{on ? "❯ " : " "}
|
|
1794
|
-
{p}
|
|
1795
|
-
</Text>
|
|
1796
|
-
);
|
|
1797
|
-
})}
|
|
1798
|
-
<Hint
|
|
1799
|
-
width={hintWidth}
|
|
1800
|
-
variants={[
|
|
1801
|
-
" ↑↓ select · enter/tab insert the path · the file's content is sent with the message",
|
|
1802
|
-
" ↑↓ select · enter/tab insert the path",
|
|
1803
|
-
" ↑↓ · enter insert",
|
|
1804
|
-
]}
|
|
1805
|
-
/>
|
|
1806
|
-
</Box>
|
|
1807
|
-
) : notice ? (
|
|
1808
|
-
<Text color="yellow"> {notice}</Text>
|
|
1809
|
-
) : null}
|
|
1810
|
-
{/* 压在输入框上边框的右边,不占行,出现和消失时下面的内容不跳 */}
|
|
1811
|
-
{flash ? (
|
|
1812
|
-
<Box position="absolute" top={0} right={2}>
|
|
1813
|
-
<Text color="green"> {flash} </Text>
|
|
1814
|
-
</Box>
|
|
1815
|
-
) : null}
|
|
1816
|
-
</Box>
|
|
1772
|
+
}),
|
|
1773
|
+
h(Hint, {
|
|
1774
|
+
width: hintWidth,
|
|
1775
|
+
variants: [
|
|
1776
|
+
` ↑↓ select · enter run · tab complete${matches.length > menuRows ? ` · ${matches.length} commands` : ""}`,
|
|
1777
|
+
" ↑↓ · enter run · tab complete",
|
|
1778
|
+
],
|
|
1779
|
+
}),
|
|
1780
|
+
)
|
|
1781
|
+
: found.length
|
|
1782
|
+
? h(
|
|
1783
|
+
Box,
|
|
1784
|
+
{ flexDirection: "column", paddingX: 2 },
|
|
1785
|
+
found.slice(firstFound, firstFound + menuRows).map((p) => {
|
|
1786
|
+
const on = p === file;
|
|
1787
|
+
return h(
|
|
1788
|
+
Text,
|
|
1789
|
+
{ key: p, wrap: "truncate-middle", color: on ? "cyan" : p.endsWith("/") ? "blue" : undefined, bold: on },
|
|
1790
|
+
on ? "❯ " : " ",
|
|
1791
|
+
p,
|
|
1792
|
+
);
|
|
1793
|
+
}),
|
|
1794
|
+
h(Hint, {
|
|
1795
|
+
width: hintWidth,
|
|
1796
|
+
variants: [
|
|
1797
|
+
" ↑↓ select · enter/tab insert the path · the file's content is sent with the message",
|
|
1798
|
+
" ↑↓ select · enter/tab insert the path",
|
|
1799
|
+
" ↑↓ · enter insert",
|
|
1800
|
+
],
|
|
1801
|
+
}),
|
|
1802
|
+
)
|
|
1803
|
+
: notice
|
|
1804
|
+
? h(Text, { color: "yellow" }, ` ${notice}`)
|
|
1805
|
+
: null,
|
|
1806
|
+
// 压在输入框上边框的右边,不占行,出现和消失时下面的内容不跳
|
|
1807
|
+
flash ? h(Box, { position: "absolute", top: 0, right: 2 }, h(Text, { color: "green" }, ` ${flash} `)) : null,
|
|
1817
1808
|
);
|
|
1818
1809
|
}
|
|
1819
1810
|
|
|
1811
|
+
/** 提示在输入框里只显示第一行,后面还有时加 … */
|
|
1812
|
+
const hintLine = (hint: string) => {
|
|
1813
|
+
const [first, ...rest] = hint.split("\n");
|
|
1814
|
+
return `${first}${rest.length ? " …" : ""}`;
|
|
1815
|
+
};
|
|
1816
|
+
|
|
1820
1817
|
/** @ 补全最多显示几项 */
|
|
1821
1818
|
const MENTION_ROWS = 8;
|
|
1822
1819
|
|
|
@@ -1901,61 +1898,41 @@ function SelectDialog({
|
|
|
1901
1898
|
});
|
|
1902
1899
|
// 选项多时只显示选中项附近的一段
|
|
1903
1900
|
const start = around(selected, n, visible);
|
|
1904
|
-
return (
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
)
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
{filtering ? "" : `${i + 1}. `}
|
|
1940
|
-
{c.label}
|
|
1941
|
-
</Text>
|
|
1942
|
-
{c.hint ? <Text dimColor> {c.hint}</Text> : null}
|
|
1943
|
-
</Text>
|
|
1944
|
-
);
|
|
1945
|
-
})}
|
|
1946
|
-
{start + visible < n ? (
|
|
1947
|
-
<Text dimColor> ↓ {n - start - visible} more</Text>
|
|
1948
|
-
) : null}
|
|
1949
|
-
</Box>
|
|
1950
|
-
<Hint
|
|
1951
|
-
width={Math.max(10, columns - 4)}
|
|
1952
|
-
variants={
|
|
1953
|
-
filtering
|
|
1954
|
-
? ["↑↓ select · type to filter · enter confirm · esc clear/cancel", "↑↓ · enter · esc"]
|
|
1955
|
-
: ["↑↓ select · enter confirm · esc cancel", "↑↓ · enter · esc"]
|
|
1956
|
-
}
|
|
1957
|
-
/>
|
|
1958
|
-
</Box>
|
|
1901
|
+
return h(
|
|
1902
|
+
Box,
|
|
1903
|
+
{ flexDirection: "column", borderStyle: "round", borderColor: "yellow", paddingX: 1, marginTop: 1 },
|
|
1904
|
+
h(Text, { bold: true, wrap: "truncate-end" }, dialog.title),
|
|
1905
|
+
body.map((l, i) => h(Text, { key: i, wrap: "truncate-end" }, l || " ")),
|
|
1906
|
+
filtering
|
|
1907
|
+
? h(
|
|
1908
|
+
Text,
|
|
1909
|
+
{ wrap: "truncate-end" },
|
|
1910
|
+
h(Text, { color: "cyan" }, "filter› "),
|
|
1911
|
+
query ? h(Text, null, query) : h(Text, { dimColor: true }, `type to filter ${dialog.choices.length} items`),
|
|
1912
|
+
)
|
|
1913
|
+
: null,
|
|
1914
|
+
h(
|
|
1915
|
+
Box,
|
|
1916
|
+
{ flexDirection: "column", marginTop: filtering ? 0 : 1 },
|
|
1917
|
+
start > 0 ? h(Text, { dimColor: true }, ` ↑ ${start} more`) : null,
|
|
1918
|
+
n === 0 ? h(Text, { dimColor: true }, " no match") : null,
|
|
1919
|
+
items.slice(start, start + visible).map(({ c, i }, j) => {
|
|
1920
|
+
const on = start + j === selected;
|
|
1921
|
+
return h(
|
|
1922
|
+
Text,
|
|
1923
|
+
{ key: i, wrap: "truncate-end" },
|
|
1924
|
+
h(Text, { color: on ? "cyan" : undefined, bold: on }, on ? "❯ " : " ", filtering ? "" : `${i + 1}. `, c.label),
|
|
1925
|
+
c.hint ? h(Text, { dimColor: true }, ` ${c.hint}`) : null,
|
|
1926
|
+
);
|
|
1927
|
+
}),
|
|
1928
|
+
start + visible < n ? h(Text, { dimColor: true }, ` ↓ ${n - start - visible} more`) : null,
|
|
1929
|
+
),
|
|
1930
|
+
h(Hint, {
|
|
1931
|
+
width: Math.max(10, columns - 4),
|
|
1932
|
+
variants: filtering
|
|
1933
|
+
? ["↑↓ select · type to filter · enter confirm · esc clear/cancel", "↑↓ · enter · esc"]
|
|
1934
|
+
: ["↑↓ select · enter confirm · esc cancel", "↑↓ · enter · esc"],
|
|
1935
|
+
}),
|
|
1959
1936
|
);
|
|
1960
1937
|
}
|
|
1961
1938
|
|
|
@@ -1984,24 +1961,18 @@ function InputDialog({
|
|
|
1984
1961
|
const next = editKey(state, input, key);
|
|
1985
1962
|
if (next) setState(next);
|
|
1986
1963
|
});
|
|
1987
|
-
return (
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
mask={dialog.mask}
|
|
2001
|
-
placeholder={dialog.placeholder}
|
|
2002
|
-
active
|
|
2003
|
-
/>
|
|
2004
|
-
<Text dimColor>enter confirm · esc cancel</Text>
|
|
2005
|
-
</Box>
|
|
1964
|
+
return h(
|
|
1965
|
+
Box,
|
|
1966
|
+
{ flexDirection: "column", borderStyle: "round", borderColor: "yellow", paddingX: 1, marginTop: 1 },
|
|
1967
|
+
h(Text, { bold: true }, dialog.title),
|
|
1968
|
+
h(EditableText, {
|
|
1969
|
+
state,
|
|
1970
|
+
width: Math.max(10, columns - 6),
|
|
1971
|
+
prefix: "› ",
|
|
1972
|
+
mask: dialog.mask,
|
|
1973
|
+
placeholder: dialog.placeholder,
|
|
1974
|
+
active: true,
|
|
1975
|
+
}),
|
|
1976
|
+
h(Text, { dimColor: true }, "enter confirm · esc cancel"),
|
|
2006
1977
|
);
|
|
2007
1978
|
}
|