@noldova/terminal 0.0.0-stage → 0.0.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/LICENSE +21 -0
- package/README.md +10 -2
- package/menus.json +53 -0
- package/module.json +28 -0
- package/package.json +50 -4
- package/settings.json +83 -0
- package/src/api/index.d.ts +131 -0
- package/src/api/index.js +11 -0
- package/src/api/window.d.ts +467 -0
- package/src/api/window.js +8 -0
- package/src/enums/escape-state.js +15 -0
- package/src/enums/escape-stripper-state.js +15 -0
- package/src/enums/mark-kind.js +18 -0
- package/src/enums/shell-family.js +14 -0
- package/src/enums/system-requirement.js +11 -0
- package/src/exceptions/agent-terminal-restart.exception.js +16 -0
- package/src/exceptions/command-exited.exception.js +23 -0
- package/src/exceptions/command-failed.exception.js +13 -0
- package/src/exceptions/command-not-started.exception.js +17 -0
- package/src/exceptions/command-output-too-long.exception.js +18 -0
- package/src/exceptions/command-timed-out.exception.js +18 -0
- package/src/exceptions/command-variable-not-set.exception.js +18 -0
- package/src/exceptions/default-shell-not-found.exception.js +14 -0
- package/src/exceptions/environment-export-invalid.exception.js +14 -0
- package/src/exceptions/environment-key-unreadable.exception.js +17 -0
- package/src/exceptions/environment-unreadable.exception.js +13 -0
- package/src/exceptions/folder-not-found.exception.js +16 -0
- package/src/exceptions/host-ended.exception.js +14 -0
- package/src/exceptions/session-not-found.exception.js +18 -0
- package/src/exceptions/shell-kind-not-found.exception.js +16 -0
- package/src/exceptions/shell-not-found.exception.js +18 -0
- package/src/exceptions/shells-unreadable.exception.js +13 -0
- package/src/exceptions/stored-lines-damaged.exception.js +15 -0
- package/src/exceptions/stored-lines-unwritable.exception.js +15 -0
- package/src/exceptions/system-root-missing.exception.js +14 -0
- package/src/exceptions/terminal.exception.js +13 -0
- package/src/exceptions/unknown-method.exception.js +16 -0
- package/src/exceptions/unsupported-system.exception.js +18 -0
- package/src/exceptions/visual-studio-unreadable.exception.js +15 -0
- package/src/exceptions/wsl-distributions-unreadable.exception.js +15 -0
- package/src/interfaces/i-command-runner.js +8 -0
- package/src/interfaces/i-disposable.js +8 -0
- package/src/interfaces/i-environment-source.js +8 -0
- package/src/interfaces/i-file-system-reader.js +8 -0
- package/src/interfaces/i-file-system-writer.js +8 -0
- package/src/interfaces/i-flow-controller-listener.js +8 -0
- package/src/interfaces/i-folder-access.js +8 -0
- package/src/interfaces/i-line-process-listener.js +8 -0
- package/src/interfaces/i-line-process-starter.js +8 -0
- package/src/interfaces/i-line-process.js +8 -0
- package/src/interfaces/i-output-batcher-listener.js +8 -0
- package/src/interfaces/i-process-signaller.js +8 -0
- package/src/interfaces/i-pseudo-terminal-listener.js +8 -0
- package/src/interfaces/i-pty-exit-event.js +8 -0
- package/src/interfaces/i-pty-process.js +8 -0
- package/src/interfaces/i-pty-spawner.js +8 -0
- package/src/interfaces/i-terminal-mirror-listener.js +8 -0
- package/src/interfaces/i-terminal-session-listener.js +8 -0
- package/src/interfaces/i-waiting-options-request.js +8 -0
- package/src/models/command-listing.js +17 -0
- package/src/models/completion-candidate.js +19 -0
- package/src/models/environment-tools.js +23 -0
- package/src/models/environment-variable.js +15 -0
- package/src/models/folder-entry.js +15 -0
- package/src/models/hosted-terminal.js +116 -0
- package/src/models/mirror-line.js +27 -0
- package/src/models/mirror-snapshot.js +19 -0
- package/src/models/one-shot-launch.js +42 -0
- package/src/models/pane-progress.js +15 -0
- package/src/models/powershell-cmdlet.js +21 -0
- package/src/models/powershell-lookup.js +17 -0
- package/src/models/powershell-parameter.js +19 -0
- package/src/models/registry-value.js +15 -0
- package/src/models/request-client.js +23 -0
- package/src/models/saved-terminal.js +25 -0
- package/src/models/shell-launch.js +23 -0
- package/src/models/shell-line.js +21 -0
- package/src/models/shell-mark.js +19 -0
- package/src/models/shell-options-reply.js +17 -0
- package/src/models/shell.js +29 -0
- package/src/models/started-shell.js +21 -0
- package/src/models/system-shortfall.js +15 -0
- package/src/models/terminal-events.js +37 -0
- package/src/models/terminal-history-paths.js +15 -0
- package/src/models/terminal-prompt.js +28 -0
- package/src/models/tracked-command.js +26 -0
- package/src/models/typed-line.js +40 -0
- package/src/models/visual-studio-installation.js +22 -0
- package/src/models/waiting-run.js +25 -0
- package/src/resources.js +1725 -0
- package/src/runtime-part.js +84 -0
- package/src/services/agent-terminal.js +137 -0
- package/src/services/agent-terminals.js +55 -0
- package/src/services/bounded-reads.js +57 -0
- package/src/services/change-signal.js +33 -0
- package/src/services/command-history.js +20 -0
- package/src/services/command-runner.js +67 -0
- package/src/services/command-tracker.js +161 -0
- package/src/services/completion-source.js +316 -0
- package/src/services/context-pty-process.js +79 -0
- package/src/services/context-pty-spawner.js +26 -0
- package/src/services/deferred-pty-process.js +94 -0
- package/src/services/escape-sequence-tracker.js +126 -0
- package/src/services/escape-stripper.js +91 -0
- package/src/services/failure-text.js +15 -0
- package/src/services/file-system-writer.js +35 -0
- package/src/services/file-system.reader.js +54 -0
- package/src/services/flow-controller.js +102 -0
- package/src/services/folder-access.js +19 -0
- package/src/services/inherited-environment.js +20 -0
- package/src/services/line-process-starter.js +17 -0
- package/src/services/line-process.js +72 -0
- package/src/services/log-file.js +57 -0
- package/src/services/mac-environment.js +81 -0
- package/src/services/mac-folder-access.js +17 -0
- package/src/services/mark-scanner.js +94 -0
- package/src/services/one-shot-command.js +119 -0
- package/src/services/output-batcher.js +62 -0
- package/src/services/output-log.js +50 -0
- package/src/services/powershell-binding.js +61 -0
- package/src/services/process-signaller.js +19 -0
- package/src/services/pseudo-terminal.js +54 -0
- package/src/services/registry-export.js +108 -0
- package/src/services/resize-wakeup.js +39 -0
- package/src/services/saved-terminals.js +52 -0
- package/src/services/shared-reads.js +41 -0
- package/src/services/shell-command.js +90 -0
- package/src/services/shell-environment.js +20 -0
- package/src/services/shell-integration.js +207 -0
- package/src/services/shell-locator.js +177 -0
- package/src/services/shell-options-queue.js +34 -0
- package/src/services/shell-words.js +80 -0
- package/src/services/system-requirements.js +46 -0
- package/src/services/terminal-audience.js +83 -0
- package/src/services/terminal-history-folder.js +97 -0
- package/src/services/terminal-history-segment.js +109 -0
- package/src/services/terminal-history.js +130 -0
- package/src/services/terminal-host.js +931 -0
- package/src/services/terminal-line-reader.js +101 -0
- package/src/services/terminal-mirror.js +221 -0
- package/src/services/terminal-owner.service.js +27 -0
- package/src/services/terminal-session.js +398 -0
- package/src/services/visual-studio.reader.js +76 -0
- package/src/services/windows-environment.js +218 -0
- package/src/services/windows-folder-access.js +23 -0
- package/src/services/wsl-distribution.reader.js +49 -0
- package/src/services/xterm-headless-loader.js +14 -0
- package/src/tools/enums/command-status.js +13 -0
- package/src/tools/enums/run-method.js +11 -0
- package/src/tools/exceptions/abort-reason-unknown.exception.js +17 -0
- package/src/tools/exceptions/stale-terminal.exception.js +16 -0
- package/src/tools/interfaces/i-agent-command.js +8 -0
- package/src/tools/interfaces/i-agent-terminal.js +8 -0
- package/src/tools/interfaces/i-agent-terminals.js +8 -0
- package/src/tools/interfaces/i-output-source.js +8 -0
- package/src/tools/interfaces/i-terminal-prompt.js +8 -0
- package/src/tools/models/agent-terminal-access.js +25 -0
- package/src/tools/models/agent-terminal-opening.js +29 -0
- package/src/tools/models/command-line.js +28 -0
- package/src/tools/models/key-sequence.js +27 -0
- package/src/tools/models/output-chunk.js +18 -0
- package/src/tools/models/output-excerpt.js +31 -0
- package/src/tools/models/permission-ask.js +34 -0
- package/src/tools/models/read-cursor.js +26 -0
- package/src/tools/models/read-cursors.js +25 -0
- package/src/tools/models/terminal-open-input.js +34 -0
- package/src/tools/models/terminal-output-report.js +61 -0
- package/src/tools/models/terminal-read-input.js +39 -0
- package/src/tools/models/terminal-run-input.js +52 -0
- package/src/tools/models/terminal-target-input.js +34 -0
- package/src/tools/models/terminal-write-input.js +38 -0
- package/src/tools/models/tool-call-context.js +61 -0
- package/src/tools/services/abort-reason-reader.js +25 -0
- package/src/tools/services/permission-details.js +42 -0
- package/src/tools/services/permission-gate.js +35 -0
- package/src/tools/services/signal-race.js +24 -0
- package/src/tools/services/terminal-access-policy.js +57 -0
- package/src/tools/services/terminal-close-tool.js +57 -0
- package/src/tools/services/terminal-interrupt-tool.js +57 -0
- package/src/tools/services/terminal-list-tool.js +69 -0
- package/src/tools/services/terminal-open-tool.js +71 -0
- package/src/tools/services/terminal-read-tool.js +58 -0
- package/src/tools/services/terminal-run-tool.js +78 -0
- package/src/tools/services/terminal-text-escaper.js +40 -0
- package/src/tools/services/terminal-tool.js +47 -0
- package/src/tools/services/terminal-tools.js +60 -0
- package/src/tools/services/terminal-write-tool.js +75 -0
- package/src/tools/services/tool-failures.js +28 -0
- package/src/tools/services/tool-results.js +13 -0
|
@@ -0,0 +1,316 @@
|
|
|
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
|
+
import path from "node:path";
|
|
9
|
+
import { Resources as ProtocolResources, TerminalCompletion, TerminalCompletionItem, TerminalCompletionKind, TerminalMissingCommands, TerminalShellKind } from "@noldova/terminal.protocol";
|
|
10
|
+
import { CommandFailedException } from "../exceptions/command-failed.exception.js";
|
|
11
|
+
import { CommandListing } from "../models/command-listing.js";
|
|
12
|
+
import { CompletionCandidate } from "../models/completion-candidate.js";
|
|
13
|
+
import { PowerShellLookup } from "../models/powershell-lookup.js";
|
|
14
|
+
import { ShellLine } from "../models/shell-line.js";
|
|
15
|
+
import { Resources } from "../resources.js";
|
|
16
|
+
import { BoundedReads } from "./bounded-reads.js";
|
|
17
|
+
import { FailureText } from "./failure-text.js";
|
|
18
|
+
import { PowerShellBinding } from "./powershell-binding.js";
|
|
19
|
+
import { SharedReads } from "./shared-reads.js";
|
|
20
|
+
import { ShellWords } from "./shell-words.js";
|
|
21
|
+
export class CompletionSource {
|
|
22
|
+
runner;
|
|
23
|
+
isWindows;
|
|
24
|
+
paths;
|
|
25
|
+
homeFolder;
|
|
26
|
+
binding;
|
|
27
|
+
shared;
|
|
28
|
+
stuck = [];
|
|
29
|
+
listed = new WeakMap();
|
|
30
|
+
looked = new WeakMap();
|
|
31
|
+
skipped = new WeakMap();
|
|
32
|
+
failing = new WeakSet();
|
|
33
|
+
log;
|
|
34
|
+
constructor(fileSystem, runner, platform, homeFolder, log) {
|
|
35
|
+
this.runner = runner;
|
|
36
|
+
this.log = log;
|
|
37
|
+
this.isWindows = platform === Resources.windowsPlatform;
|
|
38
|
+
this.paths = this.isWindows ? path.win32 : path.posix;
|
|
39
|
+
this.homeFolder = homeFolder;
|
|
40
|
+
this.binding = new PowerShellBinding(this.isWindows);
|
|
41
|
+
this.shared = new SharedReads(fileSystem);
|
|
42
|
+
}
|
|
43
|
+
async completeAsync(key, kind, line, cursor, folder, environment, shellNames, shellBuiltins) {
|
|
44
|
+
if (!Resources.completedShellKinds.includes(kind) || this.stuck.includes(key))
|
|
45
|
+
return new TerminalCompletion(cursor, []);
|
|
46
|
+
const builtins = kind === TerminalShellKind.PowerShell ? Resources.powerShellBuiltins
|
|
47
|
+
: [...new Set([...shellBuiltins ?? [], ...shellNames ?? []])]
|
|
48
|
+
.filter(t => !t.startsWith(Resources.helperNamePrefix) && t !== Resources.autocdName && !t.startsWith(Resources.suffixAliasNameStart));
|
|
49
|
+
return this.readAsync(key, t => this.completeLineAsync(t, kind, builtins, line.slice(0, cursor), folder, environment));
|
|
50
|
+
}
|
|
51
|
+
followsCommand(kind, line, cursor) {
|
|
52
|
+
return ShellWords.read(line.slice(0, cursor), kind === TerminalShellKind.PowerShell).words.length > 0;
|
|
53
|
+
}
|
|
54
|
+
addOptions(completion, kind, line, cursor, options) {
|
|
55
|
+
const ignoresCase = this.isWindows || kind === TerminalShellKind.PowerShell;
|
|
56
|
+
const toKey = (text) => ignoresCase ? text.toLowerCase() : text;
|
|
57
|
+
const prefix = toKey(line.slice(completion.replaceFrom, cursor));
|
|
58
|
+
const labels = new Set(completion.items.map(t => t.label));
|
|
59
|
+
const added = [...new Set(options)]
|
|
60
|
+
.filter(t => t.trim().length > 0 && t.length <= ProtocolResources.maximumPathLength && !labels.has(t) && toKey(t).startsWith(prefix))
|
|
61
|
+
.map(t => new TerminalCompletionItem(t, t, TerminalCompletionKind.Option));
|
|
62
|
+
if (added.length === 0)
|
|
63
|
+
return completion;
|
|
64
|
+
const items = [...completion.items, ...added].sort((a, b) => a.label.localeCompare(b.label, Resources.sortLocale));
|
|
65
|
+
return new TerminalCompletion(completion.replaceFrom, items.slice(0, ProtocolResources.maximumCompletionItems));
|
|
66
|
+
}
|
|
67
|
+
async findMissingAsync(key, shell, prompt, kind, folder, names, shellNames, environment) {
|
|
68
|
+
if (kind === TerminalShellKind.PowerShell || !Resources.completedShellKinds.includes(kind) || shellNames === null || this.stuck.includes(key))
|
|
69
|
+
return new TerminalMissingCommands([]);
|
|
70
|
+
const takesBareNames = this.isWindows && kind === TerminalShellKind.Bash;
|
|
71
|
+
const search = JSON.stringify([kind, this.readVariable(environment, Resources.pathVariable),
|
|
72
|
+
this.readVariable(environment, Resources.pathExtensionsVariable)]);
|
|
73
|
+
const last = this.listed.get(shell);
|
|
74
|
+
const listed = last !== undefined && last.prompt === prompt && last.search === search ? last.commands : null;
|
|
75
|
+
return this.readAsync(key, async (reads) => {
|
|
76
|
+
const commands = listed ?? (await this.listCommandsAsync(reads, [], environment, takesBareNames)).map(t => t.value);
|
|
77
|
+
if (reads.wasCutShort)
|
|
78
|
+
return new TerminalMissingCommands([]);
|
|
79
|
+
this.listed.set(shell, new CommandListing(prompt, search, commands));
|
|
80
|
+
const found = [...shellNames, ...commands];
|
|
81
|
+
const known = new Set(this.isWindows ? found.map(t => t.toLowerCase()) : found);
|
|
82
|
+
const unknown = names.filter(t => !this.isPath(t) && !t.startsWith(Resources.helperNamePrefix)
|
|
83
|
+
&& !known.has(this.toCommandName(t)) && !this.hasSuffixAlias(t, shellNames));
|
|
84
|
+
const missing = unknown.length > 0 && shellNames.has(Resources.autocdName)
|
|
85
|
+
? await this.dropFoldersAsync(reads, kind, folder, environment, unknown) : unknown;
|
|
86
|
+
return new TerminalMissingCommands(reads.wasCutShort ? [] : missing);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
async findMissingPowerShellAsync(shell, program, names, shellNames, environment) {
|
|
90
|
+
if (shellNames === null) {
|
|
91
|
+
const reason = shell.isPathReset ? Resources.powerShellLookupPathReset : shell.isModulePathReset ? Resources.powerShellLookupModulePathReset
|
|
92
|
+
: shell.isNamesReset ? Resources.powerShellLookupNamesTooLong : Resources.powerShellLookupNamesUnreported;
|
|
93
|
+
if (this.skipped.get(shell) !== reason)
|
|
94
|
+
this.log.write(Resources.formatPowerShellLookupSkipped(reason));
|
|
95
|
+
this.skipped.set(shell, reason);
|
|
96
|
+
return new TerminalMissingCommands([]);
|
|
97
|
+
}
|
|
98
|
+
this.skipped.delete(shell);
|
|
99
|
+
const variables = await this.toLongModulePathsAsync(Object.fromEntries([Resources.pathVariable,
|
|
100
|
+
Resources.pathExtensionsVariable, Resources.modulePathVariable].flatMap(t => {
|
|
101
|
+
const value = this.readVariable(environment, this.isWindows ? t.toUpperCase() : t);
|
|
102
|
+
return value === undefined ? [] : [[t, value]];
|
|
103
|
+
})));
|
|
104
|
+
const search = JSON.stringify([program, variables]);
|
|
105
|
+
const last = this.looked.get(shell);
|
|
106
|
+
const answers = last !== undefined && last.shellNames === shellNames && last.search === search ? last.answers : new Map();
|
|
107
|
+
this.looked.set(shell, new PowerShellLookup(shellNames, search, answers));
|
|
108
|
+
const known = new Set([...shellNames].map(t => t.toLowerCase()));
|
|
109
|
+
const asked = [...new Set(names)].filter(t => !this.isPath(t) && Resources.powerShellLookupNamePattern.test(t)
|
|
110
|
+
&& !known.has(t.toLowerCase()) && !known.has(`${Resources.powerShellImplicitVerb}${t}`.toLowerCase()));
|
|
111
|
+
const unasked = asked.filter(t => !answers.has(t));
|
|
112
|
+
if (unasked.length > 0) {
|
|
113
|
+
try {
|
|
114
|
+
const output = await this.runner.runAsync(program, [...Resources.environmentReadArguments,
|
|
115
|
+
Buffer.from(Resources.formatPowerShellLookupScript(unasked), Resources.utf16Encoding).toString(Resources.base64Encoding)], Resources.powerShellLookupMilliseconds, variables);
|
|
116
|
+
const missing = new Set(output.split(Resources.lineBreaks).map(t => t.trim()));
|
|
117
|
+
for (const [index, name] of unasked.entries())
|
|
118
|
+
answers.set(name, missing.has(String(index)));
|
|
119
|
+
this.failing.delete(shell);
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
if (!(error instanceof CommandFailedException))
|
|
123
|
+
throw error;
|
|
124
|
+
if (!this.failing.has(shell))
|
|
125
|
+
this.log.write(Resources.formatPowerShellLookupFailed(unasked.length, FailureText.read(error)));
|
|
126
|
+
this.failing.add(shell);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return new TerminalMissingCommands(asked.filter(t => answers.get(t) === true));
|
|
130
|
+
}
|
|
131
|
+
hasSuffixAlias(name, shellNames) {
|
|
132
|
+
const start = name.lastIndexOf(Resources.suffixStart);
|
|
133
|
+
return start > 0 && shellNames.has(`${Resources.suffixAliasNameStart}${name.slice(start + 1)}`);
|
|
134
|
+
}
|
|
135
|
+
async dropFoldersAsync(reads, kind, folder, environment, names) {
|
|
136
|
+
const workFolder = this.toLocalPath(folder, kind, this.readVariable(environment, Resources.temporaryFolderVariable) ?? null);
|
|
137
|
+
if (workFolder === null)
|
|
138
|
+
return names;
|
|
139
|
+
const folders = new Set((await reads.readEntriesAsync(workFolder)).filter(t => t.isFolder)
|
|
140
|
+
.map(t => this.isWindows ? t.name.toLowerCase() : t.name));
|
|
141
|
+
return names.filter(t => !folders.has(this.isWindows ? t.toLowerCase() : t));
|
|
142
|
+
}
|
|
143
|
+
async readAsync(key, list) {
|
|
144
|
+
const reads = new BoundedReads(this.shared, Resources.completionReadMilliseconds);
|
|
145
|
+
try {
|
|
146
|
+
return await list(reads);
|
|
147
|
+
}
|
|
148
|
+
finally {
|
|
149
|
+
reads.end();
|
|
150
|
+
for (const read of reads.listPendingReads()) {
|
|
151
|
+
this.stuck.push(key);
|
|
152
|
+
void Promise.allSettled([read]).then(() => this.stuck.splice(this.stuck.indexOf(key), 1));
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
async completeLineAsync(reads, kind, builtins, line, folder, environment) {
|
|
157
|
+
const isPowerShell = kind === TerminalShellKind.PowerShell;
|
|
158
|
+
const typed = ShellWords.read(line, isPowerShell);
|
|
159
|
+
const escapesWildcards = isPowerShell && this.binding.bindsWildcardPath(typed.words);
|
|
160
|
+
const shellLine = escapesWildcards
|
|
161
|
+
? new ShellLine(typed.words, typed.start, typed.value.replace(Resources.powerShellEscapedWildcards, Resources.completionSourceEscapedWildcardReplacement), typed.quote, typed.startsQuoted)
|
|
162
|
+
: typed;
|
|
163
|
+
const ignoresCase = this.isWindows || isPowerShell;
|
|
164
|
+
const prefix = ignoresCase ? shellLine.value.toLowerCase() : shellLine.value;
|
|
165
|
+
const expandsHome = isPowerShell || !shellLine.startsQuoted;
|
|
166
|
+
const keepsHome = expandsHome && this.isHome(shellLine.value);
|
|
167
|
+
const candidates = (await this.listAsync(reads, kind, builtins, shellLine, folder, environment, expandsHome))
|
|
168
|
+
.filter(t => (ignoresCase ? t.value.toLowerCase() : t.value).startsWith(prefix));
|
|
169
|
+
const items = [...new Map(candidates.map(t => [t.value, t])).values()]
|
|
170
|
+
.sort((a, b) => a.label.localeCompare(b.label, Resources.sortLocale))
|
|
171
|
+
.map((t) => [ShellWords.write(t.value, shellLine.quote, isPowerShell, t.closesQuote, escapesWildcards && (t.kind === TerminalCompletionKind.File || t.kind === TerminalCompletionKind.Folder), keepsHome), t])
|
|
172
|
+
.filter(([t]) => t.length <= ProtocolResources.maximumPathLength)
|
|
173
|
+
.map(([text, t]) => new TerminalCompletionItem(text, t.label, t.kind));
|
|
174
|
+
return new TerminalCompletion(shellLine.start, items.slice(0, ProtocolResources.maximumCompletionItems));
|
|
175
|
+
}
|
|
176
|
+
listAsync(reads, kind, builtins, shellLine, folder, environment, expandsHome) {
|
|
177
|
+
const words = shellLine.words.map(t => this.toCommandName(t));
|
|
178
|
+
if (words.length === 0 && !this.isPath(shellLine.value))
|
|
179
|
+
return this.listCommandsAsync(reads, builtins, environment);
|
|
180
|
+
const temporaryFolder = this.readVariable(environment, Resources.temporaryFolderVariable) ?? null;
|
|
181
|
+
const workFolder = this.toLocalPath(folder, kind, temporaryFolder);
|
|
182
|
+
if (workFolder !== null && words.length === Resources.subcommandWordCount && words[0] === Resources.gitCommand && Resources.gitBranchCommands.some(t => shellLine.words[1] === t))
|
|
183
|
+
return this.listBranchesAsync(reads, workFolder, environment);
|
|
184
|
+
if (workFolder !== null && words.length === Resources.subcommandWordCount && words[0] === Resources.npmCommand && Resources.npmRunCommands.some(t => shellLine.words[1] === t))
|
|
185
|
+
return this.listScriptsAsync(reads, workFolder);
|
|
186
|
+
return this.listPathsAsync(reads, kind, shellLine.value, workFolder, expandsHome, temporaryFolder);
|
|
187
|
+
}
|
|
188
|
+
async listPathsAsync(reads, kind, value, workFolder, expandsHome, temporaryFolder) {
|
|
189
|
+
const end = Math.max(value.lastIndexOf(Resources.posixSeparator), this.isWindows ? value.lastIndexOf(Resources.windowsSeparator) : -1);
|
|
190
|
+
const typedFolder = value.slice(0, end + 1);
|
|
191
|
+
const folder = workFolder === null ? null : this.toFolder(kind, typedFolder, workFolder, expandsHome, temporaryFolder);
|
|
192
|
+
if (folder === null)
|
|
193
|
+
return [];
|
|
194
|
+
const separator = end >= 0 ? value.charAt(end)
|
|
195
|
+
: this.isWindows && kind === TerminalShellKind.PowerShell ? Resources.windowsSeparator : Resources.posixSeparator;
|
|
196
|
+
const showsHidden = value.slice(end + 1).startsWith(Resources.hiddenPrefix);
|
|
197
|
+
return (await reads.readEntriesAsync(folder))
|
|
198
|
+
.filter(t => showsHidden || !t.name.startsWith(Resources.hiddenPrefix))
|
|
199
|
+
.map(t => t.isFolder
|
|
200
|
+
? new CompletionCandidate(`${typedFolder}${t.name}${separator}`, `${t.name}${separator}`, TerminalCompletionKind.Folder, false)
|
|
201
|
+
: new CompletionCandidate(`${typedFolder}${t.name}`, t.name, TerminalCompletionKind.File, true));
|
|
202
|
+
}
|
|
203
|
+
async listCommandsAsync(reads, builtins, environment, takesBareNames = false) {
|
|
204
|
+
const extensions = this.isWindows
|
|
205
|
+
? (this.readVariable(environment, Resources.pathExtensionsVariable) ?? Resources.defaultPathExtensions).toLowerCase()
|
|
206
|
+
.split(path.win32.delimiter).filter(t => t !== "")
|
|
207
|
+
: null;
|
|
208
|
+
const entries = await Promise.all(this.searchFolders(environment).map(t => reads.readEntriesAsync(t)));
|
|
209
|
+
const names = [...builtins];
|
|
210
|
+
for (const entry of entries.flat()) {
|
|
211
|
+
const extension = this.paths.extname(entry.name).toLowerCase();
|
|
212
|
+
if (!entry.isFolder && (extensions === null || extensions.includes(extension) || takesBareNames && extension === ""))
|
|
213
|
+
names.push(extensions === null ? entry.name : entry.name.slice(0, entry.name.length - extension.length));
|
|
214
|
+
}
|
|
215
|
+
return names.map(t => new CompletionCandidate(t, t, TerminalCompletionKind.Command, true));
|
|
216
|
+
}
|
|
217
|
+
async listBranchesAsync(reads, folder, environment) {
|
|
218
|
+
const git = await this.findProgramAsync(reads, this.isWindows ? Resources.gitExecutableFile : Resources.gitCommand, environment);
|
|
219
|
+
if (git === null)
|
|
220
|
+
return [];
|
|
221
|
+
let output;
|
|
222
|
+
try {
|
|
223
|
+
output = await this.runner.runAsync(git, [Resources.completionSourceGitFolderArgument, folder, ...Resources.gitBranchArguments], Resources.completionCommandMilliseconds);
|
|
224
|
+
}
|
|
225
|
+
catch (error) {
|
|
226
|
+
if (error instanceof CommandFailedException)
|
|
227
|
+
return [];
|
|
228
|
+
throw error;
|
|
229
|
+
}
|
|
230
|
+
return output.split(Resources.lineBreaks)
|
|
231
|
+
.filter(t => !t.endsWith(Resources.remoteHeadSuffix))
|
|
232
|
+
.map(t => t.startsWith(Resources.headsPrefix) ? t.slice(Resources.headsPrefix.length)
|
|
233
|
+
: t.startsWith(Resources.remotesPrefix) ? t.slice(Resources.remotesPrefix.length) : "")
|
|
234
|
+
.filter(t => t !== "")
|
|
235
|
+
.map(t => new CompletionCandidate(t, t, TerminalCompletionKind.Branch, true));
|
|
236
|
+
}
|
|
237
|
+
async listScriptsAsync(reads, folder) {
|
|
238
|
+
let current = folder;
|
|
239
|
+
let text = await reads.readTextOrNullAsync(this.paths.join(current, Resources.packageFile));
|
|
240
|
+
while (text === null && this.paths.dirname(current) !== current) {
|
|
241
|
+
current = this.paths.dirname(current);
|
|
242
|
+
text = await reads.readTextOrNullAsync(this.paths.join(current, Resources.packageFile));
|
|
243
|
+
}
|
|
244
|
+
if (text === null)
|
|
245
|
+
return [];
|
|
246
|
+
let parsed;
|
|
247
|
+
try {
|
|
248
|
+
parsed = JSON.parse(text);
|
|
249
|
+
}
|
|
250
|
+
catch (error) {
|
|
251
|
+
if (!(error instanceof SyntaxError))
|
|
252
|
+
throw error;
|
|
253
|
+
return [];
|
|
254
|
+
}
|
|
255
|
+
if (typeof parsed !== "object" || parsed === null || !(Resources.packageScriptsField in parsed))
|
|
256
|
+
return [];
|
|
257
|
+
const scripts = parsed[Resources.packageScriptsField];
|
|
258
|
+
if (typeof scripts !== "object" || scripts === null || Array.isArray(scripts))
|
|
259
|
+
return [];
|
|
260
|
+
return Object.keys(scripts).map(t => new CompletionCandidate(t, t, TerminalCompletionKind.Script, true));
|
|
261
|
+
}
|
|
262
|
+
async findProgramAsync(reads, name, environment) {
|
|
263
|
+
for (const folder of this.searchFolders(environment)) {
|
|
264
|
+
const file = this.paths.join(folder, name);
|
|
265
|
+
if (await reads.isProgramAsync(file))
|
|
266
|
+
return file;
|
|
267
|
+
}
|
|
268
|
+
return null;
|
|
269
|
+
}
|
|
270
|
+
searchFolders(environment) {
|
|
271
|
+
return [...new Set((this.readVariable(environment, Resources.pathVariable) ?? "").split(this.paths.delimiter).filter(t => this.paths.isAbsolute(t)))];
|
|
272
|
+
}
|
|
273
|
+
async toLongModulePathsAsync(variables) {
|
|
274
|
+
const modulePath = variables[Resources.modulePathVariable];
|
|
275
|
+
if (!this.isWindows || modulePath === undefined || !modulePath.includes(Resources.shortNameMark))
|
|
276
|
+
return variables;
|
|
277
|
+
const reads = new BoundedReads(this.shared, Resources.completionReadMilliseconds);
|
|
278
|
+
try {
|
|
279
|
+
const entries = await Promise.all(modulePath.split(Resources.windowsPathListSeparator)
|
|
280
|
+
.map(async (t) => t.includes(Resources.shortNameMark) ? await reads.readRealPathOrNullAsync(t) ?? t : t));
|
|
281
|
+
return { ...variables, [Resources.modulePathVariable]: entries.join(Resources.windowsPathListSeparator) };
|
|
282
|
+
}
|
|
283
|
+
finally {
|
|
284
|
+
reads.end();
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
readVariable(environment, name) {
|
|
288
|
+
return this.isWindows ? Object.entries(environment).find(([t]) => t.toUpperCase() === name)?.[1] : environment[name];
|
|
289
|
+
}
|
|
290
|
+
toFolder(kind, typedFolder, workFolder, expandsHome, temporaryFolder) {
|
|
291
|
+
const folder = expandsHome && this.isHome(typedFolder) ? this.paths.join(this.homeFolder, typedFolder.slice(Resources.homePrefix.length)) : this.toLocalPath(typedFolder, kind, temporaryFolder);
|
|
292
|
+
return folder === null ? null : this.paths.resolve(workFolder, folder);
|
|
293
|
+
}
|
|
294
|
+
toLocalPath(value, kind, temporaryFolder) {
|
|
295
|
+
if (!this.isWindows || kind !== TerminalShellKind.Bash || !value.startsWith(Resources.posixSeparator))
|
|
296
|
+
return value;
|
|
297
|
+
const temporary = Resources.gitBashTemporaryFolder;
|
|
298
|
+
if (temporaryFolder !== null && path.win32.isAbsolute(temporaryFolder)
|
|
299
|
+
&& (value === temporary || value.startsWith(`${temporary}${Resources.posixSeparator}`)))
|
|
300
|
+
return path.win32.join(temporaryFolder, value.slice(temporary.length));
|
|
301
|
+
if (!Resources.gitBashDrivePath.test(value))
|
|
302
|
+
return null;
|
|
303
|
+
return Resources.formatCompletionSourceWindowsDrivePath(value.charAt(1).toUpperCase(), value.slice(Resources.completionSourceGitBashDrivePrefixLength).replaceAll(Resources.posixSeparator, Resources.windowsSeparator));
|
|
304
|
+
}
|
|
305
|
+
toCommandName(word) {
|
|
306
|
+
const name = this.paths.basename(word);
|
|
307
|
+
return this.isWindows ? name.toLowerCase().replace(Resources.windowsProgramExtension, "") : name;
|
|
308
|
+
}
|
|
309
|
+
isHome(value) {
|
|
310
|
+
return value.startsWith(Resources.homePrefix) || (this.isWindows && value.startsWith(Resources.windowsHomePrefix));
|
|
311
|
+
}
|
|
312
|
+
isPath(value) {
|
|
313
|
+
return value.includes(Resources.posixSeparator) || (this.isWindows && value.includes(Resources.windowsSeparator))
|
|
314
|
+
|| value.startsWith(Resources.hiddenPrefix) || value.startsWith(Resources.homeWord);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
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
|
+
import { constants } from "node:os";
|
|
9
|
+
export class ContextPtyProcess {
|
|
10
|
+
terminal;
|
|
11
|
+
constructor(terminal) {
|
|
12
|
+
this.terminal = terminal;
|
|
13
|
+
}
|
|
14
|
+
get pid() {
|
|
15
|
+
return this.terminal.processId;
|
|
16
|
+
}
|
|
17
|
+
onData(listener) {
|
|
18
|
+
const early = [];
|
|
19
|
+
let isHolding = true;
|
|
20
|
+
let isListening = true;
|
|
21
|
+
const registration = this.terminal.onOutput(t => {
|
|
22
|
+
if (isHolding)
|
|
23
|
+
early.push(t);
|
|
24
|
+
else
|
|
25
|
+
listener(t);
|
|
26
|
+
});
|
|
27
|
+
if (early.length === 0)
|
|
28
|
+
isHolding = false;
|
|
29
|
+
else
|
|
30
|
+
queueMicrotask(() => {
|
|
31
|
+
for (let text = early.shift(); text !== undefined; text = early.shift())
|
|
32
|
+
if (isListening)
|
|
33
|
+
try {
|
|
34
|
+
listener(text);
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
queueMicrotask(() => {
|
|
38
|
+
throw error;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
isHolding = false;
|
|
42
|
+
});
|
|
43
|
+
return {
|
|
44
|
+
dispose: () => {
|
|
45
|
+
isListening = false;
|
|
46
|
+
registration[Symbol.dispose]();
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
onExit(listener) {
|
|
51
|
+
let isListening = true;
|
|
52
|
+
void this.terminal.exited.then(t => {
|
|
53
|
+
if (isListening)
|
|
54
|
+
listener(ContextPtyProcess.toEvent(t));
|
|
55
|
+
});
|
|
56
|
+
return { dispose: () => isListening = false };
|
|
57
|
+
}
|
|
58
|
+
write(data) {
|
|
59
|
+
this.terminal.write(data);
|
|
60
|
+
}
|
|
61
|
+
resize(columns, rows) {
|
|
62
|
+
this.terminal.resize(columns, rows);
|
|
63
|
+
}
|
|
64
|
+
readForegroundProcessGroupAsync() {
|
|
65
|
+
return this.terminal.readForegroundProcessGroupAsync();
|
|
66
|
+
}
|
|
67
|
+
pause() {
|
|
68
|
+
this.terminal.pause();
|
|
69
|
+
}
|
|
70
|
+
resume() {
|
|
71
|
+
this.terminal.resume();
|
|
72
|
+
}
|
|
73
|
+
endAsync() {
|
|
74
|
+
return this.terminal.stopAsync();
|
|
75
|
+
}
|
|
76
|
+
static toEvent(exit) {
|
|
77
|
+
return exit.signal === null ? { exitCode: exit.code ?? undefined } : { exitCode: undefined, signal: constants.signals[exit.signal] };
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
import { PseudoTerminalRequest } from "@noldova/desktop.runtime";
|
|
9
|
+
import { ContextPtyProcess } from "./context-pty-process.js";
|
|
10
|
+
export class ContextPtySpawner {
|
|
11
|
+
context;
|
|
12
|
+
library;
|
|
13
|
+
constructor(context) {
|
|
14
|
+
this.context = context;
|
|
15
|
+
this.library = undefined;
|
|
16
|
+
}
|
|
17
|
+
async spawnAsync(file, args, folder, columns, rows, environment, inheritCursor) {
|
|
18
|
+
this.library ??= import("node-pty");
|
|
19
|
+
const library = await this.library;
|
|
20
|
+
const request = typeof args === "string"
|
|
21
|
+
? new PseudoTerminalRequest(library, file, [], folder, columns, rows, environment, { inheritCursor, commandLine: args })
|
|
22
|
+
: new PseudoTerminalRequest(library, file, args, folder, columns, rows, environment, { inheritCursor });
|
|
23
|
+
const terminal = await this.context.startPseudoTerminalAsync(request);
|
|
24
|
+
return new ContextPtyProcess(terminal);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
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 DeferredPtyProcess {
|
|
9
|
+
dataListeners = new Set();
|
|
10
|
+
exitListeners = new Set();
|
|
11
|
+
startProcessAsync;
|
|
12
|
+
process;
|
|
13
|
+
starting;
|
|
14
|
+
columns;
|
|
15
|
+
rows;
|
|
16
|
+
isPaused = false;
|
|
17
|
+
isEnded = false;
|
|
18
|
+
hasExited = false;
|
|
19
|
+
constructor(startProcessAsync, columns, rows) {
|
|
20
|
+
this.startProcessAsync = startProcessAsync;
|
|
21
|
+
this.columns = columns;
|
|
22
|
+
this.rows = rows;
|
|
23
|
+
this.process = undefined;
|
|
24
|
+
this.starting = undefined;
|
|
25
|
+
}
|
|
26
|
+
get hasStarted() {
|
|
27
|
+
return this.starting !== undefined;
|
|
28
|
+
}
|
|
29
|
+
get pid() {
|
|
30
|
+
return this.process?.pid ?? null;
|
|
31
|
+
}
|
|
32
|
+
onData(listener) {
|
|
33
|
+
this.dataListeners.add(listener);
|
|
34
|
+
return { dispose: () => this.dataListeners.delete(listener) };
|
|
35
|
+
}
|
|
36
|
+
onExit(listener) {
|
|
37
|
+
this.exitListeners.add(listener);
|
|
38
|
+
return { dispose: () => this.exitListeners.delete(listener) };
|
|
39
|
+
}
|
|
40
|
+
write(data) {
|
|
41
|
+
this.process?.write(data);
|
|
42
|
+
}
|
|
43
|
+
resize(columns, rows) {
|
|
44
|
+
this.columns = columns;
|
|
45
|
+
this.rows = rows;
|
|
46
|
+
if (this.process === undefined)
|
|
47
|
+
this.start();
|
|
48
|
+
else
|
|
49
|
+
this.process.resize(columns, rows);
|
|
50
|
+
}
|
|
51
|
+
pause() {
|
|
52
|
+
this.isPaused = true;
|
|
53
|
+
this.process?.pause();
|
|
54
|
+
}
|
|
55
|
+
resume() {
|
|
56
|
+
this.isPaused = false;
|
|
57
|
+
this.process?.resume();
|
|
58
|
+
}
|
|
59
|
+
readForegroundProcessGroupAsync() {
|
|
60
|
+
return this.process?.readForegroundProcessGroupAsync() ?? Promise.resolve(null);
|
|
61
|
+
}
|
|
62
|
+
async endAsync() {
|
|
63
|
+
this.isEnded = true;
|
|
64
|
+
await this.starting;
|
|
65
|
+
if (this.process !== undefined)
|
|
66
|
+
return this.process.endAsync();
|
|
67
|
+
this.exit({ exitCode: undefined });
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
start() {
|
|
71
|
+
if (this.starting !== undefined || this.isEnded)
|
|
72
|
+
return;
|
|
73
|
+
const [columns, rows] = [this.columns, this.rows];
|
|
74
|
+
this.starting = this.startProcessAsync(columns, rows).then(process => {
|
|
75
|
+
process.onData(t => {
|
|
76
|
+
for (const listener of this.dataListeners)
|
|
77
|
+
listener(t);
|
|
78
|
+
});
|
|
79
|
+
process.onExit(t => this.exit(t));
|
|
80
|
+
if (this.isPaused)
|
|
81
|
+
process.pause();
|
|
82
|
+
if (this.columns !== columns || this.rows !== rows)
|
|
83
|
+
process.resize(this.columns, this.rows);
|
|
84
|
+
this.process = process;
|
|
85
|
+
}, () => this.exit({ exitCode: undefined }));
|
|
86
|
+
}
|
|
87
|
+
exit(event) {
|
|
88
|
+
if (this.hasExited)
|
|
89
|
+
return;
|
|
90
|
+
this.hasExited = true;
|
|
91
|
+
for (const listener of this.exitListeners)
|
|
92
|
+
listener(event);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
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
|
+
import { EscapeState } from "../enums/escape-state.js";
|
|
9
|
+
import { Resources } from "../resources.js";
|
|
10
|
+
export class EscapeSequenceTracker {
|
|
11
|
+
state = EscapeState.Ground;
|
|
12
|
+
parts = [];
|
|
13
|
+
length = 0;
|
|
14
|
+
isOverflowed = false;
|
|
15
|
+
get pending() {
|
|
16
|
+
return this.isOverflowed ? "" : this.parts.join("");
|
|
17
|
+
}
|
|
18
|
+
track(data) {
|
|
19
|
+
let start = this.state === EscapeState.Ground ? -1 : 0;
|
|
20
|
+
for (let index = this.findNext(data, 0); index < data.length; index = this.findNext(data, index + 1)) {
|
|
21
|
+
const next = this.advance(data.charCodeAt(index));
|
|
22
|
+
if (next === EscapeState.Ground)
|
|
23
|
+
start = -1;
|
|
24
|
+
else if (this.isIntroducer(data.charCodeAt(index), next)) {
|
|
25
|
+
this.clear();
|
|
26
|
+
start = index;
|
|
27
|
+
}
|
|
28
|
+
this.state = next;
|
|
29
|
+
}
|
|
30
|
+
if (this.state === EscapeState.Ground)
|
|
31
|
+
this.clear();
|
|
32
|
+
else
|
|
33
|
+
this.append(data.slice(start));
|
|
34
|
+
}
|
|
35
|
+
findNext(data, start) {
|
|
36
|
+
const search = EscapeSequenceTracker.searchOf(this.state);
|
|
37
|
+
if (search === null)
|
|
38
|
+
return start;
|
|
39
|
+
search.lastIndex = start;
|
|
40
|
+
return search.exec(data)?.index ?? data.length;
|
|
41
|
+
}
|
|
42
|
+
advance(code) {
|
|
43
|
+
if (code === Resources.escapeSequenceTrackerCancel || code === Resources.escapeSequenceTrackerSubstitute)
|
|
44
|
+
return EscapeState.Ground;
|
|
45
|
+
if (code === Resources.escapeSequenceTrackerEscape)
|
|
46
|
+
return EscapeState.Escape;
|
|
47
|
+
switch (this.state) {
|
|
48
|
+
case EscapeState.Ground:
|
|
49
|
+
return EscapeSequenceTracker.introduce(code);
|
|
50
|
+
case EscapeState.Escape:
|
|
51
|
+
return EscapeSequenceTracker.escape(code);
|
|
52
|
+
case EscapeState.EscapeIntermediate:
|
|
53
|
+
return EscapeSequenceTracker.escapeIntermediate(code);
|
|
54
|
+
case EscapeState.ControlSequence:
|
|
55
|
+
return EscapeSequenceTracker.controlSequence(code);
|
|
56
|
+
case EscapeState.OperatingSystemCommand:
|
|
57
|
+
case EscapeState.ControlString:
|
|
58
|
+
return EscapeState.Ground;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
isIntroducer(code, next) {
|
|
62
|
+
return code === Resources.escapeSequenceTrackerEscape || (this.state === EscapeState.Ground && next !== EscapeState.Ground);
|
|
63
|
+
}
|
|
64
|
+
clear() {
|
|
65
|
+
this.parts = [];
|
|
66
|
+
this.length = 0;
|
|
67
|
+
this.isOverflowed = false;
|
|
68
|
+
}
|
|
69
|
+
append(part) {
|
|
70
|
+
if (this.isOverflowed)
|
|
71
|
+
return;
|
|
72
|
+
this.length += part.length;
|
|
73
|
+
if (this.length > Resources.maximumPendingLength) {
|
|
74
|
+
this.parts = [];
|
|
75
|
+
this.isOverflowed = true;
|
|
76
|
+
}
|
|
77
|
+
else
|
|
78
|
+
this.parts.push(part);
|
|
79
|
+
}
|
|
80
|
+
static searchOf(state) {
|
|
81
|
+
switch (state) {
|
|
82
|
+
case EscapeState.Ground:
|
|
83
|
+
return Resources.escapeSequenceTrackerIntroducer;
|
|
84
|
+
case EscapeState.OperatingSystemCommand:
|
|
85
|
+
return Resources.escapeSequenceTrackerOperatingSystemCommandStop;
|
|
86
|
+
case EscapeState.ControlString:
|
|
87
|
+
return Resources.escapeSequenceTrackerControlStringStop;
|
|
88
|
+
default:
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
static introduce(code) {
|
|
93
|
+
switch (code) {
|
|
94
|
+
case Resources.escapeSequenceTrackerControlSequenceIntroducer:
|
|
95
|
+
return EscapeState.ControlSequence;
|
|
96
|
+
case Resources.escapeSequenceTrackerOperatingSystemCommand:
|
|
97
|
+
return EscapeState.OperatingSystemCommand;
|
|
98
|
+
default:
|
|
99
|
+
return EscapeState.ControlString;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
static escape(code) {
|
|
103
|
+
switch (code) {
|
|
104
|
+
case Resources.escapeSequenceTrackerOpenBracket:
|
|
105
|
+
return EscapeState.ControlSequence;
|
|
106
|
+
case Resources.escapeSequenceTrackerCloseBracket:
|
|
107
|
+
return EscapeState.OperatingSystemCommand;
|
|
108
|
+
case Resources.escapeSequenceTrackerLetterP:
|
|
109
|
+
case Resources.escapeSequenceTrackerLetterX:
|
|
110
|
+
case Resources.escapeSequenceTrackerCaret:
|
|
111
|
+
case Resources.escapeSequenceTrackerUnderscore:
|
|
112
|
+
return EscapeState.ControlString;
|
|
113
|
+
default:
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
if (code < Resources.escapeSequenceTrackerSpace || code === Resources.escapeSequenceTrackerDelete)
|
|
117
|
+
return EscapeState.Escape;
|
|
118
|
+
return code <= Resources.escapeSequenceTrackerLastIntermediate ? EscapeState.EscapeIntermediate : EscapeState.Ground;
|
|
119
|
+
}
|
|
120
|
+
static escapeIntermediate(code) {
|
|
121
|
+
return code <= Resources.escapeSequenceTrackerLastIntermediate || code === Resources.escapeSequenceTrackerDelete ? EscapeState.EscapeIntermediate : EscapeState.Ground;
|
|
122
|
+
}
|
|
123
|
+
static controlSequence(code) {
|
|
124
|
+
return code < Resources.escapeSequenceTrackerFirstControlSequenceFinal || code === Resources.escapeSequenceTrackerDelete ? EscapeState.ControlSequence : EscapeState.Ground;
|
|
125
|
+
}
|
|
126
|
+
}
|