@noldova/terminal 0.0.6 → 0.0.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/README.md +1 -1
- package/module.json +2 -2
- package/package.json +8 -6
- package/src/exceptions/stored-lines-damaged.exception.js +2 -1
- package/src/models/hosted-terminal.js +14 -7
- package/src/models/integration-script.js +15 -0
- package/src/models/mark-introducer.js +15 -0
- package/src/models/mark-terminator.js +15 -0
- package/src/models/mirror-line.js +2 -1
- package/src/models/one-shot-launch.js +2 -1
- package/src/models/output-span.js +15 -0
- package/src/models/shell-candidate.js +21 -0
- package/src/models/shell-mark.js +2 -1
- package/src/models/taken-segment.js +15 -0
- package/src/models/terminal-folder-key.js +15 -0
- package/src/models/terminal-opening.js +2 -1
- package/src/models/tracked-command.js +2 -1
- package/src/models/typed-line.js +2 -1
- package/src/models/wsl-launcher.js +15 -0
- package/src/resources.js +7 -3
- package/src/runtime-part.js +2 -1
- package/src/services/agent-terminal.js +8 -5
- package/src/services/agent-terminals.js +3 -2
- package/src/services/bounded-reads.js +7 -5
- package/src/services/change-signal.js +5 -4
- package/src/services/command-runner.js +10 -4
- package/src/services/command-tracker.js +5 -4
- package/src/services/completion-source.js +27 -23
- package/src/services/context-pty-process.js +3 -2
- package/src/services/context-pty-spawner.js +2 -1
- package/src/services/deferred-pty-process.js +7 -5
- package/src/services/escape-sequence-tracker.js +2 -1
- package/src/services/failure-text.js +2 -1
- package/src/services/flow-controller.js +5 -4
- package/src/services/latest-environment.js +2 -1
- package/src/services/mac-environment.js +3 -2
- package/src/services/mark-scanner.js +22 -14
- package/src/services/one-shot-command.js +3 -2
- package/src/services/output-batcher.js +2 -1
- package/src/services/output-log.js +4 -1
- package/src/services/powershell-binding.js +7 -6
- package/src/services/pseudo-terminal.js +7 -1
- package/src/services/registry-export.js +3 -2
- package/src/services/resize-wakeup.js +2 -1
- package/src/services/saved-terminals.js +2 -1
- package/src/services/shared-reads.js +3 -2
- package/src/services/shell-command.js +14 -15
- package/src/services/shell-integration.js +24 -22
- package/src/services/shell-locator.js +25 -22
- package/src/services/shell-words.js +3 -2
- package/src/services/system-requirements.js +9 -9
- package/src/services/terminal-audience.js +10 -9
- package/src/services/terminal-history-folder.js +5 -4
- package/src/services/terminal-history-segment.js +2 -1
- package/src/services/terminal-history.js +14 -12
- package/src/services/terminal-host.js +104 -101
- package/src/services/terminal-line-reader.js +3 -2
- package/src/services/terminal-mirror.js +13 -12
- package/src/services/terminal-session.js +37 -26
- package/src/services/visual-studio.reader.js +3 -2
- package/src/services/windows-environment.js +12 -11
- package/src/services/windows-folder-access.js +2 -1
- package/src/services/wsl-distribution.reader.js +2 -1
- package/src/tools/models/agent-terminal-opening.js +2 -1
- package/src/tools/models/output-chunk.js +4 -1
- package/src/tools/models/output-excerpt.js +12 -6
- package/src/tools/models/terminal-open-input.js +3 -2
- package/src/tools/models/terminal-output-report.js +5 -4
- package/src/tools/models/terminal-run-input.js +2 -1
- package/src/tools/models/terminal-target-input.js +2 -1
- package/src/tools/models/terminal-write-input.js +2 -1
- package/src/tools/models/tool-call-context.js +4 -3
- package/src/tools/services/permission-details.js +3 -2
- package/src/tools/services/permission-gate.js +2 -1
- package/src/tools/services/terminal-access-policy.js +8 -7
- package/src/tools/services/terminal-interrupt-tool.js +2 -1
- package/src/tools/services/terminal-read-tool.js +3 -2
- package/src/tools/services/terminal-run-tool.js +6 -5
- package/src/tools/services/terminal-text-escaper.js +2 -1
- package/src/tools/services/terminal-tool.js +2 -1
- package/src/tools/services/terminal-write-tool.js +2 -1
|
@@ -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 { MarkKind } from "../enums/mark-kind.js";
|
|
9
10
|
import { TrackedCommand } from "../models/tracked-command.js";
|
|
10
11
|
import { Resources } from "../resources.js";
|
|
@@ -133,9 +134,9 @@ export class CommandTracker {
|
|
|
133
134
|
endPrompt(offset) {
|
|
134
135
|
const from = this.canRedraw ? this.lineOffset : this.redrawFrom;
|
|
135
136
|
const drawn = this.canRedraw ? CommandTracker.lastLine(this.promptText) : this.promptText;
|
|
136
|
-
if (from
|
|
137
|
+
if (Object.isNull(from) || Object.isNull(drawn) || CommandTracker.drawing(this.read(from, offset)) !== drawn) {
|
|
137
138
|
this.promptOffset = offset;
|
|
138
|
-
this.promptText = this.promptStart
|
|
139
|
+
this.promptText = Object.isNull(this.promptStart) ? null : CommandTracker.drawing(this.read(this.promptStart, offset));
|
|
139
140
|
}
|
|
140
141
|
this.lineOffset = offset;
|
|
141
142
|
this.promptStart = null;
|
|
@@ -149,7 +150,7 @@ export class CommandTracker {
|
|
|
149
150
|
return text.length > 1 && text.startsWith(Resources.lineFeed) ? text.slice(1) : text;
|
|
150
151
|
}
|
|
151
152
|
static lastLine(text) {
|
|
152
|
-
return text
|
|
153
|
+
return Object.isNull(text) ? null : text.slice(text.lastIndexOf(Resources.lineFeed) + 1);
|
|
153
154
|
}
|
|
154
155
|
stopRedraws() {
|
|
155
156
|
this.canRedraw = false;
|
|
@@ -157,7 +158,7 @@ export class CommandTracker {
|
|
|
157
158
|
}
|
|
158
159
|
end(mark) {
|
|
159
160
|
const command = this.current ?? new TrackedCommand(this.lineOffset ?? mark.offset, false);
|
|
160
|
-
const exitCode = mark.value
|
|
161
|
+
const exitCode = !Object.isNull(mark.value) && Resources.commandTrackerExitCode.test(mark.value) ? Number.parseInt(mark.value, Resources.decimalRadix) : null;
|
|
161
162
|
command.end(mark.offset, exitCode, this.cwd);
|
|
162
163
|
this.isAtPrompt = false;
|
|
163
164
|
this.current = null;
|
|
@@ -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 path from "node:path";
|
|
9
10
|
import { Resources as ProtocolResources, TerminalCompletion, TerminalCompletionItem, TerminalCompletionKind, TerminalMissingCommands, TerminalShellKind } from "@noldova/terminal.protocol";
|
|
10
11
|
import { CommandFailedException } from "../exceptions/command-failed.exception.js";
|
|
@@ -70,13 +71,13 @@ export class CompletionSource {
|
|
|
70
71
|
return new TerminalCompletion(completion.replaceFrom, items.slice(0, ProtocolResources.maximumCompletionItems));
|
|
71
72
|
}
|
|
72
73
|
async findMissingAsync(key, shell, prompt, kind, folder, names, shellNames, environment) {
|
|
73
|
-
if (kind === TerminalShellKind.PowerShell || !Resources.completedShellKinds.includes(kind) || shellNames
|
|
74
|
+
if (kind === TerminalShellKind.PowerShell || !Resources.completedShellKinds.includes(kind) || Object.isNull(shellNames) || this.stuck.includes(key))
|
|
74
75
|
return new TerminalMissingCommands([]);
|
|
75
76
|
const takesBareNames = this.isWindows && kind === TerminalShellKind.Bash;
|
|
76
77
|
const search = JSON.stringify([kind, this.readVariable(environment, Resources.pathVariable),
|
|
77
78
|
this.readVariable(environment, Resources.pathExtensionsVariable)]);
|
|
78
79
|
const last = this.listed.get(shell);
|
|
79
|
-
const listed = last
|
|
80
|
+
const listed = !Object.isUndefined(last) && last.prompt === prompt && last.search === search ? last.commands : null;
|
|
80
81
|
return this.readAsync(key, async (reads) => {
|
|
81
82
|
const commands = listed ?? (await this.listCommandsAsync(reads, [], environment, takesBareNames)).map(t => t.value);
|
|
82
83
|
if (reads.wasCutShort)
|
|
@@ -92,7 +93,7 @@ export class CompletionSource {
|
|
|
92
93
|
});
|
|
93
94
|
}
|
|
94
95
|
async findMissingPowerShellAsync(shell, program, names, shellNames, environment) {
|
|
95
|
-
if (shellNames
|
|
96
|
+
if (Object.isNull(shellNames)) {
|
|
96
97
|
const reason = shell.isPathReset ? Resources.powerShellLookupPathReset : shell.isModulePathReset ? Resources.powerShellLookupModulePathReset
|
|
97
98
|
: shell.isNamesReset ? Resources.powerShellLookupNamesTooLong : Resources.powerShellLookupNamesUnreported;
|
|
98
99
|
if (this.skipped.get(shell) !== reason)
|
|
@@ -104,11 +105,11 @@ export class CompletionSource {
|
|
|
104
105
|
const variables = await this.toLongModulePathsAsync(Object.fromEntries([Resources.pathVariable,
|
|
105
106
|
Resources.pathExtensionsVariable, Resources.modulePathVariable].flatMap(t => {
|
|
106
107
|
const value = this.readVariable(environment, this.isWindows ? t.toUpperCase() : t);
|
|
107
|
-
return value
|
|
108
|
+
return Object.isUndefined(value) ? [] : [[t, value]];
|
|
108
109
|
})));
|
|
109
110
|
const search = JSON.stringify([program, variables]);
|
|
110
111
|
const last = this.looked.get(shell);
|
|
111
|
-
const answers = last
|
|
112
|
+
const answers = !Object.isUndefined(last) && last.shellNames === shellNames && last.search === search ? last.answers : new Map();
|
|
112
113
|
this.looked.set(shell, new PowerShellLookup(shellNames, search, answers));
|
|
113
114
|
const known = new Set([...shellNames].map(t => t.toLowerCase()));
|
|
114
115
|
const asked = [...new Set(names)].filter(t => !this.isPath(t) && Resources.powerShellLookupNamePattern.test(t)
|
|
@@ -142,7 +143,7 @@ export class CompletionSource {
|
|
|
142
143
|
}
|
|
143
144
|
async dropFoldersAsync(reads, kind, folder, environment, names) {
|
|
144
145
|
const workFolder = this.toLocalFolder(folder, kind, environment);
|
|
145
|
-
if (workFolder
|
|
146
|
+
if (Object.isNull(workFolder))
|
|
146
147
|
return names;
|
|
147
148
|
const folders = new Set((await reads.readEntriesAsync(workFolder)).filter(t => t.isFolder)
|
|
148
149
|
.map(t => this.isWindows ? t.name.toLowerCase() : t.name));
|
|
@@ -176,9 +177,12 @@ export class CompletionSource {
|
|
|
176
177
|
.filter(t => (ignoresCase ? t.value.toLowerCase() : t.value).startsWith(prefix));
|
|
177
178
|
const items = [...new Map(candidates.map(t => [t.value, t])).values()]
|
|
178
179
|
.sort((a, b) => a.label.localeCompare(b.label, Resources.sortLocale))
|
|
179
|
-
.
|
|
180
|
-
.
|
|
181
|
-
.
|
|
180
|
+
.flatMap(t => {
|
|
181
|
+
const text = ShellWords.write(t.value, shellLine.quote, isPowerShell, t.closesQuote, escapesWildcards && (t.kind === TerminalCompletionKind.File || t.kind === TerminalCompletionKind.Folder), keepsHome);
|
|
182
|
+
return text.length <= ProtocolResources.maximumPathLength && !ProtocolResources.controlCharacters.test(text)
|
|
183
|
+
? [new TerminalCompletionItem(text, t.label, t.kind)]
|
|
184
|
+
: [];
|
|
185
|
+
});
|
|
182
186
|
return new TerminalCompletion(shellLine.start, items.slice(0, ProtocolResources.maximumCompletionItems));
|
|
183
187
|
}
|
|
184
188
|
listAsync(reads, kind, builtins, shellLine, folder, environment, expandsHome) {
|
|
@@ -187,17 +191,17 @@ export class CompletionSource {
|
|
|
187
191
|
return this.listCommandsAsync(reads, builtins, environment);
|
|
188
192
|
const temporaryFolder = this.readVariable(environment, Resources.temporaryFolderVariable) ?? null;
|
|
189
193
|
const workFolder = this.toLocalPath(folder, kind, temporaryFolder);
|
|
190
|
-
if (workFolder
|
|
194
|
+
if (!Object.isNull(workFolder) && words.length === Resources.subcommandWordCount && words[0] === Resources.gitCommand && Resources.gitBranchCommands.some(t => shellLine.words[1] === t))
|
|
191
195
|
return this.listBranchesAsync(reads, workFolder, environment);
|
|
192
|
-
if (workFolder
|
|
196
|
+
if (!Object.isNull(workFolder) && words.length === Resources.subcommandWordCount && words[0] === Resources.npmCommand && Resources.npmRunCommands.some(t => shellLine.words[1] === t))
|
|
193
197
|
return this.listScriptsAsync(reads, workFolder);
|
|
194
198
|
return this.listPathsAsync(reads, kind, shellLine.value, workFolder, expandsHome, temporaryFolder);
|
|
195
199
|
}
|
|
196
200
|
async listPathsAsync(reads, kind, value, workFolder, expandsHome, temporaryFolder) {
|
|
197
201
|
const end = Math.max(value.lastIndexOf(Resources.posixSeparator), this.isWindows ? value.lastIndexOf(Resources.windowsSeparator) : -1);
|
|
198
202
|
const typedFolder = value.slice(0, end + 1);
|
|
199
|
-
const folder = workFolder
|
|
200
|
-
if (folder
|
|
203
|
+
const folder = Object.isNull(workFolder) ? null : this.toFolder(kind, typedFolder, workFolder, expandsHome, temporaryFolder);
|
|
204
|
+
if (Object.isNull(folder))
|
|
201
205
|
return [];
|
|
202
206
|
const separator = end >= 0 ? value.charAt(end)
|
|
203
207
|
: this.isWindows && kind === TerminalShellKind.PowerShell ? Resources.windowsSeparator : Resources.posixSeparator;
|
|
@@ -217,14 +221,14 @@ export class CompletionSource {
|
|
|
217
221
|
const names = [...builtins];
|
|
218
222
|
for (const entry of entries.flat()) {
|
|
219
223
|
const extension = this.paths.extname(entry.name).toLowerCase();
|
|
220
|
-
if (!entry.isFolder && (extensions
|
|
221
|
-
names.push(extensions
|
|
224
|
+
if (!entry.isFolder && (Object.isNull(extensions) || extensions.includes(extension) || takesBareNames && extension === ""))
|
|
225
|
+
names.push(Object.isNull(extensions) ? entry.name : entry.name.slice(0, entry.name.length - extension.length));
|
|
222
226
|
}
|
|
223
227
|
return names.map(t => new CompletionCandidate(t, t, TerminalCompletionKind.Command, true));
|
|
224
228
|
}
|
|
225
229
|
async listBranchesAsync(reads, folder, environment) {
|
|
226
230
|
const git = await this.findProgramAsync(reads, this.isWindows ? Resources.gitExecutableFile : Resources.gitCommand, environment);
|
|
227
|
-
if (git
|
|
231
|
+
if (Object.isNull(git))
|
|
228
232
|
return [];
|
|
229
233
|
let output;
|
|
230
234
|
try {
|
|
@@ -245,11 +249,11 @@ export class CompletionSource {
|
|
|
245
249
|
async listScriptsAsync(reads, folder) {
|
|
246
250
|
let current = folder;
|
|
247
251
|
let text = await reads.readTextOrNullAsync(this.paths.join(current, Resources.packageFile));
|
|
248
|
-
while (text
|
|
252
|
+
while (Object.isNull(text) && this.paths.dirname(current) !== current) {
|
|
249
253
|
current = this.paths.dirname(current);
|
|
250
254
|
text = await reads.readTextOrNullAsync(this.paths.join(current, Resources.packageFile));
|
|
251
255
|
}
|
|
252
|
-
if (text
|
|
256
|
+
if (Object.isNull(text))
|
|
253
257
|
return [];
|
|
254
258
|
let parsed;
|
|
255
259
|
try {
|
|
@@ -260,10 +264,10 @@ export class CompletionSource {
|
|
|
260
264
|
throw error;
|
|
261
265
|
return [];
|
|
262
266
|
}
|
|
263
|
-
if (
|
|
267
|
+
if (!Object.isObject(parsed) || !(Resources.packageScriptsField in parsed))
|
|
264
268
|
return [];
|
|
265
269
|
const scripts = parsed[Resources.packageScriptsField];
|
|
266
|
-
if (
|
|
270
|
+
if (!Object.isObject(scripts) || Array.isArray(scripts))
|
|
267
271
|
return [];
|
|
268
272
|
return Object.keys(scripts).map(t => new CompletionCandidate(t, t, TerminalCompletionKind.Script, true));
|
|
269
273
|
}
|
|
@@ -280,7 +284,7 @@ export class CompletionSource {
|
|
|
280
284
|
}
|
|
281
285
|
async toLongModulePathsAsync(variables) {
|
|
282
286
|
const modulePath = variables[Resources.modulePathVariable];
|
|
283
|
-
if (!this.isWindows || modulePath
|
|
287
|
+
if (!this.isWindows || Object.isUndefined(modulePath) || !modulePath.includes(Resources.shortNameMark))
|
|
284
288
|
return variables;
|
|
285
289
|
const reads = new BoundedReads(this.shared, Resources.completionReadMilliseconds);
|
|
286
290
|
try {
|
|
@@ -297,13 +301,13 @@ export class CompletionSource {
|
|
|
297
301
|
}
|
|
298
302
|
toFolder(kind, typedFolder, workFolder, expandsHome, temporaryFolder) {
|
|
299
303
|
const folder = expandsHome && this.isHome(typedFolder) ? this.paths.join(this.homeFolder, typedFolder.slice(Resources.homePrefix.length)) : this.toLocalPath(typedFolder, kind, temporaryFolder);
|
|
300
|
-
return folder
|
|
304
|
+
return Object.isNull(folder) ? null : this.paths.resolve(workFolder, folder);
|
|
301
305
|
}
|
|
302
306
|
toLocalPath(value, kind, temporaryFolder) {
|
|
303
307
|
if (!this.isWindows || kind !== TerminalShellKind.Bash || !value.startsWith(Resources.posixSeparator))
|
|
304
308
|
return value;
|
|
305
309
|
const temporary = Resources.gitBashTemporaryFolder;
|
|
306
|
-
if (temporaryFolder
|
|
310
|
+
if (!Object.isNull(temporaryFolder) && path.win32.isAbsolute(temporaryFolder)
|
|
307
311
|
&& (value === temporary || value.startsWith(`${temporary}${Resources.posixSeparator}`)))
|
|
308
312
|
return path.win32.join(temporaryFolder, value.slice(temporary.length));
|
|
309
313
|
if (!Resources.gitBashDrivePath.test(value))
|
|
@@ -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 { constants } from "node:os";
|
|
9
10
|
export class ContextPtyProcess {
|
|
10
11
|
terminal;
|
|
@@ -28,7 +29,7 @@ export class ContextPtyProcess {
|
|
|
28
29
|
isHolding = false;
|
|
29
30
|
else
|
|
30
31
|
queueMicrotask(() => {
|
|
31
|
-
for (let text = early.shift(); text
|
|
32
|
+
for (let text = early.shift(); !Object.isUndefined(text); text = early.shift())
|
|
32
33
|
if (isListening)
|
|
33
34
|
try {
|
|
34
35
|
listener(text);
|
|
@@ -74,6 +75,6 @@ export class ContextPtyProcess {
|
|
|
74
75
|
return this.terminal.stopAsync();
|
|
75
76
|
}
|
|
76
77
|
static toEvent(exit) {
|
|
77
|
-
return exit.signal
|
|
78
|
+
return Object.isNull(exit.signal) ? { exitCode: exit.code ?? undefined } : { exitCode: undefined, signal: constants.signals[exit.signal] };
|
|
78
79
|
}
|
|
79
80
|
}
|
|
@@ -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 { PseudoTerminalRequest } from "@noldova/desktop.runtime";
|
|
9
10
|
import { ContextPtyProcess } from "./context-pty-process.js";
|
|
10
11
|
export class ContextPtySpawner {
|
|
@@ -17,7 +18,7 @@ export class ContextPtySpawner {
|
|
|
17
18
|
async spawnAsync(file, args, folder, columns, rows, environment, inheritCursor) {
|
|
18
19
|
this.library ??= import("node-pty");
|
|
19
20
|
const library = await this.library;
|
|
20
|
-
const request =
|
|
21
|
+
const request = Object.isString(args)
|
|
21
22
|
? new PseudoTerminalRequest(library, file, [], folder, columns, rows, environment, { inheritCursor, commandLine: args })
|
|
22
23
|
: new PseudoTerminalRequest(library, file, args, folder, columns, rows, environment, { inheritCursor });
|
|
23
24
|
const terminal = await this.context.startPseudoTerminalAsync(request);
|
|
@@ -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
|
export class DeferredPtyProcess {
|
|
9
10
|
dataListeners = new Set();
|
|
10
11
|
exitListeners = new Set();
|
|
@@ -24,7 +25,7 @@ export class DeferredPtyProcess {
|
|
|
24
25
|
this.starting = undefined;
|
|
25
26
|
}
|
|
26
27
|
get hasStarted() {
|
|
27
|
-
return this.starting
|
|
28
|
+
return !Object.isUndefined(this.starting);
|
|
28
29
|
}
|
|
29
30
|
get pid() {
|
|
30
31
|
return this.process?.pid ?? null;
|
|
@@ -43,7 +44,7 @@ export class DeferredPtyProcess {
|
|
|
43
44
|
resize(columns, rows) {
|
|
44
45
|
this.columns = columns;
|
|
45
46
|
this.rows = rows;
|
|
46
|
-
if (this.process
|
|
47
|
+
if (Object.isUndefined(this.process))
|
|
47
48
|
this.start();
|
|
48
49
|
else
|
|
49
50
|
this.process.resize(columns, rows);
|
|
@@ -62,15 +63,16 @@ export class DeferredPtyProcess {
|
|
|
62
63
|
async endAsync() {
|
|
63
64
|
this.isEnded = true;
|
|
64
65
|
await this.starting;
|
|
65
|
-
if (this.process
|
|
66
|
+
if (!Object.isUndefined(this.process))
|
|
66
67
|
return this.process.endAsync();
|
|
67
68
|
this.exit({ exitCode: undefined });
|
|
68
69
|
return true;
|
|
69
70
|
}
|
|
70
71
|
start() {
|
|
71
|
-
if (this.starting
|
|
72
|
+
if (!Object.isUndefined(this.starting) || this.isEnded)
|
|
72
73
|
return;
|
|
73
|
-
const
|
|
74
|
+
const columns = this.columns;
|
|
75
|
+
const rows = this.rows;
|
|
74
76
|
this.starting = this.startProcessAsync(columns, rows).then(process => {
|
|
75
77
|
process.onData(t => {
|
|
76
78
|
for (const listener of this.dataListeners)
|
|
@@ -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 { EscapeState } from "../enums/escape-state.js";
|
|
9
10
|
import { Resources } from "../resources.js";
|
|
10
11
|
export class EscapeSequenceTracker {
|
|
@@ -34,7 +35,7 @@ export class EscapeSequenceTracker {
|
|
|
34
35
|
}
|
|
35
36
|
findNext(data, start) {
|
|
36
37
|
const search = EscapeSequenceTracker.searchOf(this.state);
|
|
37
|
-
if (search
|
|
38
|
+
if (Object.isNull(search))
|
|
38
39
|
return start;
|
|
39
40
|
search.lastIndex = start;
|
|
40
41
|
return search.exec(data)?.index ?? data.length;
|
|
@@ -5,11 +5,12 @@
|
|
|
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
|
export class FailureText {
|
|
10
11
|
static read(error) {
|
|
11
12
|
if (!(error instanceof Error))
|
|
12
13
|
return String(error);
|
|
13
|
-
return error.cause
|
|
14
|
+
return Object.isUndefined(error.cause) ? error.message : Resources.formatFailureWithCause(error.message, FailureText.read(error.cause));
|
|
14
15
|
}
|
|
15
16
|
}
|
|
@@ -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 { PaneProgress } from "../models/pane-progress.js";
|
|
9
10
|
import { Resources } from "../resources.js";
|
|
10
11
|
export class FlowController {
|
|
@@ -40,21 +41,21 @@ export class FlowController {
|
|
|
40
41
|
}
|
|
41
42
|
acknowledge(paneId, offset) {
|
|
42
43
|
const pane = this.panes.get(paneId);
|
|
43
|
-
if (pane
|
|
44
|
+
if (Object.isUndefined(pane))
|
|
44
45
|
return;
|
|
45
46
|
pane.offset = Math.max(pane.offset, Math.min(offset, this.producedOffset));
|
|
46
47
|
this.update();
|
|
47
48
|
}
|
|
48
49
|
setVisible(paneId, isVisible) {
|
|
49
50
|
const pane = this.panes.get(paneId);
|
|
50
|
-
if (pane
|
|
51
|
+
if (Object.isUndefined(pane))
|
|
51
52
|
return;
|
|
52
53
|
pane.isVisible = isVisible;
|
|
53
54
|
this.update();
|
|
54
55
|
}
|
|
55
56
|
detach(paneId) {
|
|
56
57
|
const pane = this.panes.get(paneId);
|
|
57
|
-
if (pane
|
|
58
|
+
if (Object.isUndefined(pane))
|
|
58
59
|
return false;
|
|
59
60
|
FlowController.stopStallTimer(pane);
|
|
60
61
|
this.panes.delete(paneId);
|
|
@@ -94,7 +95,7 @@ export class FlowController {
|
|
|
94
95
|
this.listener.onStalled(paneId);
|
|
95
96
|
}
|
|
96
97
|
static stopStallTimer(pane) {
|
|
97
|
-
if (pane.stallTimer
|
|
98
|
+
if (Object.isNull(pane.stallTimer))
|
|
98
99
|
return;
|
|
99
100
|
clearTimeout(pane.stallTimer);
|
|
100
101
|
pane.stallTimer = null;
|
|
@@ -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
|
export class LatestEnvironment {
|
|
9
10
|
source;
|
|
10
11
|
inherited;
|
|
@@ -17,7 +18,7 @@ export class LatestEnvironment {
|
|
|
17
18
|
}
|
|
18
19
|
async readAsync() {
|
|
19
20
|
const environment = await this.source.readAsync();
|
|
20
|
-
if (environment
|
|
21
|
+
if (Object.isNull(environment))
|
|
21
22
|
return this.inherited;
|
|
22
23
|
this.latest = environment;
|
|
23
24
|
return environment;
|
|
@@ -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 { posix } from "node:path";
|
|
9
10
|
import { Resources } from "../resources.js";
|
|
10
11
|
import { FileSystemReader } from "./file-system.reader.js";
|
|
@@ -63,8 +64,8 @@ export class MacEnvironment {
|
|
|
63
64
|
}
|
|
64
65
|
async withUtf8LocaleAsync(locale) {
|
|
65
66
|
const maximized = new Intl.Locale(locale).maximize();
|
|
66
|
-
const name = maximized.region
|
|
67
|
-
return name
|
|
67
|
+
const name = Object.isUndefined(maximized.region) ? null : Resources.formatUtf8Locale(maximized.language, maximized.region);
|
|
68
|
+
return !Object.isNull(name) && await this.hasLocaleAsync(name)
|
|
68
69
|
? { ...this.environment, [Resources.languageVariable]: name }
|
|
69
70
|
: { ...this.environment, [Resources.characterTypeVariable]: Resources.utf8Locale };
|
|
70
71
|
}
|
|
@@ -5,7 +5,10 @@
|
|
|
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 { MarkKind } from "../enums/mark-kind.js";
|
|
10
|
+
import { MarkIntroducer } from "../models/mark-introducer.js";
|
|
11
|
+
import { MarkTerminator } from "../models/mark-terminator.js";
|
|
9
12
|
import { ShellMark } from "../models/shell-mark.js";
|
|
10
13
|
import { Resources } from "../resources.js";
|
|
11
14
|
const INTRODUCERS = [Resources.markIntroducer, Resources.eightBitMarkIntroducer];
|
|
@@ -25,13 +28,16 @@ export class MarkScanner {
|
|
|
25
28
|
this.carry = "";
|
|
26
29
|
let index = 0;
|
|
27
30
|
while (index < text.length) {
|
|
28
|
-
const
|
|
31
|
+
const introducer = MarkScanner.findIntroducer(text, index);
|
|
32
|
+
const start = introducer.start;
|
|
29
33
|
if (start < 0) {
|
|
30
34
|
this.carry = MarkScanner.toIntroducerPrefix(text, index);
|
|
31
35
|
break;
|
|
32
36
|
}
|
|
33
|
-
const payloadStart = start + introducer.length;
|
|
34
|
-
const
|
|
37
|
+
const payloadStart = start + introducer.text.length;
|
|
38
|
+
const terminator = MarkScanner.findTerminator(text, payloadStart);
|
|
39
|
+
const payloadEnd = terminator.payloadEnd;
|
|
40
|
+
const end = terminator.end;
|
|
35
41
|
if (payloadEnd < 0) {
|
|
36
42
|
this.carry = text.length - start <= Resources.maximumMarkLength ? text.slice(start) : MarkScanner.toIntroducerPrefix(text, payloadStart);
|
|
37
43
|
break;
|
|
@@ -45,7 +51,7 @@ export class MarkScanner {
|
|
|
45
51
|
continue;
|
|
46
52
|
}
|
|
47
53
|
const mark = this.parse(text.slice(payloadStart, payloadEnd), textOffset + end);
|
|
48
|
-
if (mark
|
|
54
|
+
if (!Object.isNull(mark))
|
|
49
55
|
marks.push(mark);
|
|
50
56
|
index = end;
|
|
51
57
|
}
|
|
@@ -54,7 +60,7 @@ export class MarkScanner {
|
|
|
54
60
|
parse(payload, offset) {
|
|
55
61
|
const [kindText, nonce, ...values] = payload.replace(Resources.markScannerIgnoredControl, "").split(Resources.markScannerFieldSeparator);
|
|
56
62
|
const kind = Resources.markKindLetters.get(String(kindText));
|
|
57
|
-
if (kind
|
|
63
|
+
if (Object.isUndefined(kind) || nonce !== this.nonce)
|
|
58
64
|
return null;
|
|
59
65
|
const fields = values.map(t => t.replace(Resources.markScannerEscapedCharacter, (_, code) => String.fromCharCode(Number.parseInt(code, Resources.hexadecimalRadix))));
|
|
60
66
|
return new ShellMark(kind, fields.length === 0 ? null : fields.join(Resources.markScannerFieldSeparator), offset, fields);
|
|
@@ -62,24 +68,26 @@ export class MarkScanner {
|
|
|
62
68
|
static findTerminator(text, from) {
|
|
63
69
|
for (let index = from; index < text.length; index++) {
|
|
64
70
|
const terminator = TERMINATORS.find(t => text.startsWith(t, index));
|
|
65
|
-
if (terminator
|
|
66
|
-
return
|
|
71
|
+
if (!Object.isUndefined(terminator))
|
|
72
|
+
return new MarkTerminator(index, index + terminator.length);
|
|
67
73
|
if (CANCELS.some(t => text.startsWith(t, index)))
|
|
68
|
-
return
|
|
74
|
+
return new MarkTerminator(index, -1);
|
|
69
75
|
if (!text.startsWith(Resources.escape, index))
|
|
70
76
|
continue;
|
|
71
77
|
if (index + Resources.escape.length === text.length)
|
|
72
|
-
return
|
|
73
|
-
return text.startsWith(Resources.stringTerminator, index)
|
|
78
|
+
return new MarkTerminator(-1, -1);
|
|
79
|
+
return text.startsWith(Resources.stringTerminator, index)
|
|
80
|
+
? new MarkTerminator(index, index + Resources.stringTerminator.length)
|
|
81
|
+
: new MarkTerminator(index, -1);
|
|
74
82
|
}
|
|
75
|
-
return
|
|
83
|
+
return new MarkTerminator(-1, -1);
|
|
76
84
|
}
|
|
77
85
|
static findIntroducer(text, from) {
|
|
78
|
-
let found =
|
|
86
|
+
let found = new MarkIntroducer(-1, "");
|
|
79
87
|
for (const introducer of INTRODUCERS) {
|
|
80
88
|
const start = text.indexOf(introducer, from);
|
|
81
|
-
if (start >= 0 && (found
|
|
82
|
-
found =
|
|
89
|
+
if (start >= 0 && (found.start < 0 || start < found.start))
|
|
90
|
+
found = new MarkIntroducer(start, introducer);
|
|
83
91
|
}
|
|
84
92
|
return found;
|
|
85
93
|
}
|
|
@@ -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 path from "node:path";
|
|
9
10
|
import { TerminalShellKind, TerminalSize } from "@noldova/terminal.protocol";
|
|
10
11
|
import { OneShotLaunch } from "../models/one-shot-launch.js";
|
|
@@ -62,7 +63,7 @@ export class OneShotCommand {
|
|
|
62
63
|
}
|
|
63
64
|
async endAsync() {
|
|
64
65
|
await this.started;
|
|
65
|
-
if (this.terminal
|
|
66
|
+
if (!Object.isNull(this.terminal) && !this.hasEnded)
|
|
66
67
|
await this.terminal.endAsync();
|
|
67
68
|
}
|
|
68
69
|
interrupt() {
|
|
@@ -80,7 +81,7 @@ export class OneShotCommand {
|
|
|
80
81
|
return OneShotCommand.toCmdLaunch(shell, command);
|
|
81
82
|
case Resources.pwshExecutable:
|
|
82
83
|
case Resources.windowsPowerShellExecutable:
|
|
83
|
-
return new OneShotLaunch(shell.file, [...Resources.powerShellOneShotArguments, shell.startCommand
|
|
84
|
+
return new OneShotLaunch(shell.file, [...Resources.powerShellOneShotArguments, Object.isNull(shell.startCommand) ? command : `${shell.startCommand}${Resources.lineFeed}${command}`]);
|
|
84
85
|
default:
|
|
85
86
|
return new OneShotLaunch(shell.file, [...Resources.posixOneShotArguments, command]);
|
|
86
87
|
}
|
|
@@ -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 { TerminalInputMark } from "@noldova/terminal.protocol";
|
|
9
10
|
import { Resources } from "../resources.js";
|
|
10
11
|
export class OutputBatcher {
|
|
@@ -49,7 +50,7 @@ export class OutputBatcher {
|
|
|
49
50
|
this.cancelTimer();
|
|
50
51
|
}
|
|
51
52
|
cancelTimer() {
|
|
52
|
-
if (this.timer
|
|
53
|
+
if (Object.isNull(this.timer))
|
|
53
54
|
return;
|
|
54
55
|
clearTimeout(this.timer);
|
|
55
56
|
this.timer = null;
|
|
@@ -41,7 +41,10 @@ export class OutputLog {
|
|
|
41
41
|
return this.text.slice(Math.max(start - this.startOffset, 0), Math.max(end - this.startOffset, 0));
|
|
42
42
|
}
|
|
43
43
|
readSince(offset) {
|
|
44
|
-
return
|
|
44
|
+
return this.readChunk(offset, this.endOffset);
|
|
45
|
+
}
|
|
46
|
+
readChunk(start, end) {
|
|
47
|
+
return new OutputChunk(this.readRange(start, end), end, Math.max(Math.min(this.startOffset, end) - start, 0));
|
|
45
48
|
}
|
|
46
49
|
subscribe(listener) {
|
|
47
50
|
this.listeners.add(listener);
|
|
@@ -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
|
export class PowerShellBinding {
|
|
10
11
|
isWindows;
|
|
@@ -13,11 +14,11 @@ export class PowerShellBinding {
|
|
|
13
14
|
}
|
|
14
15
|
bindsWildcardPath(words) {
|
|
15
16
|
const [command, ...rest] = words.map(t => t.toLowerCase());
|
|
16
|
-
if (command
|
|
17
|
+
if (Object.isUndefined(command))
|
|
17
18
|
return false;
|
|
18
19
|
const cmdlet = Resources.powerShellPathCmdlets
|
|
19
20
|
.find(t => t.names.includes(command) || (this.isWindows && t.windowsAliases.includes(command)));
|
|
20
|
-
if (cmdlet
|
|
21
|
+
if (Object.isUndefined(cmdlet))
|
|
21
22
|
return false;
|
|
22
23
|
const parameters = [...cmdlet.parameters, ...Resources.powerShellCommonParameters];
|
|
23
24
|
const named = [];
|
|
@@ -25,7 +26,7 @@ export class PowerShellBinding {
|
|
|
25
26
|
let positional = 0;
|
|
26
27
|
let ended = false;
|
|
27
28
|
for (const word of rest) {
|
|
28
|
-
if (pending
|
|
29
|
+
if (!Object.isNull(pending)) {
|
|
29
30
|
named.push(pending.slot);
|
|
30
31
|
pending = null;
|
|
31
32
|
continue;
|
|
@@ -43,19 +44,19 @@ export class PowerShellBinding {
|
|
|
43
44
|
const fixed = this.matches(parameters, name);
|
|
44
45
|
const found = fixed.length > 0 ? fixed : this.matches(cmdlet.dynamicParameters, name);
|
|
45
46
|
const parameter = found.length === 1 ? found.at(0) : undefined;
|
|
46
|
-
if (parameter
|
|
47
|
+
if (Object.isUndefined(parameter))
|
|
47
48
|
return false;
|
|
48
49
|
if (separator >= 0 || parameter.isSwitch)
|
|
49
50
|
named.push(parameter.slot);
|
|
50
51
|
else
|
|
51
52
|
pending = parameter;
|
|
52
53
|
}
|
|
53
|
-
if (pending
|
|
54
|
+
if (!Object.isNull(pending))
|
|
54
55
|
return pending.name === Resources.powerShellPathParameter;
|
|
55
56
|
return cmdlet.positions.filter(t => !named.includes(t)).at(positional) === Resources.powerShellPathParameter;
|
|
56
57
|
}
|
|
57
58
|
matches(parameters, name) {
|
|
58
59
|
const exact = parameters.find(t => t.name === name || t.aliases.includes(name));
|
|
59
|
-
return exact
|
|
60
|
+
return !Object.isUndefined(exact) ? [exact] : parameters.filter(t => [t.name, ...t.aliases].some(n => n.startsWith(name)));
|
|
60
61
|
}
|
|
61
62
|
}
|
|
@@ -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
|
export class PseudoTerminal {
|
|
10
11
|
process;
|
|
@@ -39,6 +40,9 @@ export class PseudoTerminal {
|
|
|
39
40
|
get pid() {
|
|
40
41
|
return this.process.pid;
|
|
41
42
|
}
|
|
43
|
+
get isHoldingKeys() {
|
|
44
|
+
return this.openRequests > 0;
|
|
45
|
+
}
|
|
42
46
|
write(data) {
|
|
43
47
|
if (this.hasExited)
|
|
44
48
|
return;
|
|
@@ -107,10 +111,12 @@ export class PseudoTerminal {
|
|
|
107
111
|
this.answerLimit = undefined;
|
|
108
112
|
this.openRequests = 0;
|
|
109
113
|
this.isResizeAsking = false;
|
|
114
|
+
if (this.heldKeys.length > 0)
|
|
115
|
+
this.listener.onReleasingKeys?.();
|
|
110
116
|
for (const key of this.heldKeys.splice(0))
|
|
111
117
|
this.write(key);
|
|
112
118
|
}
|
|
113
119
|
static toExitCode(event) {
|
|
114
|
-
return event.signal
|
|
120
|
+
return Object.isUndefined(event.signal) || event.signal === 0 ? event.exitCode ?? null : null;
|
|
115
121
|
}
|
|
116
122
|
}
|