@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.
- package/bunfig.toml +4 -0
- package/package.json +72 -0
- package/src/app.tsx +1134 -0
- package/src/attention.ts +260 -0
- package/src/audio.d.ts +9 -0
- package/src/audio.ts +53 -0
- package/src/clipboard.ts +124 -0
- package/src/component/bg-pulse-render.ts +436 -0
- package/src/component/bg-pulse.tsx +99 -0
- package/src/component/command-palette.tsx +79 -0
- package/src/component/dialog-agent.tsx +31 -0
- package/src/component/dialog-console-org.tsx +135 -0
- package/src/component/dialog-debug.tsx +90 -0
- package/src/component/dialog-mcp.tsx +85 -0
- package/src/component/dialog-model.tsx +197 -0
- package/src/component/dialog-move-session.tsx +353 -0
- package/src/component/dialog-provider.tsx +469 -0
- package/src/component/dialog-retry-action.tsx +160 -0
- package/src/component/dialog-session-delete-failed.tsx +99 -0
- package/src/component/dialog-session-list.tsx +364 -0
- package/src/component/dialog-session-rename.tsx +31 -0
- package/src/component/dialog-skill.tsx +70 -0
- package/src/component/dialog-stash.tsx +87 -0
- package/src/component/dialog-status.tsx +168 -0
- package/src/component/dialog-tag.tsx +47 -0
- package/src/component/dialog-theme-list.tsx +50 -0
- package/src/component/dialog-variant.tsx +39 -0
- package/src/component/dialog-workspace-create.tsx +308 -0
- package/src/component/dialog-workspace-file-changes.tsx +144 -0
- package/src/component/dialog-workspace-list.tsx +112 -0
- package/src/component/dialog-workspace-unavailable.tsx +69 -0
- package/src/component/error-component.tsx +240 -0
- package/src/component/logo.tsx +61 -0
- package/src/component/plugin-route-missing.tsx +14 -0
- package/src/component/prompt/autocomplete.tsx +781 -0
- package/src/component/prompt/cwd.ts +0 -0
- package/src/component/prompt/frecency.tsx +1 -0
- package/src/component/prompt/history.tsx +1 -0
- package/src/component/prompt/index.tsx +1713 -0
- package/src/component/prompt/local-attachment.ts +48 -0
- package/src/component/prompt/move.tsx +205 -0
- package/src/component/prompt/stash.tsx +1 -0
- package/src/component/prompt/workspace.tsx +137 -0
- package/src/component/register-spinner.ts +6 -0
- package/src/component/spinner.tsx +26 -0
- package/src/component/startup-loading.tsx +63 -0
- package/src/component/todo-item.tsx +32 -0
- package/src/component/use-connected.tsx +12 -0
- package/src/component/workspace-label.tsx +19 -0
- package/src/config/index.tsx +129 -0
- package/src/config/keybind.ts +471 -0
- package/src/context/args.tsx +16 -0
- package/src/context/clipboard.tsx +18 -0
- package/src/context/data.tsx +569 -0
- package/src/context/directory.ts +17 -0
- package/src/context/editor.ts +408 -0
- package/src/context/epilogue.tsx +6 -0
- package/src/context/event.ts +36 -0
- package/src/context/exit.tsx +8 -0
- package/src/context/helper.tsx +26 -0
- package/src/context/kv.tsx +66 -0
- package/src/context/local.tsx +542 -0
- package/src/context/location.tsx +14 -0
- package/src/context/path-format.tsx +24 -0
- package/src/context/permission.tsx +26 -0
- package/src/context/project.tsx +115 -0
- package/src/context/prompt.tsx +18 -0
- package/src/context/route.tsx +60 -0
- package/src/context/runtime.tsx +62 -0
- package/src/context/sdk.tsx +151 -0
- package/src/context/sync.tsx +666 -0
- package/src/context/theme.tsx +332 -0
- package/src/context/thinking.ts +67 -0
- package/src/editor-zed.ts +286 -0
- package/src/editor.ts +101 -0
- package/src/feature-plugins/builtins.ts +36 -0
- package/src/feature-plugins/home/footer.tsx +100 -0
- package/src/feature-plugins/home/tips-view.tsx +287 -0
- package/src/feature-plugins/home/tips.tsx +59 -0
- package/src/feature-plugins/sidebar/context.tsx +65 -0
- package/src/feature-plugins/sidebar/files.tsx +70 -0
- package/src/feature-plugins/sidebar/footer.tsx +98 -0
- package/src/feature-plugins/sidebar/lsp.tsx +65 -0
- package/src/feature-plugins/sidebar/mcp.tsx +97 -0
- package/src/feature-plugins/sidebar/todo.tsx +49 -0
- package/src/feature-plugins/system/diff-viewer-file-tree-utils.ts +232 -0
- package/src/feature-plugins/system/diff-viewer-file-tree.tsx +162 -0
- package/src/feature-plugins/system/diff-viewer-ui.tsx +103 -0
- package/src/feature-plugins/system/diff-viewer.tsx +1077 -0
- package/src/feature-plugins/system/notifications.ts +94 -0
- package/src/feature-plugins/system/plugins.tsx +269 -0
- package/src/feature-plugins/system/which-key.tsx +608 -0
- package/src/index.tsx +1 -0
- package/src/keymap.tsx +290 -0
- package/src/logo.ts +11 -0
- package/src/parsers-config.ts +386 -0
- package/src/plugin/adapters.tsx +355 -0
- package/src/plugin/api.ts +52 -0
- package/src/plugin/command-shim.ts +109 -0
- package/src/plugin/runtime.tsx +81 -0
- package/src/plugin/slots.tsx +65 -0
- package/src/prompt/display.ts +48 -0
- package/src/prompt/frecency.tsx +80 -0
- package/src/prompt/history.tsx +111 -0
- package/src/prompt/part.ts +29 -0
- package/src/prompt/stash.tsx +89 -0
- package/src/prompt/traits.ts +29 -0
- package/src/routes/home/session-destination.tsx +41 -0
- package/src/routes/home.tsx +95 -0
- package/src/routes/session/dialog-fork-from-timeline.tsx +76 -0
- package/src/routes/session/dialog-message.tsx +109 -0
- package/src/routes/session/dialog-subagent.tsx +26 -0
- package/src/routes/session/dialog-timeline.tsx +47 -0
- package/src/routes/session/footer.tsx +91 -0
- package/src/routes/session/index.tsx +2710 -0
- package/src/routes/session/permission.tsx +718 -0
- package/src/routes/session/question.tsx +514 -0
- package/src/routes/session/sidebar.tsx +103 -0
- package/src/routes/session/subagent-footer.tsx +132 -0
- package/src/runtime.tsx +9 -0
- package/src/terminal-win32.ts +130 -0
- package/src/theme/assets/aura.json +69 -0
- package/src/theme/assets/ayu.json +80 -0
- package/src/theme/assets/carbonfox.json +248 -0
- package/src/theme/assets/catppuccin-frappe.json +230 -0
- package/src/theme/assets/catppuccin-macchiato.json +230 -0
- package/src/theme/assets/catppuccin.json +112 -0
- package/src/theme/assets/cobalt2.json +225 -0
- package/src/theme/assets/cursor.json +249 -0
- package/src/theme/assets/dracula.json +219 -0
- package/src/theme/assets/everforest.json +241 -0
- package/src/theme/assets/flexoki.json +237 -0
- package/src/theme/assets/github.json +233 -0
- package/src/theme/assets/gruvbox.json +242 -0
- package/src/theme/assets/kanagawa.json +77 -0
- package/src/theme/assets/lucent-orng.json +234 -0
- package/src/theme/assets/material.json +235 -0
- package/src/theme/assets/matrix.json +77 -0
- package/src/theme/assets/mercury.json +252 -0
- package/src/theme/assets/monokai.json +221 -0
- package/src/theme/assets/nightowl.json +221 -0
- package/src/theme/assets/nord.json +223 -0
- package/src/theme/assets/one-dark.json +84 -0
- package/src/theme/assets/opencode.json +245 -0
- package/src/theme/assets/orng.json +249 -0
- package/src/theme/assets/osaka-jade.json +93 -0
- package/src/theme/assets/palenight.json +222 -0
- package/src/theme/assets/rosepine.json +234 -0
- package/src/theme/assets/solarized.json +223 -0
- package/src/theme/assets/synthwave84.json +226 -0
- package/src/theme/assets/tokyonight.json +243 -0
- package/src/theme/assets/vercel.json +245 -0
- package/src/theme/assets/vesper.json +218 -0
- package/src/theme/assets/zenburn.json +223 -0
- package/src/theme/index.ts +1089 -0
- package/src/ui/border.ts +21 -0
- package/src/ui/dialog-alert.tsx +66 -0
- package/src/ui/dialog-confirm.tsx +108 -0
- package/src/ui/dialog-export-options.tsx +217 -0
- package/src/ui/dialog-help.tsx +40 -0
- package/src/ui/dialog-prompt.tsx +126 -0
- package/src/ui/dialog-select.tsx +790 -0
- package/src/ui/dialog.tsx +231 -0
- package/src/ui/link.tsx +34 -0
- package/src/ui/spinner.ts +368 -0
- package/src/ui/toast.tsx +102 -0
- package/src/util/collapse-tool-output.ts +19 -0
- package/src/util/error.ts +182 -0
- package/src/util/filetype.ts +130 -0
- package/src/util/format.ts +20 -0
- package/src/util/layout.ts +25 -0
- package/src/util/locale.ts +86 -0
- package/src/util/model.ts +28 -0
- package/src/util/path.ts +12 -0
- package/src/util/persistence.ts +33 -0
- package/src/util/presentation.ts +38 -0
- package/src/util/provider-origin.ts +7 -0
- package/src/util/record.ts +3 -0
- package/src/util/renderer.ts +7 -0
- package/src/util/revert-diff.ts +18 -0
- package/src/util/scroll.ts +27 -0
- package/src/util/selection.ts +79 -0
- package/src/util/session.ts +3 -0
- package/src/util/signal.ts +51 -0
- package/src/util/system.ts +20 -0
- package/src/util/tool-display.ts +13 -0
- package/src/util/transcript.ts +112 -0
- package/sst-env.d.ts +10 -0
- package/test/app-lifecycle.test.tsx +128 -0
- package/test/cli/cmd/tui/dialog-workspace-create.test.ts +28 -0
- package/test/cli/cmd/tui/model-options.test.ts +32 -0
- package/test/cli/cmd/tui/notifications.test.ts +267 -0
- package/test/cli/cmd/tui/provider-options.test.ts +41 -0
- package/test/cli/cmd/tui/sync-fixture.tsx +70 -0
- package/test/cli/cmd/tui/sync-live-hydration.test.tsx +262 -0
- package/test/cli/cmd/tui/sync-undefined-messages.test.tsx +43 -0
- package/test/cli/cmd/tui/sync.test.tsx +65 -0
- package/test/cli/tui/__snapshots__/inline-tool-wrap-snapshot.test.tsx.snap +92 -0
- package/test/cli/tui/data.test.tsx +486 -0
- package/test/cli/tui/dialog-prompt.test.tsx +147 -0
- package/test/cli/tui/diff-viewer-file-tree.test.tsx +200 -0
- package/test/cli/tui/diff-viewer.test.tsx +268 -0
- package/test/cli/tui/inline-tool-wrap-snapshot.test.tsx +351 -0
- package/test/cli/tui/prompt-submit-race.test.ts +98 -0
- package/test/cli/tui/thinking.test.ts +36 -0
- package/test/cli/tui/use-event.test.tsx +148 -0
- package/test/clipboard.test.ts +19 -0
- package/test/component/dialog-session-list.test.ts +46 -0
- package/test/config.test.tsx +127 -0
- package/test/context/local.test.ts +22 -0
- package/test/editor.test.ts +32 -0
- package/test/feature-plugins/diff-viewer-file-tree-utils.test.ts +323 -0
- package/test/fixture/fixture.ts +13 -0
- package/test/fixture/tui-environment.tsx +32 -0
- package/test/fixture/tui-plugin.ts +36 -0
- package/test/fixture/tui-runtime.ts +12 -0
- package/test/fixture/tui-sdk.ts +109 -0
- package/test/index.test.tsx +6 -0
- package/test/keymap.test.tsx +141 -0
- package/test/plugin/runtime.test.ts +50 -0
- package/test/plugin/slots.test.tsx +38 -0
- package/test/prompt/display.test.ts +33 -0
- package/test/prompt/history.test.ts +39 -0
- package/test/prompt/jsonl.test.ts +24 -0
- package/test/prompt/local-attachment.test.ts +43 -0
- package/test/prompt/part.test.ts +53 -0
- package/test/prompt/persistence.test.ts +23 -0
- package/test/prompt/traits.test.ts +25 -0
- package/test/runtime.test.tsx +37 -0
- package/test/theme.test.ts +81 -0
- package/test/util/error.test.ts +49 -0
- package/test/util/filetype.test.ts +16 -0
- package/test/util/format.test.ts +59 -0
- package/test/util/model.test.ts +9 -0
- package/test/util/presentation.test.ts +8 -0
- package/test/util/renderer.test.ts +30 -0
- package/test/util/revert-diff.test.ts +35 -0
- package/test/util/session.test.ts +10 -0
- package/test/util/tool-display.test.ts +40 -0
- package/test/util/transcript.test.ts +421 -0
- package/tsconfig.json +10 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { Event } from "@neurocode-ai/sdk/v2"
|
|
2
|
+
import type { TuiAttentionSoundName, TuiPlugin, TuiPluginApi } from "@neurocode-ai/plugin/tui"
|
|
3
|
+
import type { BuiltinTuiPlugin } from "../builtins"
|
|
4
|
+
|
|
5
|
+
const id = "internal:notifications"
|
|
6
|
+
|
|
7
|
+
type SessionError = Extract<Event, { type: "session.error" }>["properties"]["error"]
|
|
8
|
+
|
|
9
|
+
function notify(api: TuiPluginApi, sessionID: string | undefined, message: string, sound: TuiAttentionSoundName) {
|
|
10
|
+
const session = sessionID ? api.state.session.get(sessionID) : undefined
|
|
11
|
+
const isSubagent = session?.parentID !== undefined
|
|
12
|
+
void api.attention.notify({
|
|
13
|
+
title: session?.title,
|
|
14
|
+
message,
|
|
15
|
+
notification: isSubagent ? false : { when: "blurred" },
|
|
16
|
+
sound: { name: sound, when: "always" },
|
|
17
|
+
})
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function sessionErrorMessage(error: SessionError) {
|
|
21
|
+
if (error?.name === "MessageAbortedError") return "Session aborted"
|
|
22
|
+
const data = error?.data
|
|
23
|
+
if (data && typeof data === "object" && "message" in data && data.message === "SSE read timed out") {
|
|
24
|
+
return "Model stopped responding"
|
|
25
|
+
}
|
|
26
|
+
return "Session error"
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const tui: TuiPlugin = async (api) => {
|
|
30
|
+
const active = new Set<string>()
|
|
31
|
+
const errored = new Set<string>()
|
|
32
|
+
const questions = new Set<string>()
|
|
33
|
+
const permissions = new Set<string>()
|
|
34
|
+
|
|
35
|
+
api.event.on("question.asked", (event) => {
|
|
36
|
+
if (questions.has(event.properties.id)) return
|
|
37
|
+
questions.add(event.properties.id)
|
|
38
|
+
notify(api, event.properties.sessionID, "Question needs input", "question")
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
api.event.on("question.replied", (event) => {
|
|
42
|
+
questions.delete(event.properties.requestID)
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
api.event.on("question.rejected", (event) => {
|
|
46
|
+
questions.delete(event.properties.requestID)
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
api.event.on("permission.asked", (event) => {
|
|
50
|
+
if (permissions.has(event.properties.id)) return
|
|
51
|
+
permissions.add(event.properties.id)
|
|
52
|
+
notify(api, event.properties.sessionID, "Permission needs input", "permission")
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
api.event.on("permission.replied", (event) => {
|
|
56
|
+
permissions.delete(event.properties.requestID)
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
api.event.on("session.status", (event) => {
|
|
60
|
+
const sessionID = event.properties.sessionID
|
|
61
|
+
if (event.properties.status.type === "busy" || event.properties.status.type === "retry") {
|
|
62
|
+
active.add(sessionID)
|
|
63
|
+
errored.delete(sessionID)
|
|
64
|
+
return
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (event.properties.status.type !== "idle") return
|
|
68
|
+
if (!active.has(sessionID)) return
|
|
69
|
+
active.delete(sessionID)
|
|
70
|
+
|
|
71
|
+
if (errored.has(sessionID)) {
|
|
72
|
+
errored.delete(sessionID)
|
|
73
|
+
return
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const session = api.state.session.get(sessionID)
|
|
77
|
+
notify(api, sessionID, "Session done", session?.parentID ? "subagent_done" : "done")
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
api.event.on("session.error", (event) => {
|
|
81
|
+
const sessionID = event.properties.sessionID
|
|
82
|
+
if (!sessionID) return
|
|
83
|
+
if (!active.has(sessionID)) return
|
|
84
|
+
errored.add(sessionID)
|
|
85
|
+
notify(api, sessionID, sessionErrorMessage(event.properties.error), "error")
|
|
86
|
+
})
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const plugin: BuiltinTuiPlugin = {
|
|
90
|
+
id,
|
|
91
|
+
tui,
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export default plugin
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import type { TuiPlugin, TuiPluginApi, TuiPluginStatus } from "@neurocode-ai/plugin/tui"
|
|
2
|
+
import type { BuiltinTuiPlugin } from "../builtins"
|
|
3
|
+
import { useTerminalDimensions } from "@opentui/solid"
|
|
4
|
+
import { fileURLToPath } from "url"
|
|
5
|
+
import { DialogSelect, type DialogSelectOption } from "../../ui/dialog-select"
|
|
6
|
+
import { Show, createEffect, createMemo, createSignal } from "solid-js"
|
|
7
|
+
import { useBindings } from "../../keymap"
|
|
8
|
+
|
|
9
|
+
const id = "internal:plugin-manager"
|
|
10
|
+
|
|
11
|
+
function state(api: TuiPluginApi, item: TuiPluginStatus) {
|
|
12
|
+
if (!item.enabled) {
|
|
13
|
+
return <span style={{ fg: api.theme.current.textMuted }}>disabled</span>
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<span style={{ fg: item.active ? api.theme.current.success : api.theme.current.error }}>
|
|
18
|
+
{item.active ? "active" : "inactive"}
|
|
19
|
+
</span>
|
|
20
|
+
)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function source(spec: string) {
|
|
24
|
+
if (!spec.startsWith("file://")) return
|
|
25
|
+
return fileURLToPath(spec)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function meta(item: TuiPluginStatus, width: number) {
|
|
29
|
+
if (item.source === "internal") {
|
|
30
|
+
if (width >= 120) return "Built-in plugin"
|
|
31
|
+
return "Built-in"
|
|
32
|
+
}
|
|
33
|
+
const next = source(item.spec)
|
|
34
|
+
if (next) return next
|
|
35
|
+
return item.spec
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function Install(props: { api: TuiPluginApi }) {
|
|
39
|
+
const [global, setGlobal] = createSignal(false)
|
|
40
|
+
const [busy, setBusy] = createSignal(false)
|
|
41
|
+
|
|
42
|
+
useBindings(() => ({
|
|
43
|
+
enabled: !busy(),
|
|
44
|
+
bindings: [{ key: "tab", desc: "Toggle install scope", group: "Plugins", cmd: () => setGlobal((value) => !value) }],
|
|
45
|
+
}))
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<props.api.ui.DialogPrompt
|
|
49
|
+
title="Install plugin"
|
|
50
|
+
placeholder="npm package name"
|
|
51
|
+
busy={busy()}
|
|
52
|
+
busyText="Installing plugin..."
|
|
53
|
+
description={() => (
|
|
54
|
+
<box flexDirection="row" gap={1}>
|
|
55
|
+
<text fg={props.api.theme.current.textMuted}>scope:</text>
|
|
56
|
+
<text fg={busy() ? props.api.theme.current.textMuted : props.api.theme.current.text}>
|
|
57
|
+
{global() ? "global" : "local"}
|
|
58
|
+
</text>
|
|
59
|
+
<Show when={!busy()}>
|
|
60
|
+
<text fg={props.api.theme.current.textMuted}>(tab toggle)</text>
|
|
61
|
+
</Show>
|
|
62
|
+
</box>
|
|
63
|
+
)}
|
|
64
|
+
onConfirm={(raw) => {
|
|
65
|
+
if (busy()) return
|
|
66
|
+
const mod = raw.trim()
|
|
67
|
+
if (!mod) {
|
|
68
|
+
props.api.ui.toast({
|
|
69
|
+
variant: "error",
|
|
70
|
+
message: "Plugin package name is required",
|
|
71
|
+
})
|
|
72
|
+
return
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
setBusy(true)
|
|
76
|
+
void props.api.plugins
|
|
77
|
+
.install(mod, { global: global() })
|
|
78
|
+
.then((out) => {
|
|
79
|
+
if (!out.ok) {
|
|
80
|
+
props.api.ui.toast({
|
|
81
|
+
variant: "error",
|
|
82
|
+
message: out.message,
|
|
83
|
+
})
|
|
84
|
+
if (out.missing) {
|
|
85
|
+
props.api.ui.toast({
|
|
86
|
+
variant: "info",
|
|
87
|
+
message: "Check npm registry/auth settings and try again.",
|
|
88
|
+
})
|
|
89
|
+
}
|
|
90
|
+
show(props.api)
|
|
91
|
+
return
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
props.api.ui.toast({
|
|
95
|
+
variant: "success",
|
|
96
|
+
message: `Installed ${mod} (${global() ? "global" : "local"}: ${out.dir})`,
|
|
97
|
+
})
|
|
98
|
+
if (!out.tui) {
|
|
99
|
+
props.api.ui.toast({
|
|
100
|
+
variant: "info",
|
|
101
|
+
message: "Package has no TUI target to load in this app.",
|
|
102
|
+
})
|
|
103
|
+
show(props.api)
|
|
104
|
+
return
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return props.api.plugins.add(mod).then((ok) => {
|
|
108
|
+
if (!ok) {
|
|
109
|
+
props.api.ui.toast({
|
|
110
|
+
variant: "warning",
|
|
111
|
+
message: "Installed plugin, but runtime load failed. See console/logs; restart TUI to retry.",
|
|
112
|
+
})
|
|
113
|
+
show(props.api)
|
|
114
|
+
return
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
props.api.ui.toast({
|
|
118
|
+
variant: "success",
|
|
119
|
+
message: `Loaded ${mod} in current session.`,
|
|
120
|
+
})
|
|
121
|
+
show(props.api)
|
|
122
|
+
})
|
|
123
|
+
})
|
|
124
|
+
.finally(() => {
|
|
125
|
+
setBusy(false)
|
|
126
|
+
})
|
|
127
|
+
}}
|
|
128
|
+
onCancel={() => {
|
|
129
|
+
show(props.api)
|
|
130
|
+
}}
|
|
131
|
+
/>
|
|
132
|
+
)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function row(api: TuiPluginApi, item: TuiPluginStatus, width: number): DialogSelectOption<string> {
|
|
136
|
+
return {
|
|
137
|
+
title: item.id,
|
|
138
|
+
value: item.id,
|
|
139
|
+
category: item.source === "internal" ? "Internal" : "External",
|
|
140
|
+
description: meta(item, width),
|
|
141
|
+
footer: state(api, item),
|
|
142
|
+
disabled: item.id === id,
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function showInstall(api: TuiPluginApi) {
|
|
147
|
+
api.ui.dialog.replace(() => <Install api={api} />)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function View(props: { api: TuiPluginApi }) {
|
|
151
|
+
const size = useTerminalDimensions()
|
|
152
|
+
const [list, setList] = createSignal(props.api.plugins.list())
|
|
153
|
+
const [cur, setCur] = createSignal<string | undefined>()
|
|
154
|
+
const [lock, setLock] = createSignal(false)
|
|
155
|
+
|
|
156
|
+
createEffect(() => {
|
|
157
|
+
const width = size().width
|
|
158
|
+
if (width >= 128) {
|
|
159
|
+
props.api.ui.dialog.setSize("xlarge")
|
|
160
|
+
return
|
|
161
|
+
}
|
|
162
|
+
if (width >= 96) {
|
|
163
|
+
props.api.ui.dialog.setSize("large")
|
|
164
|
+
return
|
|
165
|
+
}
|
|
166
|
+
props.api.ui.dialog.setSize("medium")
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
const rows = createMemo(() =>
|
|
170
|
+
[...list()]
|
|
171
|
+
.sort((a, b) => {
|
|
172
|
+
const x = a.source === "internal" ? 1 : 0
|
|
173
|
+
const y = b.source === "internal" ? 1 : 0
|
|
174
|
+
if (x !== y) return x - y
|
|
175
|
+
return a.id.localeCompare(b.id)
|
|
176
|
+
})
|
|
177
|
+
.map((item) => row(props.api, item, size().width)),
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
const flip = (x: string) => {
|
|
181
|
+
if (lock()) return
|
|
182
|
+
const item = list().find((entry) => entry.id === x)
|
|
183
|
+
if (!item) return
|
|
184
|
+
setLock(true)
|
|
185
|
+
const task = item.active ? props.api.plugins.deactivate(x) : props.api.plugins.activate(x)
|
|
186
|
+
void task
|
|
187
|
+
.then((ok) => {
|
|
188
|
+
if (!ok) {
|
|
189
|
+
props.api.ui.toast({
|
|
190
|
+
variant: "error",
|
|
191
|
+
message: `Failed to update plugin ${item.id}`,
|
|
192
|
+
})
|
|
193
|
+
}
|
|
194
|
+
setList(props.api.plugins.list())
|
|
195
|
+
})
|
|
196
|
+
.finally(() => {
|
|
197
|
+
setLock(false)
|
|
198
|
+
})
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return (
|
|
202
|
+
<DialogSelect
|
|
203
|
+
title="Plugins"
|
|
204
|
+
options={rows()}
|
|
205
|
+
current={cur()}
|
|
206
|
+
onMove={(item) => setCur(item.value)}
|
|
207
|
+
actions={[
|
|
208
|
+
{
|
|
209
|
+
title: "toggle",
|
|
210
|
+
command: "plugins.toggle",
|
|
211
|
+
hidden: lock(),
|
|
212
|
+
onTrigger: (item) => {
|
|
213
|
+
setCur(item.value)
|
|
214
|
+
flip(item.value)
|
|
215
|
+
},
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
title: "install",
|
|
219
|
+
command: "dialog.plugins.install",
|
|
220
|
+
hidden: lock(),
|
|
221
|
+
onTrigger: () => {
|
|
222
|
+
showInstall(props.api)
|
|
223
|
+
},
|
|
224
|
+
},
|
|
225
|
+
]}
|
|
226
|
+
onSelect={(item) => {
|
|
227
|
+
setCur(item.value)
|
|
228
|
+
flip(item.value)
|
|
229
|
+
}}
|
|
230
|
+
/>
|
|
231
|
+
)
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function show(api: TuiPluginApi) {
|
|
235
|
+
api.ui.dialog.replace(() => <View api={api} />)
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const tui: TuiPlugin = async (api) => {
|
|
239
|
+
api.keymap.registerLayer({
|
|
240
|
+
commands: [
|
|
241
|
+
{
|
|
242
|
+
name: "plugins.list",
|
|
243
|
+
title: "Plugins",
|
|
244
|
+
category: "System",
|
|
245
|
+
namespace: "palette",
|
|
246
|
+
run() {
|
|
247
|
+
show(api)
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
{
|
|
251
|
+
name: "plugins.install",
|
|
252
|
+
title: "Install plugin",
|
|
253
|
+
category: "System",
|
|
254
|
+
namespace: "palette",
|
|
255
|
+
run() {
|
|
256
|
+
showInstall(api)
|
|
257
|
+
},
|
|
258
|
+
},
|
|
259
|
+
],
|
|
260
|
+
bindings: api.tuiConfig.keybinds.gather("plugins.palette", ["plugins.list", "plugins.install"]),
|
|
261
|
+
})
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const plugin: BuiltinTuiPlugin = {
|
|
265
|
+
id,
|
|
266
|
+
tui,
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export default plugin
|