@deepseek-harness-tui/dsh-tui 0.20.0 → 0.20.2
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/README.md +18 -3
- package/bin/dsh-tui.js +26 -8
- package/guide/dsh-tui-guide/claude-backend.en.md +6 -5
- package/guide/dsh-tui-guide/claude-backend.md +5 -5
- package/guide/dsh-tui-guide/configuration.en.md +26 -12
- package/guide/dsh-tui-guide/configuration.md +18 -9
- package/guide/dsh-tui-guide/getting-started.en.md +17 -9
- package/guide/dsh-tui-guide/getting-started.md +11 -7
- package/guide/dsh-tui-guide/interaction.en.md +1 -0
- package/guide/dsh-tui-guide/interaction.md +1 -0
- package/guide/dsh-tui-guide/migrate.en.md +5 -0
- package/guide/dsh-tui-guide/migrate.md +4 -0
- package/guide/dsh-tui-guide/plugins.en.md +17 -1
- package/guide/dsh-tui-guide/plugins.md +12 -1
- package/guide/dsh-tui-guide/themes.en.md +1 -1
- package/guide/dsh-tui-guide/themes.md +1 -1
- package/guide/dsh-tui-guide/user-guide.en.md +8 -2
- package/guide/dsh-tui-guide/user-guide.md +8 -2
- package/lib/settings.json +19 -3
- package/lib/types/adapter/kernel/host-facade.d.ts +3 -1
- package/lib/types/adapter/kernel/host-facade.d.ts.map +1 -1
- package/lib/types/adapter/kernel/host-facade.js +6 -0
- package/lib/types/adapter/kernel/runtime.d.ts.map +1 -1
- package/lib/types/adapter/kernel/runtime.js +5 -0
- package/lib/types/adapter/kernel/slices/extensions.d.ts +1 -0
- package/lib/types/adapter/kernel/slices/extensions.d.ts.map +1 -1
- package/lib/types/adapter/kernel/slices/extensions.js +6 -1
- package/lib/types/adapter/kernel/slices/index.d.ts +1 -1
- package/lib/types/adapter/kernel/slices/index.d.ts.map +1 -1
- package/lib/types/adapter/kernel/slices/index.js +3 -2
- package/lib/types/adapter/ports/channel-catalog.d.ts +19 -0
- package/lib/types/adapter/ports/channel-catalog.d.ts.map +1 -1
- package/lib/types/adapter/ports/channel-settings.d.ts +6 -0
- package/lib/types/adapter/ports/channel-settings.d.ts.map +1 -1
- package/lib/types/adapter/ports/channel-view.d.ts +28 -2
- package/lib/types/adapter/ports/channel-view.d.ts.map +1 -1
- package/lib/types/adapter/ports/extensions.d.ts +9 -0
- package/lib/types/adapter/ports/extensions.d.ts.map +1 -1
- package/lib/types/adapter/ports/index.d.ts +1 -1
- package/lib/types/adapter/ports/index.d.ts.map +1 -1
- package/lib/types/adapter/upstream/extensions-driver.d.ts +4 -1
- package/lib/types/adapter/upstream/extensions-driver.d.ts.map +1 -1
- package/lib/types/adapter/upstream/extensions-driver.js +111 -1
- package/lib/types/adapter/upstream/index.d.ts +1 -1
- package/lib/types/adapter/upstream/index.d.ts.map +1 -1
- package/lib/types/adapter/upstream/index.js +1 -1
- package/lib/types/api.d.ts +1 -1
- package/lib/types/api.d.ts.map +1 -1
- package/lib/types/backends/claude/backend.d.ts.map +1 -1
- package/lib/types/backends/claude/backend.js +7 -2
- package/lib/types/backends/claude/session/lifecycle.d.ts.map +1 -1
- package/lib/types/backends/claude/session/lifecycle.js +11 -9
- package/lib/types/backends/claude/side-query.d.ts +2 -0
- package/lib/types/backends/claude/side-query.d.ts.map +1 -1
- package/lib/types/backends/claude/side-query.js +30 -13
- package/lib/types/components/FileSuggestions.d.ts +2 -2
- package/lib/types/components/FileSuggestions.d.ts.map +1 -1
- package/lib/types/components/FileSuggestions.js +25 -5
- package/lib/types/components/PromptInput.d.ts +7 -1
- package/lib/types/components/PromptInput.d.ts.map +1 -1
- package/lib/types/components/PromptInput.js +81 -23
- package/lib/types/components/messages/AssistantToolUseMessage.d.ts +1 -1
- package/lib/types/components/messages/AssistantToolUseMessage.d.ts.map +1 -1
- package/lib/types/components/messages/AssistantToolUseMessage.js +228 -27
- package/lib/types/components/messages/presentCardBackground.d.ts +28 -0
- package/lib/types/components/messages/presentCardBackground.d.ts.map +1 -0
- package/lib/types/components/messages/presentCardBackground.js +23 -0
- package/lib/types/dsh-adapter/backend/translate.d.ts.map +1 -1
- package/lib/types/dsh-adapter/backend/translate.js +28 -1
- package/lib/types/dsh-adapter/channel/core/compose.d.ts.map +1 -1
- package/lib/types/dsh-adapter/channel/core/files.d.ts.map +1 -1
- package/lib/types/dsh-adapter/channel/file-actions.d.ts +1 -1
- package/lib/types/dsh-adapter/channel/file-actions.d.ts.map +1 -1
- package/lib/types/dsh-adapter/channel/file-actions.js +11 -4
- package/lib/types/dsh-adapter/channel/settings-host.d.ts.map +1 -1
- package/lib/types/dsh-adapter/channel/settings-host.js +78 -12
- package/lib/types/dsh-adapter/channel/state.d.ts +4 -3
- package/lib/types/dsh-adapter/channel/state.d.ts.map +1 -1
- package/lib/types/dsh-adapter/channel/state.js +4 -3
- package/lib/types/dsh-adapter/channel/types.d.ts +1 -1
- package/lib/types/dsh-adapter/channel/types.d.ts.map +1 -1
- package/lib/types/dsh-adapter/channel.d.ts +1 -1
- package/lib/types/dsh-adapter/channel.d.ts.map +1 -1
- package/lib/types/dsh-adapter/childStderr.d.ts +1 -1
- package/lib/types/dsh-adapter/childStderr.d.ts.map +1 -1
- package/lib/types/dsh-adapter/childStderr.js +5 -0
- package/lib/types/dsh-adapter/contract.d.ts +23 -8
- package/lib/types/dsh-adapter/contract.d.ts.map +1 -1
- package/lib/types/dsh-adapter/contract.js +27 -7
- package/lib/types/dsh-adapter/extensions.d.ts +3 -2
- package/lib/types/dsh-adapter/extensions.d.ts.map +1 -1
- package/lib/types/dsh-adapter/extensions.js +5 -2
- package/lib/types/dsh-adapter/host-contract.d.ts +1 -1
- package/lib/types/dsh-adapter/host-contract.js +1 -1
- package/lib/types/dsh-adapter/host-dsh.d.ts +4 -0
- package/lib/types/dsh-adapter/host-dsh.d.ts.map +1 -1
- package/lib/types/dsh-adapter/host-dsh.js +26 -0
- package/lib/types/dsh-adapter/host-entry.js +4 -2
- package/lib/types/dsh-adapter/host-service-diagnostics.d.ts +61 -0
- package/lib/types/dsh-adapter/host-service-diagnostics.d.ts.map +1 -0
- package/lib/types/dsh-adapter/host-service-diagnostics.js +103 -0
- package/lib/types/dsh-adapter/index.d.ts +5 -0
- package/lib/types/dsh-adapter/index.d.ts.map +1 -1
- package/lib/types/dsh-adapter/index.js +1 -0
- package/lib/types/dsh-adapter/mention-providers.d.ts +91 -0
- package/lib/types/dsh-adapter/mention-providers.d.ts.map +1 -0
- package/lib/types/dsh-adapter/mention-providers.js +214 -0
- package/lib/types/dsh-adapter/migrate/entry.d.ts +2 -0
- package/lib/types/dsh-adapter/migrate/entry.d.ts.map +1 -0
- package/lib/types/dsh-adapter/migrate/entry.js +46 -0
- package/lib/types/dsh-adapter/plugin.d.ts.map +1 -1
- package/lib/types/dsh-adapter/plugin.js +42 -2
- package/lib/types/dsh-adapter/present-tool.d.ts +20 -0
- package/lib/types/dsh-adapter/present-tool.d.ts.map +1 -0
- package/lib/types/dsh-adapter/present-tool.js +96 -0
- package/lib/types/extensions.d.ts +2 -0
- package/lib/types/extensions.d.ts.map +1 -1
- package/lib/types/extensions.js +4 -1
- package/lib/types/i18n.d.ts +21 -2
- package/lib/types/i18n.d.ts.map +1 -1
- package/lib/types/i18n.js +9 -1
- package/lib/types/ink/components/ScrollBox.d.ts.map +1 -1
- package/lib/types/ink/components/ScrollBox.js +13 -0
- package/lib/types/ink/dom.d.ts +3 -0
- package/lib/types/ink/dom.d.ts.map +1 -1
- package/lib/types/ink/ink.d.ts.map +1 -1
- package/lib/types/ink/ink.js +30 -34
- package/lib/types/ink/render-node-to-output.d.ts +3 -0
- package/lib/types/ink/render-node-to-output.d.ts.map +1 -1
- package/lib/types/ink/render-node-to-output.js +54 -40
- package/lib/types/ink/selection.d.ts +38 -28
- package/lib/types/ink/selection.d.ts.map +1 -1
- package/lib/types/ink/selection.js +201 -130
- package/lib/types/kernelPrefs.d.ts +5 -2
- package/lib/types/kernelPrefs.d.ts.map +1 -1
- package/lib/types/kernelPrefs.js +5 -2
- package/lib/types/screens/Chat.d.ts +4 -1
- package/lib/types/screens/Chat.d.ts.map +1 -1
- package/lib/types/screens/Chat.js +2 -2
- package/lib/types/settings/definitions.d.ts +12 -0
- package/lib/types/settings/definitions.d.ts.map +1 -1
- package/lib/types/settings/definitions.js +10 -2
- package/lib/types/theme.d.ts +4 -0
- package/lib/types/theme.d.ts.map +1 -1
- package/lib/types/theme.js +20 -2
- package/lib/types/tuiDisplayPrefs.d.ts +3 -0
- package/lib/types/tuiDisplayPrefs.d.ts.map +1 -1
- package/lib/types/tuiDisplayPrefs.js +10 -0
- package/lib/types/update.d.ts +74 -5
- package/lib/types/update.d.ts.map +1 -1
- package/lib/types/update.js +297 -46
- package/lib/types/updateHost.d.ts.map +1 -1
- package/lib/types/updateHost.js +16 -5
- package/lib/types/usageStats.d.ts +6 -0
- package/lib/types/usageStats.d.ts.map +1 -1
- package/lib/types/usageStats.js +8 -0
- package/lib/types/utils/colorMix.d.ts +19 -0
- package/lib/types/utils/colorMix.d.ts.map +1 -0
- package/lib/types/utils/colorMix.js +51 -0
- package/lib/types/utils/commandLine.d.ts +8 -0
- package/lib/types/utils/commandLine.d.ts.map +1 -0
- package/lib/types/utils/commandLine.js +37 -0
- package/lib/types/utils/desktopEntry.d.ts +32 -0
- package/lib/types/utils/desktopEntry.d.ts.map +1 -0
- package/lib/types/utils/desktopEntry.js +302 -0
- package/lib/types/utils/externalEditor.d.ts +2 -5
- package/lib/types/utils/externalEditor.d.ts.map +1 -1
- package/lib/types/utils/externalEditor.js +4 -36
- package/lib/types/utils/fileSuggestions.d.ts +14 -3
- package/lib/types/utils/fileSuggestions.d.ts.map +1 -1
- package/lib/types/utils/fileSuggestions.js +33 -0
- package/lib/types/utils/openExternal.d.ts +9 -0
- package/lib/types/utils/openExternal.d.ts.map +1 -1
- package/lib/types/utils/openExternal.js +87 -3
- package/lib/types/utils/terminalLaunch.d.ts +16 -0
- package/lib/types/utils/terminalLaunch.d.ts.map +1 -0
- package/lib/types/utils/terminalLaunch.js +121 -0
- package/package.json +116 -110
- package/tui-profile/feed/README.md +1 -1
- package/tui-profile/feed/first-party.json +1 -1
|
@@ -20,12 +20,24 @@
|
|
|
20
20
|
* works) — `windowsHide` alone (CREATE_NO_WINDOW) keeps it invisible
|
|
21
21
|
* AND functional.
|
|
22
22
|
* - macOS: `open` (reveal adds `-R`).
|
|
23
|
-
* - Linux/other: `xdg-open
|
|
23
|
+
* - Linux/other: `xdg-open`, except a local file whose resolved handler is
|
|
24
|
+
* `Terminal=true` (e.g. `vim.desktop`). The generic `xdg-open` path executes
|
|
25
|
+
* `Exec=` directly without a terminal wrapper, so such an app inherits the
|
|
26
|
+
* TUI's non-tty stdio and exits immediately. For those targets the default entry
|
|
27
|
+
* is resolved through `xdg-mime`, its Exec is expanded, and the command is
|
|
28
|
+
* spawned inside a terminal (desktopEntry.ts / terminalLaunch.ts). Missing
|
|
29
|
+
* tools, an unsupported Exec or terminal startup errors fall back to
|
|
30
|
+
* `xdg-open`. Non-empty `Path=` is outside this wrapper's scope and stays
|
|
31
|
+
* with the system launcher; generic xdg-open may still lack a tty and
|
|
32
|
+
* ignore the working directory for those entries.
|
|
24
33
|
*/
|
|
25
34
|
import { spawn } from 'node:child_process';
|
|
26
35
|
import { dirname } from 'node:path';
|
|
27
|
-
import { existsSync, statSync } from 'node:fs';
|
|
36
|
+
import { existsSync, readFileSync, statSync } from 'node:fs';
|
|
37
|
+
import { expandExec, findDesktopEntry, parseDesktopEntry } from './desktopEntry.js';
|
|
38
|
+
import { execFileNoThrow } from './execFileNoThrow.js';
|
|
28
39
|
import { cmdEscapeArgument } from './shellQuote.js';
|
|
40
|
+
import { buildTerminalSpawn, isExecutableOnPath, resolveTerminal } from './terminalLaunch.js';
|
|
29
41
|
import { logError } from './log.js';
|
|
30
42
|
/**
|
|
31
43
|
* Spawn a fire-and-forget child: no stdio pipes, no wait, unref'd so the
|
|
@@ -108,6 +120,65 @@ export function buildWin32OpenSpawn(target) {
|
|
|
108
120
|
}
|
|
109
121
|
return buildWin32StartSpawn(target);
|
|
110
122
|
}
|
|
123
|
+
const URL_SCHEME = /^[a-z][a-z0-9+.-]*:\/\//i;
|
|
124
|
+
/** Whether a Linux target is a URL rather than a local path. */
|
|
125
|
+
function isUrlTarget(target) {
|
|
126
|
+
return URL_SCHEME.test(target) || /^mailto:/i.test(target);
|
|
127
|
+
}
|
|
128
|
+
/** One bounded `xdg-mime query` call; undefined on failure/empty output. */
|
|
129
|
+
async function queryXdgMime(kind, value) {
|
|
130
|
+
const result = await execFileNoThrow('xdg-mime', ['query', kind, value], { timeout: 800 });
|
|
131
|
+
if (result.code !== 0)
|
|
132
|
+
return undefined;
|
|
133
|
+
const line = result.stdout.trim().split(/\r?\n/, 1)[0]?.trim();
|
|
134
|
+
return line === undefined || line === '' ? undefined : line;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Resolve a local file's default handler and, when it is `Terminal=true`,
|
|
138
|
+
* build the terminal-wrapped spawn descriptor. Exported for the regression
|
|
139
|
+
* script; `undefined` means "keep using xdg-open".
|
|
140
|
+
*/
|
|
141
|
+
export async function resolveLinuxFileOpen(target, env = process.env) {
|
|
142
|
+
if (target === '' || isUrlTarget(target) || isDirectory(target))
|
|
143
|
+
return undefined;
|
|
144
|
+
const mime = await queryXdgMime('filetype', target);
|
|
145
|
+
if (mime === undefined)
|
|
146
|
+
return undefined;
|
|
147
|
+
const id = await queryXdgMime('default', mime);
|
|
148
|
+
if (id === undefined)
|
|
149
|
+
return undefined;
|
|
150
|
+
const path = findDesktopEntry(id, env);
|
|
151
|
+
if (path === undefined)
|
|
152
|
+
return undefined;
|
|
153
|
+
let entry;
|
|
154
|
+
try {
|
|
155
|
+
entry = parseDesktopEntry(readFileSync(path, 'utf8'), id, path);
|
|
156
|
+
}
|
|
157
|
+
catch {
|
|
158
|
+
return undefined;
|
|
159
|
+
}
|
|
160
|
+
if (entry === undefined || entry.hidden || !entry.terminal)
|
|
161
|
+
return undefined;
|
|
162
|
+
// Path= is outside this wrapper's scope. Keep the system launcher's
|
|
163
|
+
// existing behavior instead of substituting the TUI's working directory.
|
|
164
|
+
if (entry.workingDirectory !== undefined)
|
|
165
|
+
return undefined;
|
|
166
|
+
if (entry.tryExec !== undefined && !isExecutableOnPath(entry.tryExec, env)) {
|
|
167
|
+
logError(`dsh-tui: ${entry.id} is Terminal=true but TryExec "${entry.tryExec}" is not available; falling back to xdg-open`);
|
|
168
|
+
return undefined;
|
|
169
|
+
}
|
|
170
|
+
const argv = expandExec(entry.exec, target, entry);
|
|
171
|
+
if (argv === undefined) {
|
|
172
|
+
logError(`dsh-tui: ${entry.id} is Terminal=true but its Exec line is unsupported; falling back to xdg-open`);
|
|
173
|
+
return undefined;
|
|
174
|
+
}
|
|
175
|
+
const terminal = resolveTerminal(env);
|
|
176
|
+
if (terminal === undefined) {
|
|
177
|
+
logError(`dsh-tui: ${entry.id} is Terminal=true but no terminal emulator was found; falling back to xdg-open`);
|
|
178
|
+
return undefined;
|
|
179
|
+
}
|
|
180
|
+
return buildTerminalSpawn(terminal, argv);
|
|
181
|
+
}
|
|
111
182
|
/** Open a URL, file or directory with the platform's default handler. */
|
|
112
183
|
export function openExternal(target) {
|
|
113
184
|
if (target === '')
|
|
@@ -130,9 +201,22 @@ export function openExternal(target) {
|
|
|
130
201
|
else if (process.platform === 'darwin') {
|
|
131
202
|
spawnDetached('open', [target]);
|
|
132
203
|
}
|
|
133
|
-
else {
|
|
204
|
+
else if (isDirectory(target) || isUrlTarget(target)) {
|
|
134
205
|
spawnDetached('xdg-open', [target]);
|
|
135
206
|
}
|
|
207
|
+
else {
|
|
208
|
+
void resolveLinuxFileOpen(target).then(spec => {
|
|
209
|
+
if (spec === undefined)
|
|
210
|
+
spawnDetached('xdg-open', [target]);
|
|
211
|
+
else
|
|
212
|
+
spawnDetached(spec.file, spec.args, {
|
|
213
|
+
onError: () => spawnDetached('xdg-open', [target]),
|
|
214
|
+
});
|
|
215
|
+
}, error => {
|
|
216
|
+
logError(error);
|
|
217
|
+
spawnDetached('xdg-open', [target]);
|
|
218
|
+
});
|
|
219
|
+
}
|
|
136
220
|
}
|
|
137
221
|
/** Open a file with its associated application (openExternal with a file). */
|
|
138
222
|
export function openFile(path) {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** A terminal command split into the emulator args and the program separator. */
|
|
2
|
+
export interface TerminalSpec {
|
|
3
|
+
readonly file: string;
|
|
4
|
+
readonly args: readonly string[];
|
|
5
|
+
readonly separator: readonly string[];
|
|
6
|
+
}
|
|
7
|
+
/** Whether `command` resolves to an executable on PATH (or is an executable path). */
|
|
8
|
+
export declare function isExecutableOnPath(command: string, env?: NodeJS.ProcessEnv): boolean;
|
|
9
|
+
/** Resolve the terminal command, or undefined when none is available. */
|
|
10
|
+
export declare function resolveTerminal(env?: NodeJS.ProcessEnv): TerminalSpec | undefined;
|
|
11
|
+
/** Assemble the final argv: terminal args, separator, then the handler argv. */
|
|
12
|
+
export declare function buildTerminalSpawn(terminal: TerminalSpec, argv: readonly string[]): {
|
|
13
|
+
file: string;
|
|
14
|
+
args: string[];
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=terminalLaunch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"terminalLaunch.d.ts","sourceRoot":"","sources":["../../../src/utils/terminalLaunch.ts"],"names":[],"mappings":"AAiBA,iFAAiF;AACjF,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAA;IAChC,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAA;CACtC;AAWD,sFAAsF;AACtF,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,OAAO,CAQjG;AAyDD,yEAAyE;AACzE,wBAAgB,eAAe,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,YAAY,GAAG,SAAS,CAiB9F;AAED,gFAAgF;AAChF,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,YAAY,EACtB,IAAI,EAAE,SAAS,MAAM,EAAE,GACtB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAA;CAAE,CAElC"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pick a terminal emulator for the Linux `Terminal=true` open path and build
|
|
3
|
+
* the spawn descriptor. The TUI itself owns a tty but hands child processes
|
|
4
|
+
* `stdio: 'ignore'`, so a terminal application must get its own window; this
|
|
5
|
+
* is the piece the generic `xdg-open` path lacks (it executes `Exec=` directly).
|
|
6
|
+
*
|
|
7
|
+
* Selection order: `$TERMINAL` (may carry arguments, e.g. `kitty -1`) → KDE's
|
|
8
|
+
* `kdeglobals` `[General] TerminalApplication` → `xdg-terminal-exec` → the
|
|
9
|
+
* first known terminal on PATH. Each terminal gets its own command separator
|
|
10
|
+
* (`kitty`/`foot` take the program directly, `konsole`/`xterm` use `-e`,
|
|
11
|
+
* GNOME Terminal uses `--`, wezterm uses `start --`, XFCE/MATE/Terminator use `-x`).
|
|
12
|
+
*/
|
|
13
|
+
import { readFileSync, statSync } from 'node:fs';
|
|
14
|
+
import { homedir } from 'node:os';
|
|
15
|
+
import { basename, delimiter, join } from 'node:path';
|
|
16
|
+
import { splitCommandLine } from './commandLine.js';
|
|
17
|
+
function isExecutableFile(path) {
|
|
18
|
+
try {
|
|
19
|
+
const stat = statSync(path);
|
|
20
|
+
return stat.isFile() && (stat.mode & 0o111) !== 0;
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/** Whether `command` resolves to an executable on PATH (or is an executable path). */
|
|
27
|
+
export function isExecutableOnPath(command, env = process.env) {
|
|
28
|
+
if (command === '')
|
|
29
|
+
return false;
|
|
30
|
+
if (command.includes('/'))
|
|
31
|
+
return isExecutableFile(command);
|
|
32
|
+
for (const dir of (env.PATH ?? '').split(delimiter)) {
|
|
33
|
+
if (dir === '')
|
|
34
|
+
continue;
|
|
35
|
+
if (isExecutableFile(join(dir, command)))
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
/** How a terminal takes the program to run. */
|
|
41
|
+
function separatorFor(file) {
|
|
42
|
+
switch (basename(file).replace(/\.exe$/i, '')) {
|
|
43
|
+
case 'kitty':
|
|
44
|
+
case 'foot':
|
|
45
|
+
case 'xdg-terminal-exec':
|
|
46
|
+
return [];
|
|
47
|
+
case 'wezterm':
|
|
48
|
+
return ['start', '--'];
|
|
49
|
+
case 'gnome-terminal':
|
|
50
|
+
return ['--'];
|
|
51
|
+
case 'xfce4-terminal':
|
|
52
|
+
case 'mate-terminal':
|
|
53
|
+
case 'terminator':
|
|
54
|
+
return ['-x'];
|
|
55
|
+
default:
|
|
56
|
+
return ['-e'];
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function specFor(commandLine) {
|
|
60
|
+
const argv = splitCommandLine(commandLine);
|
|
61
|
+
const file = argv[0];
|
|
62
|
+
if (file === undefined || file === '')
|
|
63
|
+
return undefined;
|
|
64
|
+
return { file, args: argv.slice(1), separator: separatorFor(file) };
|
|
65
|
+
}
|
|
66
|
+
/** KDE stores its terminal choice in `~/.config/kdeglobals` (`[General]`). */
|
|
67
|
+
function readKdeTerminal(env) {
|
|
68
|
+
const configHome = env.XDG_CONFIG_HOME?.trim() || join(env.HOME?.trim() || homedir(), '.config');
|
|
69
|
+
let text;
|
|
70
|
+
try {
|
|
71
|
+
text = readFileSync(join(configHome, 'kdeglobals'), 'utf8');
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
let inGeneral = false;
|
|
77
|
+
for (const raw of text.split(/\r?\n/)) {
|
|
78
|
+
const line = raw.trim();
|
|
79
|
+
if (line.startsWith('[') && line.endsWith(']')) {
|
|
80
|
+
inGeneral = line === '[General]';
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
if (!inGeneral)
|
|
84
|
+
continue;
|
|
85
|
+
const eq = line.indexOf('=');
|
|
86
|
+
if (eq <= 0)
|
|
87
|
+
continue;
|
|
88
|
+
if (line.slice(0, eq).trim() !== 'TerminalApplication')
|
|
89
|
+
continue;
|
|
90
|
+
const value = line.slice(eq + 1).trim();
|
|
91
|
+
return value === '' ? undefined : specFor(value);
|
|
92
|
+
}
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
const FALLBACK_TERMINALS = ['kitty', 'ghostty', 'konsole', 'alacritty', 'wezterm', 'foot', 'rio', 'gnome-terminal', 'xterm'];
|
|
96
|
+
/** Resolve the terminal command, or undefined when none is available. */
|
|
97
|
+
export function resolveTerminal(env = process.env) {
|
|
98
|
+
const explicit = env.TERMINAL?.trim() ?? '';
|
|
99
|
+
if (explicit !== '') {
|
|
100
|
+
const spec = specFor(explicit);
|
|
101
|
+
if (spec !== undefined && isExecutableOnPath(spec.file, env))
|
|
102
|
+
return spec;
|
|
103
|
+
}
|
|
104
|
+
// A stale kdeglobals value must not shadow a working xdg-terminal-exec or
|
|
105
|
+
// the known-terminal fallbacks below.
|
|
106
|
+
const kde = readKdeTerminal(env);
|
|
107
|
+
if (kde !== undefined && isExecutableOnPath(kde.file, env))
|
|
108
|
+
return kde;
|
|
109
|
+
if (isExecutableOnPath('xdg-terminal-exec', env)) {
|
|
110
|
+
return { file: 'xdg-terminal-exec', args: [], separator: [] };
|
|
111
|
+
}
|
|
112
|
+
for (const file of FALLBACK_TERMINALS) {
|
|
113
|
+
if (isExecutableOnPath(file, env))
|
|
114
|
+
return { file, args: [], separator: separatorFor(file) };
|
|
115
|
+
}
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
/** Assemble the final argv: terminal args, separator, then the handler argv. */
|
|
119
|
+
export function buildTerminalSpawn(terminal, argv) {
|
|
120
|
+
return { file: terminal.file, args: [...terminal.args, ...terminal.separator, ...argv] };
|
|
121
|
+
}
|