@noldova/terminal 0.0.16 → 0.0.17
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/module.json +2 -2
- package/package.json +9 -9
- package/src/enums/mark-kind.js +1 -0
- package/src/enums/shell-family.js +1 -0
- package/src/exceptions/command-exited.exception.js +2 -1
- package/src/models/hosted-terminal.js +20 -9
- package/src/models/one-shot-launch.js +7 -4
- package/src/models/right-prompt-span.js +14 -0
- package/src/models/terminal-prompt.js +5 -5
- package/src/models/typed-line.js +2 -2
- package/src/resources.js +263 -13
- package/src/services/agent-terminal.js +7 -5
- package/src/services/command-describer.js +35 -33
- package/src/services/command-runner.js +5 -3
- package/src/services/command-tracker.js +17 -2
- package/src/services/completion-source.js +62 -30
- package/src/services/escape-sequence-tracker.js +1 -1
- package/src/services/escape-stripper.js +10 -7
- package/src/services/file-system.reader.js +2 -1
- package/src/services/fish-shell-adapter.js +90 -0
- package/src/services/folder-change-line.js +2 -0
- package/src/services/line-process.js +3 -2
- package/src/services/log-file.js +4 -3
- package/src/services/mac-environment.js +5 -2
- package/src/services/mark-scanner.js +5 -5
- package/src/services/output-batcher.js +1 -1
- package/src/services/output-log.js +2 -1
- package/src/services/posix-shell-adapter.js +3 -2
- package/src/services/printed-text.js +3 -2
- package/src/services/pseudo-terminal.js +1 -1
- package/src/services/registry-export.js +5 -5
- package/src/services/resize-wakeup.js +1 -1
- package/src/services/saved-terminals.js +2 -1
- package/src/services/shell-adapters.js +3 -1
- package/src/services/shell-command.js +7 -2
- package/src/services/shell-integration.js +32 -14
- package/src/services/shell-locator.js +27 -13
- package/src/services/shell-words.js +5 -5
- package/src/services/terminal-history-segment.js +1 -1
- package/src/services/terminal-host.js +84 -43
- package/src/services/terminal-line-reader.js +9 -3
- package/src/services/terminal-mirror.js +12 -11
- package/src/services/terminal-session.js +24 -8
- package/src/services/wsl-distribution.reader.js +5 -2
- package/src/services/wsl-shell-adapter.js +6 -2
- package/src/tools/models/output-excerpt.js +2 -1
- package/src/tools/models/terminal-output-report.js +4 -2
- package/src/tools/models/tool-call-context.js +2 -1
- package/src/tools/services/terminal-access-policy.js +4 -2
- package/src/tools/services/terminal-text-escaper.js +4 -2
- package/src/tools/services/terminal-write-tool.js +5 -3
package/module.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "terminal",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.17",
|
|
4
4
|
"displayName": "Terminal",
|
|
5
5
|
"description": "Runs shells in terminal panes, and lets AI agents run commands in them through permission requests.",
|
|
6
6
|
"parts": ["runtime", "window"],
|
|
7
7
|
"pseudoTerminals": true,
|
|
8
8
|
"dependencies": {},
|
|
9
|
-
"noldovaDesktop": ">=0.0.
|
|
9
|
+
"noldovaDesktop": ">=0.0.36 <0.1.0",
|
|
10
10
|
"contributes": {
|
|
11
11
|
"methods": [
|
|
12
12
|
"terminal.shells", "terminal.open", "terminal.close", "terminal.restart", "terminal.sessions", "terminal.attach", "terminal.input", "terminal.resize",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@noldova/terminal",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.17",
|
|
4
4
|
"description": "The terminal module for apps on Noldova Desktop: terminal panes over real shells, and agent tools that run commands through permission requests.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -37,18 +37,18 @@
|
|
|
37
37
|
"registry": "https://registry.npmjs.org/"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@noldova/terminal.protocol": "0.0.
|
|
41
|
-
"@noldova/terminal.window": "0.0.
|
|
40
|
+
"@noldova/terminal.protocol": "0.0.17",
|
|
41
|
+
"@noldova/terminal.window": "0.0.17",
|
|
42
42
|
"@xterm/addon-serialize": "0.14.0",
|
|
43
43
|
"@xterm/headless": "6.0.0",
|
|
44
44
|
"node-pty": "1.2.0-beta.15"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
|
-
"@noldova/desktop.protocol": ">=0.0.
|
|
48
|
-
"@noldova/desktop.runtime": ">=0.0.
|
|
49
|
-
"@noldova/context.core": ">=0.0.
|
|
50
|
-
"@noldova/context.exceptions": ">=0.0.
|
|
51
|
-
"@noldova/context.json": ">=0.0.
|
|
47
|
+
"@noldova/desktop.protocol": ">=0.0.36 <0.1.0",
|
|
48
|
+
"@noldova/desktop.runtime": ">=0.0.36 <0.1.0",
|
|
49
|
+
"@noldova/context.core": ">=0.0.20 <0.1.0",
|
|
50
|
+
"@noldova/context.exceptions": ">=0.0.20 <0.1.0",
|
|
51
|
+
"@noldova/context.json": ">=0.0.20 <0.1.0"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "ab9f326bb1734fd375be8d93dc51d15953aea4bc"
|
|
54
54
|
}
|
package/src/enums/mark-kind.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* This source code is licensed under the license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
|
+
import "@noldova/context.core";
|
|
8
9
|
import { Resources } from "../resources.js";
|
|
9
10
|
import { CommandFailedException } from "./command-failed.exception.js";
|
|
10
11
|
export class CommandExitedException extends CommandFailedException {
|
|
@@ -12,7 +13,7 @@ export class CommandExitedException extends CommandFailedException {
|
|
|
12
13
|
exitCode;
|
|
13
14
|
signal;
|
|
14
15
|
errorText;
|
|
15
|
-
constructor(command, exit, errorText =
|
|
16
|
+
constructor(command, exit, errorText = String.empty) {
|
|
16
17
|
const text = errorText.replace(Resources.whitespaceRuns, " ").trim();
|
|
17
18
|
super(Resources.formatCommandExited(command, exit.code, exit.signal, text));
|
|
18
19
|
this.command = command;
|
|
@@ -48,7 +48,7 @@ export class HostedTerminal {
|
|
|
48
48
|
isRunStarting = false;
|
|
49
49
|
waitingRun = null;
|
|
50
50
|
typedEnds = 1;
|
|
51
|
-
paste =
|
|
51
|
+
paste = String.empty;
|
|
52
52
|
constructor(session, shell, folder, ownerSessionId, isPanelTerminal, owner, connection, environment = null) {
|
|
53
53
|
this.session = session;
|
|
54
54
|
this.shell = shell;
|
|
@@ -84,18 +84,29 @@ export class HostedTerminal {
|
|
|
84
84
|
get hasUnreadInput() {
|
|
85
85
|
const commands = this.session.commands;
|
|
86
86
|
const prompt = commands.promptIdentity;
|
|
87
|
-
return this.hasRecentInput &&
|
|
88
|
-
|
|
87
|
+
return this.hasRecentInput &&
|
|
88
|
+
(Object.isNull(this.inputPrompt) ||
|
|
89
|
+
Object.isNull(prompt) ||
|
|
90
|
+
prompt === this.inputPrompt ||
|
|
91
|
+
commands.commandMarks === this.inputCommandMarks);
|
|
89
92
|
}
|
|
90
93
|
get isFree() {
|
|
91
|
-
return Object.isNull(this.ownerSessionId) &&
|
|
92
|
-
|
|
94
|
+
return Object.isNull(this.ownerSessionId) &&
|
|
95
|
+
!this.session.hasExited &&
|
|
96
|
+
!this.isRestarting &&
|
|
97
|
+
Object.isNull(this.pendingCommand) &&
|
|
98
|
+
this.session.commands.hasMarks &&
|
|
99
|
+
!this.hasUnreadInput &&
|
|
100
|
+
this.session.readPromptLine() === String.empty;
|
|
93
101
|
}
|
|
94
102
|
get isDrawingPrompt() {
|
|
95
|
-
return Object.isNull(this.ownerSessionId) &&
|
|
96
|
-
|
|
103
|
+
return Object.isNull(this.ownerSessionId) &&
|
|
104
|
+
!this.session.hasExited &&
|
|
105
|
+
!this.isRestarting &&
|
|
106
|
+
Object.isNull(this.pendingCommand) &&
|
|
107
|
+
this.session.commands.isDrawingPrompt;
|
|
97
108
|
}
|
|
98
|
-
recordInput(isReply = false, data =
|
|
109
|
+
recordInput(isReply = false, data = String.empty, isAgent = false) {
|
|
99
110
|
this.inputReceivedLength = this.session.receivedLength;
|
|
100
111
|
if (isReply)
|
|
101
112
|
return;
|
|
@@ -141,7 +152,7 @@ export class HostedTerminal {
|
|
|
141
152
|
this.inputCommandMarks = this.session.commands.commandMarks;
|
|
142
153
|
}
|
|
143
154
|
static hasTextAfterLineBreak(data) {
|
|
144
|
-
return data.replace(Resources.bracketedPastes,
|
|
155
|
+
return data.replace(Resources.bracketedPastes, String.empty).split(Resources.lineBreaks).slice(1).some(t => t !== String.empty);
|
|
145
156
|
}
|
|
146
157
|
forgetRun(runId, start) {
|
|
147
158
|
void start.then(t => t.dispose(), () => undefined);
|
|
@@ -25,9 +25,11 @@ export class OneShotLaunch {
|
|
|
25
25
|
return Resources.formatOneShotLaunchCommandLine(OneShotLaunch.quote(this.file), line);
|
|
26
26
|
}
|
|
27
27
|
static quote(argument) {
|
|
28
|
-
const isQuoted = argument ===
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
const isQuoted = argument === String.empty ||
|
|
29
|
+
(Resources.oneShotLaunchArgumentBreak.test(argument) &&
|
|
30
|
+
argument.length > 1 &&
|
|
31
|
+
!(argument.startsWith(Resources.doubleQuote) && argument.endsWith(Resources.doubleQuote)));
|
|
32
|
+
let quoted = isQuoted ? Resources.doubleQuote : String.empty;
|
|
31
33
|
let backslashes = 0;
|
|
32
34
|
for (const unit of argument) {
|
|
33
35
|
if (unit === Resources.backslash)
|
|
@@ -37,7 +39,8 @@ export class OneShotLaunch {
|
|
|
37
39
|
backslashes = 0;
|
|
38
40
|
}
|
|
39
41
|
}
|
|
40
|
-
return isQuoted
|
|
42
|
+
return isQuoted
|
|
43
|
+
? `${quoted}${Resources.backslash.repeat(backslashes * 2)}${Resources.doubleQuote}`
|
|
41
44
|
: quoted + Resources.backslash.repeat(backslashes);
|
|
42
45
|
}
|
|
43
46
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright (c) Noldova.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
export class RightPromptSpan {
|
|
9
|
+
start;
|
|
10
|
+
end = null;
|
|
11
|
+
constructor(start) {
|
|
12
|
+
this.start = start;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -19,10 +19,10 @@ export class TerminalPrompt {
|
|
|
19
19
|
this.inputCount = inputCount;
|
|
20
20
|
}
|
|
21
21
|
equals(other) {
|
|
22
|
-
return other.isIdle === this.isIdle
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
return other.isIdle === this.isIdle &&
|
|
23
|
+
other.cwd === this.cwd &&
|
|
24
|
+
other.promptOffset === this.promptOffset &&
|
|
25
|
+
other.isAwaitingSecret === this.isAwaitingSecret &&
|
|
26
|
+
other.inputCount === this.inputCount;
|
|
27
27
|
}
|
|
28
28
|
}
|
package/src/models/typed-line.js
CHANGED
|
@@ -9,7 +9,7 @@ import "@noldova/context.core";
|
|
|
9
9
|
import { Resources } from "../resources.js";
|
|
10
10
|
export class TypedLine {
|
|
11
11
|
echo;
|
|
12
|
-
tail =
|
|
12
|
+
tail = String.empty;
|
|
13
13
|
isEchoed = false;
|
|
14
14
|
startOffset;
|
|
15
15
|
command = null;
|
|
@@ -36,6 +36,6 @@ export class TypedLine {
|
|
|
36
36
|
this.endOffset = offset;
|
|
37
37
|
}
|
|
38
38
|
static compact(text) {
|
|
39
|
-
return text.replace(Resources.whiteSpace,
|
|
39
|
+
return text.replace(Resources.whiteSpace, String.empty);
|
|
40
40
|
}
|
|
41
41
|
}
|
package/src/resources.js
CHANGED
|
@@ -57,7 +57,7 @@ export class Resources {
|
|
|
57
57
|
static maximumMarkLength = 20_480;
|
|
58
58
|
static markKindLetters = new Map([
|
|
59
59
|
["A", MarkKind.PromptStart], ["B", MarkKind.PromptEnd], ["C", MarkKind.OutputStart], ["D", MarkKind.CommandEnd], ["P", MarkKind.Property],
|
|
60
|
-
["R", MarkKind.RightPrompt], ["F", MarkKind.ContinuationEnd], ["O", MarkKind.Options], ["L", MarkKind.Loaded]
|
|
60
|
+
["R", MarkKind.RightPrompt], ["E", MarkKind.RightPromptEnd], ["F", MarkKind.ContinuationEnd], ["O", MarkKind.Options], ["L", MarkKind.Loaded]
|
|
61
61
|
]);
|
|
62
62
|
static cwdProperty = "Cwd=";
|
|
63
63
|
static pathProperty = "Path=";
|
|
@@ -193,6 +193,13 @@ export class Resources {
|
|
|
193
193
|
static posixQuotedEscapes = "\"\\$`";
|
|
194
194
|
static posixSpecial = /[\s"'\\$`|&;<>()*?[\]{}!#]/gu;
|
|
195
195
|
static posixQuotedSpecial = /["\\$`]/gu;
|
|
196
|
+
static fishCommandBreaks = "|;&(";
|
|
197
|
+
static fishCommandKeywords = ["and", "or", "not", "if", "else", "while", "begin", "command", "builtin", "exec", "time"];
|
|
198
|
+
static fishSingleQuotedEscapes = "'\\";
|
|
199
|
+
static fishDoubleQuotedEscapes = "\"\\$";
|
|
200
|
+
static fishSpecial = /[\s"'\\$|&;<>()*?{}#]/gu;
|
|
201
|
+
static fishSingleQuotedSpecial = /['\\]/gu;
|
|
202
|
+
static fishDoubleQuotedSpecial = /["\\$]/gu;
|
|
196
203
|
static powerShellSpecial = /[\s'"`$|&;(){}@,<>#]/u;
|
|
197
204
|
static powerShellQuotedSpecial = /["`$]/gu;
|
|
198
205
|
static powerShellWildcards = /[[\]*?`]/gu;
|
|
@@ -372,6 +379,7 @@ export class Resources {
|
|
|
372
379
|
static powerShellFolderKeys = "\u001b[24~d";
|
|
373
380
|
static zshFolderKeys = "\u001b[23;7~";
|
|
374
381
|
static folderEncoding = "hex";
|
|
382
|
+
static fishOptionsKeys = "\u001b[24;7~";
|
|
375
383
|
static optionsMilliseconds = 500;
|
|
376
384
|
static firstOptionsMilliseconds = 3_500;
|
|
377
385
|
static powerShellLookupMilliseconds = 10_000;
|
|
@@ -395,6 +403,7 @@ export class Resources {
|
|
|
395
403
|
static whatisNamesPerRun = 6;
|
|
396
404
|
static describeRetryMilliseconds = 300_000;
|
|
397
405
|
static zshNoStartupArgument = "-f";
|
|
406
|
+
static describeShellProgram = "/bin/sh";
|
|
398
407
|
static bashStartupVariable = "BASH_ENV";
|
|
399
408
|
static formatDescribeFailed(count, message) {
|
|
400
409
|
return `The lookup of ${count} ${count === 1 ? "command's description" : "commands' descriptions"} gave up, so they show none: ${message}`;
|
|
@@ -485,7 +494,7 @@ for ($index = 0; $index -lt $names.Count; $index++) {
|
|
|
485
494
|
static aclRemovalArguments = ["-N"];
|
|
486
495
|
static folderAccessMilliseconds = 10_000;
|
|
487
496
|
static shellsFile = "/etc/shells";
|
|
488
|
-
static
|
|
497
|
+
static systemShellFile = "/bin/sh";
|
|
489
498
|
static unixShellKinds = new Map([
|
|
490
499
|
["bash", TerminalShellKind.Bash], ["zsh", TerminalShellKind.Zsh], ["fish", TerminalShellKind.Fish], ["pwsh", TerminalShellKind.PowerShell]
|
|
491
500
|
]);
|
|
@@ -532,7 +541,8 @@ for ($index = 0; $index -lt $names.Count; $index++) {
|
|
|
532
541
|
" $key.Close()",
|
|
533
542
|
"}",
|
|
534
543
|
"[Console]::Out.WriteLine('End')"
|
|
535
|
-
]
|
|
544
|
+
]
|
|
545
|
+
.join("\n");
|
|
536
546
|
static base64Pattern = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/u;
|
|
537
547
|
static vswherePath = ["Microsoft Visual Studio", "Installer", "vswhere.exe"];
|
|
538
548
|
static vswhereArguments = ["-products", "*", "-prerelease", "-utf8", "-format", "json"];
|
|
@@ -633,6 +643,7 @@ for ($index = 0; $index -lt $names.Count; $index++) {
|
|
|
633
643
|
static timeoutFieldDescription = "Ends the command after this many milliseconds; 0, the default, means never.";
|
|
634
644
|
static waitFieldDescription = `How long to wait for new output when there is none yet, up to ${Resources.maximumCallMilliseconds} milliseconds; a longer wait is clamped, and 0 returns at once.`;
|
|
635
645
|
static maxCharsFieldDescription = `The most characters of output to return, up to ${Resources.maximumToolOutputCharacters}; a larger number is clamped. Longer output keeps its start and end and says how much it left out.`;
|
|
646
|
+
static shellIdFieldDescription = "The terminal's shell id, such as bash, zsh, pwsh or cmd, as terminal_open and terminal_list report it.";
|
|
636
647
|
static shellFieldDescription = "The shell's id, such as bash, zsh, pwsh or cmd. The default shell when absent.";
|
|
637
648
|
static statusFieldDescription = "The command's status, or null when the output isn't from a command this session ran.";
|
|
638
649
|
static methodFieldDescription = "InShell when the command ran at the terminal's prompt, OneShot when it ran in a new shell process of its own, or null when the output isn't from a command.";
|
|
@@ -670,6 +681,7 @@ if [ -n "\${NOLDOVA_TERMINAL_NOTE-}" ]; then printf '%s' "$NOLDOVA_TERMINAL_NOTE
|
|
|
670
681
|
unset NOLDOVA_TERMINAL_NONCE_FILE NOLDOVA_TERMINAL_LOGIN NOLDOVA_TERMINAL_NOTE
|
|
671
682
|
exec "$s" -l`;
|
|
672
683
|
static zshExecutable = "zsh";
|
|
684
|
+
static fishExecutable = "fish";
|
|
673
685
|
static pwshExecutable = "pwsh";
|
|
674
686
|
static windowsPowerShellExecutable = "powershell";
|
|
675
687
|
static nonceFileVariable = "NOLDOVA_TERMINAL_NONCE_FILE";
|
|
@@ -683,6 +695,12 @@ exec "$s" -l`;
|
|
|
683
695
|
static dotnetSharedMemoryFolder = "shm";
|
|
684
696
|
static dotnetSharedMemoryFolderMode = 0o700;
|
|
685
697
|
static bashScriptFile = "noldova.bash";
|
|
698
|
+
static fishScriptFolder = ["fish", "vendor_conf.d"];
|
|
699
|
+
static fishScriptFile = "noldova.fish";
|
|
700
|
+
static dataFoldersVariable = "XDG_DATA_DIRS";
|
|
701
|
+
static userDataFoldersVariable = "NOLDOVA_TERMINAL_DATA_DIRS";
|
|
702
|
+
static defaultDataFolders = "/usr/local/share:/usr/share";
|
|
703
|
+
static integrationFolderMode = 0o700;
|
|
686
704
|
static nonceFilePrefix = "nonce-";
|
|
687
705
|
static nonceFileNameBytes = 16;
|
|
688
706
|
static zshEnvironmentFile = ".zshenv";
|
|
@@ -804,7 +822,7 @@ exit 0
|
|
|
804
822
|
}
|
|
805
823
|
static formatCommandExited(name, exitCode, signal, errorText) {
|
|
806
824
|
const exited = `${name} exited with ${String(exitCode ?? signal)}`;
|
|
807
|
-
return errorText ===
|
|
825
|
+
return errorText === String.empty ? `${exited}.` : `${exited}: ${errorText}`;
|
|
808
826
|
}
|
|
809
827
|
static formatEnvironmentKeyUnread(key) {
|
|
810
828
|
return `The key ${key} could not be read.`;
|
|
@@ -888,7 +906,7 @@ exit 0
|
|
|
888
906
|
return `The terminal module has no method ${method}.`;
|
|
889
907
|
}
|
|
890
908
|
static formatShellLeftRunning(sessionId, pid) {
|
|
891
|
-
return `The shell of terminal ${sessionId}${Object.isNull(pid) ?
|
|
909
|
+
return `The shell of terminal ${sessionId}${Object.isNull(pid) ? String.empty : `, process ${pid}`}, or a process it started, did not end in time.`;
|
|
892
910
|
}
|
|
893
911
|
static formatTerminalHistoryFile(sessionId, index) {
|
|
894
912
|
return `${sessionId}-${index}.jsonl`;
|
|
@@ -927,7 +945,7 @@ exit 0
|
|
|
927
945
|
return `ConPTY sent terminal ${sessionId} no cursor request within ${String(Resources.cursorAnswerMilliseconds)} ms of a resize, so the keys typed meanwhile went on without one.`;
|
|
928
946
|
}
|
|
929
947
|
static formatLateShellLeftRunning(pid) {
|
|
930
|
-
return `A shell that started as the terminals ended${Object.isNull(pid) ?
|
|
948
|
+
return `A shell that started as the terminals ended${Object.isNull(pid) ? String.empty : `, process ${pid}`}, or a process it started, did not end in time.`;
|
|
931
949
|
}
|
|
932
950
|
static formatLogFailed(path, message) {
|
|
933
951
|
return `The log file ${path} stopped taking output: ${message}`;
|
|
@@ -951,7 +969,7 @@ exit 0
|
|
|
951
969
|
return start.map(t => (Resources.cmdQuotedArgumentPattern.test(t) ? `"${t}"` : t)).join(" ");
|
|
952
970
|
}
|
|
953
971
|
static formatCmdNoteLine(commandPrompt, name, start) {
|
|
954
|
-
return `/s /k ""${commandPrompt}" /d /v:on /s /c "echo(^!${name}^!"& set "${name}="${start ===
|
|
972
|
+
return `/s /k ""${commandPrompt}" /d /v:on /s /c "echo(^!${name}^!"& set "${name}="${start === String.empty ? String.empty : ` & ${start}`}"`;
|
|
955
973
|
}
|
|
956
974
|
static formatOneShotFailed(message) {
|
|
957
975
|
return `The command could not start: ${message}`;
|
|
@@ -1024,8 +1042,8 @@ exit 0
|
|
|
1024
1042
|
return `Terminal ${terminalId} waits for a password or another secret. Only the person types it; ask them to.`;
|
|
1025
1043
|
}
|
|
1026
1044
|
static formatLineInUse(terminalId) {
|
|
1027
|
-
return `Terminal ${terminalId} has text on its line, or the person just typed in it, so the keys would join their line and nothing was sent. `
|
|
1028
|
-
|
|
1045
|
+
return `Terminal ${terminalId} has text on its line, or the person just typed in it, so the keys would join their line and nothing was sent. ` +
|
|
1046
|
+
"Read it with terminal_read, and write once its line is empty.";
|
|
1029
1047
|
}
|
|
1030
1048
|
static formatCloseOutcomeUncertain(terminalId) {
|
|
1031
1049
|
return `The call ended while terminal ${terminalId} closed. terminal_list shows whether it's still open.`;
|
|
@@ -1034,7 +1052,7 @@ exit 0
|
|
|
1034
1052
|
return `\n[… characters left out: ${count}; the log file keeps the output up to ${Resources.maximumLogFileLength} characters, and says where it stops …]\n`;
|
|
1035
1053
|
}
|
|
1036
1054
|
static formatCommandSummary(status, exitCode, cwd, isAwaitingSecret) {
|
|
1037
|
-
const secret = isAwaitingSecret ? " The terminal waits for a password or another secret: only the person types it, so ask them to." :
|
|
1055
|
+
const secret = isAwaitingSecret ? " The terminal waits for a password or another secret: only the person types it, so ask them to." : String.empty;
|
|
1038
1056
|
return `\n\n[Status: ${status ?? "no command"}. Exit code: ${exitCode ?? "none"}. Working folder: ${cwd ?? "unknown"}.${secret}]`;
|
|
1039
1057
|
}
|
|
1040
1058
|
static formatTerminalOpened(terminalId, shellId, cwd) {
|
|
@@ -1749,8 +1767,9 @@ if [[ -n "\${__noldova_nonce_read-}" && -z "\${__noldova_nonce-}" ]]; then
|
|
|
1749
1767
|
__noldova_prompt_start="$(__noldova_mark A)"
|
|
1750
1768
|
__noldova_prompt_end="$(__noldova_mark B)"
|
|
1751
1769
|
__noldova_right_prompt="$(__noldova_mark R)"
|
|
1770
|
+
__noldova_right_prompt_end="$(__noldova_mark E)"
|
|
1752
1771
|
__noldova_continuation="$(__noldova_mark F)"
|
|
1753
|
-
builtin typeset +x __noldova_prompt_start __noldova_prompt_end __noldova_right_prompt __noldova_continuation
|
|
1772
|
+
builtin typeset +x __noldova_prompt_start __noldova_prompt_end __noldova_right_prompt __noldova_right_prompt_end __noldova_continuation
|
|
1754
1773
|
|
|
1755
1774
|
__noldova_capture() {
|
|
1756
1775
|
__noldova_status=$?
|
|
@@ -1842,10 +1861,11 @@ if [[ -n "\${__noldova_nonce_read-}" && -z "\${__noldova_nonce-}" ]]; then
|
|
|
1842
1861
|
PS2="$PS2%{$__noldova_continuation%}"
|
|
1843
1862
|
fi
|
|
1844
1863
|
builtin typeset -g +x PS2
|
|
1845
|
-
# A right prompt starts with its own mark, so the terminal knows where the person's line ends on the prompt's row
|
|
1864
|
+
# A right prompt starts with its own mark, so the terminal knows where the person's line ends on the prompt's row, and ends with
|
|
1865
|
+
# another, so its text isn't read as typed.
|
|
1846
1866
|
if [[ -n "$RPROMPT" ]]; then
|
|
1847
1867
|
if [[ "$RPROMPT" != *"$__noldova_right_prompt"* ]]; then
|
|
1848
|
-
RPROMPT="%{$__noldova_right_prompt%}$RPROMPT"
|
|
1868
|
+
RPROMPT="%{$__noldova_right_prompt%}$RPROMPT%{$__noldova_right_prompt_end%}"
|
|
1849
1869
|
fi
|
|
1850
1870
|
builtin typeset -g +x RPROMPT
|
|
1851
1871
|
fi
|
|
@@ -1976,6 +1996,236 @@ if [[ -n "$__noldova_had_zdotdir" || "$ZDOTDIR" != "$HOME" ]]; then
|
|
|
1976
1996
|
else
|
|
1977
1997
|
builtin unset ZDOTDIR
|
|
1978
1998
|
fi
|
|
1999
|
+
`;
|
|
2000
|
+
static shellIntegrationFishScript = `# The terminal module's shell integration for fish, which fish reads from vendor_conf.d in the folder the runtime put first in XDG_DATA_DIRS,
|
|
2001
|
+
# before the person's config.fish. It never changes the person's files.
|
|
2002
|
+
# XDG_DATA_DIRS goes back to what the shell started with first, so no program the shell starts finds this folder.
|
|
2003
|
+
if set -q NOLDOVA_TERMINAL_DATA_DIRS
|
|
2004
|
+
if test -n "$NOLDOVA_TERMINAL_DATA_DIRS"
|
|
2005
|
+
set -gx XDG_DATA_DIRS $NOLDOVA_TERMINAL_DATA_DIRS
|
|
2006
|
+
else
|
|
2007
|
+
set -e XDG_DATA_DIRS
|
|
2008
|
+
end
|
|
2009
|
+
set -e NOLDOVA_TERMINAL_DATA_DIRS
|
|
2010
|
+
end
|
|
2011
|
+
# The nonce's file is read, emptied and removed before the person's startup files run, so no program the shell starts later finds it.
|
|
2012
|
+
if set -q NOLDOVA_TERMINAL_NONCE_FILE
|
|
2013
|
+
read -l __noldova_nonce_read <$NOLDOVA_TERMINAL_NONCE_FILE
|
|
2014
|
+
printf '' >$NOLDOVA_TERMINAL_NONCE_FILE
|
|
2015
|
+
command rm -f -- $NOLDOVA_TERMINAL_NONCE_FILE
|
|
2016
|
+
set -e NOLDOVA_TERMINAL_NONCE_FILE
|
|
2017
|
+
if test -n "$__noldova_nonce_read"; and status is-interactive; and not set -q __noldova_nonce
|
|
2018
|
+
# Nothing that holds the nonce is exported.
|
|
2019
|
+
set -g __noldova_nonce $__noldova_nonce_read
|
|
2020
|
+
end
|
|
2021
|
+
end
|
|
2022
|
+
if set -q __noldova_nonce; and not set -q __noldova_loaded
|
|
2023
|
+
set -g __noldova_loaded 1
|
|
2024
|
+
# The loaded mark, before the person's startup files, tells the runtime the integration runs, so it waits for the first prompt however
|
|
2025
|
+
# long they take.
|
|
2026
|
+
printf '\\e]6973;L;%s\\a' $__noldova_nonce
|
|
2027
|
+
# The terminal's note, written as it is before the person's startup files, so it stays the terminal's first lines.
|
|
2028
|
+
if set -q NOLDOVA_TERMINAL_NOTE
|
|
2029
|
+
printf '%s' $NOLDOVA_TERMINAL_NOTE
|
|
2030
|
+
set -e NOLDOVA_TERMINAL_NOTE
|
|
2031
|
+
end
|
|
2032
|
+
set -g __noldova_in_command 0
|
|
2033
|
+
set -g __noldova_status 0
|
|
2034
|
+
set -g __noldova_path_sent
|
|
2035
|
+
set -g __noldova_names_sent
|
|
2036
|
+
set -g __noldova_builtins_sent 0
|
|
2037
|
+
set -g __noldova_options_sent 0
|
|
2038
|
+
|
|
2039
|
+
function __noldova_mark
|
|
2040
|
+
if set -q argv[2]
|
|
2041
|
+
printf '\\e]6973;%s;%s;%s\\a' $argv[1] $__noldova_nonce $argv[2]
|
|
2042
|
+
else
|
|
2043
|
+
printf '\\e]6973;%s;%s\\a' $argv[1] $__noldova_nonce
|
|
2044
|
+
end
|
|
2045
|
+
end
|
|
2046
|
+
|
|
2047
|
+
# The control characters a value escapes, other than the line feed, which goes first: the C0 controls but NUL, which a fish string never
|
|
2048
|
+
# holds, DEL, and the C1 controls, U+0080 to U+009F, at whose U+009C a mark would end.
|
|
2049
|
+
set -g __noldova_control_codes (seq 1 9) (seq 11 31) 127 (seq 128 159)
|
|
2050
|
+
set -g __noldova_controls
|
|
2051
|
+
for __noldova_code in $__noldova_control_codes
|
|
2052
|
+
if test $__noldova_code -lt 128
|
|
2053
|
+
set -a __noldova_controls (printf (printf '\\\\\\\\x%02x' $__noldova_code))
|
|
2054
|
+
else
|
|
2055
|
+
set -a __noldova_controls (printf (printf '\\\\\\\\u%04x' $__noldova_code))
|
|
2056
|
+
end
|
|
2057
|
+
end
|
|
2058
|
+
set -e __noldova_code
|
|
2059
|
+
|
|
2060
|
+
# A value escapes the controls, the separator and the backslash as \\xHH, which the runtime decodes; a value with none of them skips the
|
|
2061
|
+
# walk. It prints the escaped value, which a command substitution runs in the shell's own process.
|
|
2062
|
+
function __noldova_escape
|
|
2063
|
+
set -l value $argv[1]
|
|
2064
|
+
if not string match -qr '[\\x01-\\x1f;\\\\\\\\\\x7f-\\x9f]' -- $value
|
|
2065
|
+
printf '%s' $value
|
|
2066
|
+
return
|
|
2067
|
+
end
|
|
2068
|
+
set value (string replace -a -- '\\\\' '\\\\x5c' $value | string collect)
|
|
2069
|
+
set value (string replace -a -- \\n '\\\\x0a' $value | string collect)
|
|
2070
|
+
set value (string replace -a -- ';' '\\\\x3b' $value | string collect)
|
|
2071
|
+
for index in (seq (count $__noldova_controls))
|
|
2072
|
+
set value (string replace -a -- $__noldova_controls[$index] (printf '\\\\\\\\x%02x' $__noldova_control_codes[$index]) $value | string collect)
|
|
2073
|
+
end
|
|
2074
|
+
printf '%s' $value
|
|
2075
|
+
end
|
|
2076
|
+
|
|
2077
|
+
# A value longer than the limit, in UTF-16 code units, which fish counts as one for each character, sends the reset alone.
|
|
2078
|
+
function __noldova_capped_mark --argument-names value limit property reset
|
|
2079
|
+
if test (string length -- "$value") -gt $limit
|
|
2080
|
+
__noldova_mark P $reset
|
|
2081
|
+
return
|
|
2082
|
+
end
|
|
2083
|
+
set -l escaped (__noldova_escape $value)
|
|
2084
|
+
if test (string length -- (string replace -ra '[\\x{10000}-\\x{10ffff}]' '..' -- "$escaped")) -gt $limit
|
|
2085
|
+
__noldova_mark P $reset
|
|
2086
|
+
else
|
|
2087
|
+
__noldova_mark P "$property$escaped"
|
|
2088
|
+
end
|
|
2089
|
+
end
|
|
2090
|
+
|
|
2091
|
+
# Copies the person's function to the body the wrapper calls, unless the function already is the wrapper; a function that doesn't exist
|
|
2092
|
+
# gets an empty body.
|
|
2093
|
+
function __noldova_unwrapped --argument-names name body
|
|
2094
|
+
if functions -q $name; and string match -q "*$body*" -- (functions $name | string collect)
|
|
2095
|
+
return 1
|
|
2096
|
+
end
|
|
2097
|
+
functions -e $body
|
|
2098
|
+
if functions -q $name
|
|
2099
|
+
functions -c $name $body
|
|
2100
|
+
else
|
|
2101
|
+
function $body
|
|
2102
|
+
end
|
|
2103
|
+
end
|
|
2104
|
+
end
|
|
2105
|
+
|
|
2106
|
+
function __noldova_return
|
|
2107
|
+
return $argv[1]
|
|
2108
|
+
end
|
|
2109
|
+
|
|
2110
|
+
function __noldova_prompt --on-event fish_prompt
|
|
2111
|
+
set -l path (string join : -- $PATH)
|
|
2112
|
+
if test "$path" != "$__noldova_path_sent"
|
|
2113
|
+
set -g __noldova_path_sent $path
|
|
2114
|
+
__noldova_capped_mark "$path" ${Resources.maximumPathValueLength} ${Resources.pathProperty} ${Resources.pathReset}
|
|
2115
|
+
end
|
|
2116
|
+
if test $__noldova_builtins_sent = 0
|
|
2117
|
+
set -g __noldova_builtins_sent 1
|
|
2118
|
+
set -l builtins (string join ' ' -- (builtin -n))
|
|
2119
|
+
__noldova_capped_mark "$builtins" ${Resources.maximumNamesValueLength} ${Resources.builtinsProperty} ${Resources.builtinsReset}
|
|
2120
|
+
end
|
|
2121
|
+
# The person's functions, aliases among them, and abbreviations; fish lists no function starting with _.
|
|
2122
|
+
set -l names (string join ' ' -- (functions -n) (abbr --list))
|
|
2123
|
+
if test "$names" != "$__noldova_names_sent"
|
|
2124
|
+
set -g __noldova_names_sent $names
|
|
2125
|
+
__noldova_capped_mark "$names" ${Resources.maximumNamesValueLength} ${Resources.namesProperty} ${Resources.namesReset}
|
|
2126
|
+
end
|
|
2127
|
+
__noldova_bind
|
|
2128
|
+
set -l options 0
|
|
2129
|
+
if test (__noldova_bound_count) -eq 2
|
|
2130
|
+
set options ${Resources.optionsBound}
|
|
2131
|
+
end
|
|
2132
|
+
if test $options != $__noldova_options_sent
|
|
2133
|
+
set -g __noldova_options_sent $options
|
|
2134
|
+
__noldova_mark P "${Resources.optionsProperty}$options"
|
|
2135
|
+
end
|
|
2136
|
+
__noldova_mark P "${Resources.cwdProperty}"(__noldova_escape $PWD)
|
|
2137
|
+
if test $__noldova_in_command = 1
|
|
2138
|
+
set -g __noldova_in_command 0
|
|
2139
|
+
__noldova_mark D $__noldova_status
|
|
2140
|
+
end
|
|
2141
|
+
# The prompt's start mark comes first in the mode prompt, which fish draws before the left prompt, so the person's prompt keeps the last
|
|
2142
|
+
# command's status; the end mark comes after the left prompt, and a right prompt starts and ends with its own. Each is put back at the next
|
|
2143
|
+
# prompt when the person's files or a theme defined the function again.
|
|
2144
|
+
if __noldova_unwrapped fish_mode_prompt __noldova_mode_prompt
|
|
2145
|
+
function fish_mode_prompt
|
|
2146
|
+
__noldova_mark A
|
|
2147
|
+
__noldova_mode_prompt $argv
|
|
2148
|
+
end
|
|
2149
|
+
end
|
|
2150
|
+
if __noldova_unwrapped fish_prompt __noldova_left_prompt
|
|
2151
|
+
function fish_prompt
|
|
2152
|
+
__noldova_left_prompt $argv
|
|
2153
|
+
__noldova_mark B
|
|
2154
|
+
end
|
|
2155
|
+
end
|
|
2156
|
+
# A right prompt keeps the last command's status, though not each of a pipeline's, and ends with its own mark, so its text isn't read
|
|
2157
|
+
# as typed.
|
|
2158
|
+
if functions -q fish_right_prompt; and __noldova_unwrapped fish_right_prompt __noldova_right_prompt
|
|
2159
|
+
function fish_right_prompt
|
|
2160
|
+
set -l last $status
|
|
2161
|
+
__noldova_mark R
|
|
2162
|
+
__noldova_return $last
|
|
2163
|
+
__noldova_right_prompt $argv
|
|
2164
|
+
__noldova_mark E
|
|
2165
|
+
end
|
|
2166
|
+
end
|
|
2167
|
+
end
|
|
2168
|
+
|
|
2169
|
+
# The command's mark gives its first line as typed, at most 4,096 characters; an empty line runs no command.
|
|
2170
|
+
function __noldova_preexec --on-event fish_preexec
|
|
2171
|
+
set -l typed (string split -m1 \\n -- $argv[1])[1]
|
|
2172
|
+
if test -z (string trim -- "$typed")
|
|
2173
|
+
return
|
|
2174
|
+
end
|
|
2175
|
+
set -g __noldova_in_command 1
|
|
2176
|
+
__noldova_mark C "${Resources.commandProperty}"(__noldova_escape (string sub -l 4096 -- $typed))
|
|
2177
|
+
end
|
|
2178
|
+
|
|
2179
|
+
# The command's status goes out with its end mark at the next prompt, after the folder it left the shell in.
|
|
2180
|
+
function __noldova_postexec --on-event fish_postexec
|
|
2181
|
+
set -g __noldova_status $status
|
|
2182
|
+
end
|
|
2183
|
+
|
|
2184
|
+
# The hidden completion binding runs fish's own completion for the line up to the cursor and answers in an options mark with those that
|
|
2185
|
+
# start with -, which shows nothing and changes neither the line nor the history. A completion that gives none still sends the mark.
|
|
2186
|
+
function __noldova_list_options
|
|
2187
|
+
set -l mark (printf '\\e]6973;O;%s' $__noldova_nonce)
|
|
2188
|
+
set -l count 0
|
|
2189
|
+
set -l typed (commandline -cp | string collect)
|
|
2190
|
+
for line in (complete -C "$typed")
|
|
2191
|
+
set -l option (string split -m1 \\t -- $line)[1]
|
|
2192
|
+
string match -q -- '-*' $option; or continue
|
|
2193
|
+
test $count -lt ${ProtocolResources.maximumCompletionItems}; or break
|
|
2194
|
+
set -l field (__noldova_escape $option)
|
|
2195
|
+
test (math (string length -- "$mark") + (string length -- "$field")) -lt ${Resources.maximumPathValueLength}; or break
|
|
2196
|
+
set mark "$mark;$field"
|
|
2197
|
+
set count (math $count + 1)
|
|
2198
|
+
end
|
|
2199
|
+
printf '%s\\a' $mark
|
|
2200
|
+
end
|
|
2201
|
+
|
|
2202
|
+
# Ctrl+Alt+F12, which fish 4 names and fish 3 reads as its escape sequence, in the modes the person's bindings use.
|
|
2203
|
+
if string match -qr '^[0-3]\\.' -- $version
|
|
2204
|
+
set -g __noldova_options_key \\e\\[24\\;7~
|
|
2205
|
+
else
|
|
2206
|
+
set -g __noldova_options_key ctrl-alt-f12
|
|
2207
|
+
end
|
|
2208
|
+
|
|
2209
|
+
function __noldova_bound_count
|
|
2210
|
+
set -l count 0
|
|
2211
|
+
for mode in default insert
|
|
2212
|
+
if string match -q '*__noldova_list_options*' -- (bind -M $mode $__noldova_options_key 2>/dev/null | string collect)
|
|
2213
|
+
set count (math $count + 1)
|
|
2214
|
+
end
|
|
2215
|
+
end
|
|
2216
|
+
echo $count
|
|
2217
|
+
end
|
|
2218
|
+
|
|
2219
|
+
# Not where the person bound the key, which the binding would take over; it binds again after the person's key bindings were set again,
|
|
2220
|
+
# as fish_vi_key_bindings erases every binding.
|
|
2221
|
+
function __noldova_bind
|
|
2222
|
+
for mode in default insert
|
|
2223
|
+
if not bind -M $mode $__noldova_options_key >/dev/null 2>&1
|
|
2224
|
+
bind -M $mode $__noldova_options_key __noldova_list_options
|
|
2225
|
+
end
|
|
2226
|
+
end
|
|
2227
|
+
end
|
|
2228
|
+
end
|
|
1979
2229
|
`;
|
|
1980
2230
|
static shellWordsPowerShellEscapeReplacement = "`$&";
|
|
1981
2231
|
static shellWordsPosixEscapeReplacement = "\\$&";
|