@noldova/terminal 0.0.10 → 0.0.12
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 +4 -4
- package/package.json +6 -6
- package/src/api/window.d.ts +94 -1
- package/src/api/window.js +1 -1
- package/src/interfaces/i-shell-adapter.js +1 -0
- package/src/models/completion-candidate.js +8 -1
- package/src/models/describe-group.js +11 -0
- package/src/models/environment-tools.js +5 -1
- package/src/models/known-description.js +18 -0
- package/src/models/terminal-events.js +3 -1
- package/src/models/tool-command.js +15 -0
- package/src/models/tool-word.js +15 -0
- package/src/resources.js +251 -6
- package/src/runtime-part.js +5 -3
- package/src/services/command-describer.js +133 -0
- package/src/services/command-tracker.js +3 -0
- package/src/services/completion-source.js +62 -47
- package/src/services/folder-change-line.js +23 -0
- package/src/services/leftover-folders.js +42 -0
- package/src/services/posix-shell-adapter.js +54 -0
- package/src/services/powershell-shell-adapter.js +42 -0
- package/src/services/printed-text.js +40 -0
- package/src/services/pseudo-terminal.js +9 -3
- package/src/services/shell-adapters.js +25 -0
- package/src/services/terminal-history-folder.js +5 -16
- package/src/services/terminal-host.js +61 -8
- package/src/services/terminal-session.js +26 -3
- package/src/services/windows-environment.js +8 -1
|
@@ -16,15 +16,14 @@ import { ShellLine } from "../models/shell-line.js";
|
|
|
16
16
|
import { Resources } from "../resources.js";
|
|
17
17
|
import { BoundedReads } from "./bounded-reads.js";
|
|
18
18
|
import { FailureText } from "./failure-text.js";
|
|
19
|
-
import { PowerShellBinding } from "./powershell-binding.js";
|
|
20
19
|
import { SharedReads } from "./shared-reads.js";
|
|
21
|
-
import {
|
|
20
|
+
import { ShellAdapters } from "./shell-adapters.js";
|
|
22
21
|
export class CompletionSource {
|
|
23
22
|
runner;
|
|
24
23
|
isWindows;
|
|
25
24
|
paths;
|
|
26
25
|
homeFolder;
|
|
27
|
-
|
|
26
|
+
adapters;
|
|
28
27
|
shared;
|
|
29
28
|
stuck = [];
|
|
30
29
|
listed = new WeakMap();
|
|
@@ -39,25 +38,29 @@ export class CompletionSource {
|
|
|
39
38
|
this.isWindows = platform === Resources.windowsPlatform;
|
|
40
39
|
this.paths = this.isWindows ? path.win32 : path.posix;
|
|
41
40
|
this.homeFolder = homeFolder;
|
|
42
|
-
this.
|
|
41
|
+
this.adapters = new ShellAdapters(this.isWindows);
|
|
43
42
|
this.shared = new SharedReads(fileSystem);
|
|
44
43
|
}
|
|
45
44
|
async completeAsync(key, kind, line, cursor, folder, environment, shellNames, shellBuiltins) {
|
|
46
|
-
|
|
45
|
+
const shell = this.adapters.of(kind);
|
|
46
|
+
if (Object.isNull(shell) || this.stuck.includes(key))
|
|
47
47
|
return new TerminalCompletion(cursor, []);
|
|
48
|
-
const builtins =
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
const builtins = shell.listBuiltins(shellNames, shellBuiltins);
|
|
49
|
+
return this.readAsync(key, t => this.completeLineAsync(t, shell, builtins, line.slice(0, cursor), folder, environment));
|
|
50
|
+
}
|
|
51
|
+
adapterOf(kind) {
|
|
52
|
+
return this.adapters.of(kind);
|
|
52
53
|
}
|
|
53
54
|
toLocalFolder(folder, kind, environment) {
|
|
54
|
-
|
|
55
|
+
const shell = this.adapters.of(kind);
|
|
56
|
+
return Object.isNull(shell) ? folder : shell.toLocalPath(folder, this.readVariable(environment, Resources.temporaryFolderVariable) ?? null);
|
|
55
57
|
}
|
|
56
58
|
followsCommand(kind, line, cursor) {
|
|
57
|
-
|
|
59
|
+
const shell = this.adapters.of(kind);
|
|
60
|
+
return !Object.isNull(shell) && shell.readWords(line.slice(0, cursor)).words.length > 0;
|
|
58
61
|
}
|
|
59
62
|
addOptions(completion, kind, line, cursor, options) {
|
|
60
|
-
const ignoresCase = this.isWindows || kind ===
|
|
63
|
+
const ignoresCase = this.isWindows || this.adapters.of(kind)?.ignoresCase === true;
|
|
61
64
|
const toKey = (text) => ignoresCase ? text.toLowerCase() : text;
|
|
62
65
|
const prefix = toKey(line.slice(completion.replaceFrom, cursor));
|
|
63
66
|
const labels = new Set(completion.items.map(t => t.label));
|
|
@@ -71,9 +74,10 @@ export class CompletionSource {
|
|
|
71
74
|
return new TerminalCompletion(completion.replaceFrom, items.slice(0, ProtocolResources.maximumCompletionItems));
|
|
72
75
|
}
|
|
73
76
|
async findMissingAsync(key, shell, prompt, kind, folder, names, shellNames, environment) {
|
|
74
|
-
|
|
77
|
+
const adapter = this.adapters.of(kind);
|
|
78
|
+
if (Object.isNull(adapter) || adapter.looksUpMissing || Object.isNull(shellNames) || this.stuck.includes(key))
|
|
75
79
|
return new TerminalMissingCommands([]);
|
|
76
|
-
const takesBareNames =
|
|
80
|
+
const takesBareNames = adapter.takesBareNames;
|
|
77
81
|
const search = JSON.stringify([kind, this.readVariable(environment, Resources.pathVariable),
|
|
78
82
|
this.readVariable(environment, Resources.pathExtensionsVariable)]);
|
|
79
83
|
const last = this.listed.get(shell);
|
|
@@ -88,7 +92,7 @@ export class CompletionSource {
|
|
|
88
92
|
const unknown = names.filter(t => !this.isPath(t) && !t.startsWith(Resources.helperNamePrefix)
|
|
89
93
|
&& !known.has(this.toCommandName(t)) && !this.hasSuffixAlias(t, shellNames));
|
|
90
94
|
const missing = unknown.length > 0 && shellNames.has(Resources.autocdName)
|
|
91
|
-
? await this.dropFoldersAsync(reads,
|
|
95
|
+
? await this.dropFoldersAsync(reads, adapter, folder, environment, unknown) : unknown;
|
|
92
96
|
return new TerminalMissingCommands(reads.wasCutShort ? [] : missing);
|
|
93
97
|
});
|
|
94
98
|
}
|
|
@@ -141,8 +145,8 @@ export class CompletionSource {
|
|
|
141
145
|
const start = name.lastIndexOf(Resources.suffixStart);
|
|
142
146
|
return start > 0 && shellNames.has(`${Resources.suffixAliasNameStart}${name.slice(start + 1)}`);
|
|
143
147
|
}
|
|
144
|
-
async dropFoldersAsync(reads,
|
|
145
|
-
const workFolder =
|
|
148
|
+
async dropFoldersAsync(reads, shell, folder, environment, names) {
|
|
149
|
+
const workFolder = shell.toLocalPath(folder, this.readVariable(environment, Resources.temporaryFolderVariable) ?? null);
|
|
146
150
|
if (Object.isNull(workFolder))
|
|
147
151
|
return names;
|
|
148
152
|
const folders = new Set((await reads.readEntriesAsync(workFolder)).filter(t => t.isFolder)
|
|
@@ -162,49 +166,71 @@ export class CompletionSource {
|
|
|
162
166
|
}
|
|
163
167
|
}
|
|
164
168
|
}
|
|
165
|
-
async completeLineAsync(reads,
|
|
166
|
-
const
|
|
167
|
-
const
|
|
168
|
-
const escapesWildcards = isPowerShell && this.binding.bindsWildcardPath(typed.words);
|
|
169
|
+
async completeLineAsync(reads, shell, builtins, line, folder, environment) {
|
|
170
|
+
const typed = shell.readWords(line);
|
|
171
|
+
const escapesWildcards = shell.escapesWildcards(typed.words);
|
|
169
172
|
const shellLine = escapesWildcards
|
|
170
173
|
? new ShellLine(typed.words, typed.start, typed.value.replace(Resources.powerShellEscapedWildcards, Resources.completionSourceEscapedWildcardReplacement), typed.quote, typed.startsQuoted)
|
|
171
174
|
: typed;
|
|
172
|
-
const ignoresCase = this.isWindows ||
|
|
175
|
+
const ignoresCase = this.isWindows || shell.ignoresCase;
|
|
173
176
|
const prefix = ignoresCase ? shellLine.value.toLowerCase() : shellLine.value;
|
|
174
|
-
const expandsHome =
|
|
177
|
+
const expandsHome = shell.expandsHome(shellLine.startsQuoted);
|
|
175
178
|
const keepsHome = expandsHome && this.isHome(shellLine.value);
|
|
176
|
-
const candidates = (await this.listAsync(reads,
|
|
179
|
+
const candidates = (await this.listAsync(reads, shell, builtins, shellLine, folder, environment, expandsHome))
|
|
177
180
|
.filter(t => (ignoresCase ? t.value.toLowerCase() : t.value).startsWith(prefix));
|
|
178
181
|
const items = [...new Map(candidates.map(t => [t.value, t])).values()]
|
|
179
|
-
.sort((a, b) => a.label.localeCompare(b.label, Resources.sortLocale))
|
|
182
|
+
.sort((a, b) => a.rank - b.rank || a.label.localeCompare(b.label, Resources.sortLocale))
|
|
180
183
|
.flatMap(t => {
|
|
181
|
-
const text =
|
|
184
|
+
const text = shell.writeWord(t.value, shellLine.quote, t.closesQuote, escapesWildcards && (t.kind === TerminalCompletionKind.File || t.kind === TerminalCompletionKind.Folder), keepsHome);
|
|
182
185
|
return text.length <= ProtocolResources.maximumPathLength && !ProtocolResources.controlCharacters.test(text)
|
|
183
|
-
? [new TerminalCompletionItem(text, t.label, t.kind)]
|
|
186
|
+
? [new TerminalCompletionItem(text, t.label, t.kind, t.description)]
|
|
184
187
|
: [];
|
|
185
188
|
});
|
|
186
189
|
return new TerminalCompletion(shellLine.start, items.slice(0, ProtocolResources.maximumCompletionItems));
|
|
187
190
|
}
|
|
188
|
-
listAsync(reads,
|
|
191
|
+
listAsync(reads, shell, builtins, shellLine, folder, environment, expandsHome) {
|
|
189
192
|
const words = shellLine.words.map(t => this.toCommandName(t));
|
|
190
193
|
if (words.length === 0 && !this.isPath(shellLine.value))
|
|
191
194
|
return this.listCommandsAsync(reads, builtins, environment);
|
|
192
195
|
const temporaryFolder = this.readVariable(environment, Resources.temporaryFolderVariable) ?? null;
|
|
193
|
-
const workFolder =
|
|
196
|
+
const workFolder = shell.toLocalPath(folder, temporaryFolder);
|
|
194
197
|
if (!Object.isNull(workFolder) && words.length === Resources.subcommandWordCount && words[0] === Resources.gitCommand && Resources.gitBranchCommands.some(t => shellLine.words[1] === t))
|
|
195
198
|
return this.listBranchesAsync(reads, workFolder, environment);
|
|
196
199
|
if (!Object.isNull(workFolder) && words.length === Resources.subcommandWordCount && words[0] === Resources.npmCommand && Resources.npmRunCommands.some(t => shellLine.words[1] === t))
|
|
197
200
|
return this.listScriptsAsync(reads, workFolder);
|
|
198
|
-
|
|
201
|
+
const paths = this.listPathsAsync(reads, shell, shellLine.value, workFolder, expandsHome, temporaryFolder);
|
|
202
|
+
const command = words.length === 1 ? words[0] : undefined;
|
|
203
|
+
if (Object.isUndefined(command) || this.isPath(shellLine.value))
|
|
204
|
+
return paths;
|
|
205
|
+
return this.listToolWordsAsync(reads, command, workFolder, paths);
|
|
206
|
+
}
|
|
207
|
+
async listToolWordsAsync(reads, command, workFolder, paths) {
|
|
208
|
+
const tool = Resources.toolCommands.find(t => t.name === command);
|
|
209
|
+
if (!Object.isUndefined(tool))
|
|
210
|
+
return [...tool.words.map(t => new CompletionCandidate(t.name, t.name, TerminalCompletionKind.Command, true, t.description)), ...(await paths).map(t => t.ranked(1))];
|
|
211
|
+
if (command === Resources.nodeCommand)
|
|
212
|
+
return (await paths).map(t => t.kind === TerminalCompletionKind.File && Resources.nodeScriptExtensions.includes(this.paths.extname(t.label).toLowerCase()) ? t : t.ranked(1));
|
|
213
|
+
if (command === Resources.npxCommand && !Object.isNull(workFolder))
|
|
214
|
+
return [...await this.listPackageBinsAsync(reads, workFolder), ...(await paths).map(t => t.ranked(1))];
|
|
215
|
+
return paths;
|
|
199
216
|
}
|
|
200
|
-
async
|
|
217
|
+
async listPackageBinsAsync(reads, folder) {
|
|
218
|
+
let current = folder;
|
|
219
|
+
for (;;) {
|
|
220
|
+
const entries = await reads.readEntriesAsync(this.paths.join(current, ...Resources.packageBinFolder));
|
|
221
|
+
const names = [...new Set(entries.filter(t => !t.isFolder).map(t => this.isWindows ? t.name.replace(Resources.packageBinExtension, "") : t.name))];
|
|
222
|
+
if (names.length > 0 || this.paths.dirname(current) === current)
|
|
223
|
+
return names.map(t => new CompletionCandidate(t, t, TerminalCompletionKind.Command, true));
|
|
224
|
+
current = this.paths.dirname(current);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
async listPathsAsync(reads, shell, value, workFolder, expandsHome, temporaryFolder) {
|
|
201
228
|
const end = Math.max(value.lastIndexOf(Resources.posixSeparator), this.isWindows ? value.lastIndexOf(Resources.windowsSeparator) : -1);
|
|
202
229
|
const typedFolder = value.slice(0, end + 1);
|
|
203
|
-
const folder = Object.isNull(workFolder) ? null : this.toFolder(
|
|
230
|
+
const folder = Object.isNull(workFolder) ? null : this.toFolder(shell, typedFolder, workFolder, expandsHome, temporaryFolder);
|
|
204
231
|
if (Object.isNull(folder))
|
|
205
232
|
return [];
|
|
206
|
-
const separator = end >= 0 ? value.charAt(end)
|
|
207
|
-
: this.isWindows && kind === TerminalShellKind.PowerShell ? Resources.windowsSeparator : Resources.posixSeparator;
|
|
233
|
+
const separator = end >= 0 ? value.charAt(end) : shell.separator;
|
|
208
234
|
const showsHidden = value.slice(end + 1).startsWith(Resources.hiddenPrefix);
|
|
209
235
|
return (await reads.readEntriesAsync(folder))
|
|
210
236
|
.filter(t => showsHidden || !t.name.startsWith(Resources.hiddenPrefix))
|
|
@@ -299,21 +325,10 @@ export class CompletionSource {
|
|
|
299
325
|
readVariable(environment, name) {
|
|
300
326
|
return this.isWindows ? Object.entries(environment).find(([t]) => t.toUpperCase() === name)?.[1] : environment[name];
|
|
301
327
|
}
|
|
302
|
-
toFolder(
|
|
303
|
-
const folder = expandsHome && this.isHome(typedFolder) ? this.paths.join(this.homeFolder, typedFolder.slice(Resources.homePrefix.length)) :
|
|
328
|
+
toFolder(shell, typedFolder, workFolder, expandsHome, temporaryFolder) {
|
|
329
|
+
const folder = expandsHome && this.isHome(typedFolder) ? this.paths.join(this.homeFolder, typedFolder.slice(Resources.homePrefix.length)) : shell.toLocalPath(typedFolder, temporaryFolder);
|
|
304
330
|
return Object.isNull(folder) ? null : this.paths.resolve(workFolder, folder);
|
|
305
331
|
}
|
|
306
|
-
toLocalPath(value, kind, temporaryFolder) {
|
|
307
|
-
if (!this.isWindows || kind !== TerminalShellKind.Bash || !value.startsWith(Resources.posixSeparator))
|
|
308
|
-
return value;
|
|
309
|
-
const temporary = Resources.gitBashTemporaryFolder;
|
|
310
|
-
if (!Object.isNull(temporaryFolder) && path.win32.isAbsolute(temporaryFolder)
|
|
311
|
-
&& (value === temporary || value.startsWith(`${temporary}${Resources.posixSeparator}`)))
|
|
312
|
-
return path.win32.join(temporaryFolder, value.slice(temporary.length));
|
|
313
|
-
if (!Resources.gitBashDrivePath.test(value))
|
|
314
|
-
return null;
|
|
315
|
-
return Resources.formatCompletionSourceWindowsDrivePath(value.charAt(1).toUpperCase(), value.slice(Resources.completionSourceGitBashDrivePrefixLength).replaceAll(Resources.posixSeparator, Resources.windowsSeparator));
|
|
316
|
-
}
|
|
317
332
|
toCommandName(word) {
|
|
318
333
|
const name = this.paths.basename(word);
|
|
319
334
|
return this.isWindows ? name.toLowerCase().replace(Resources.windowsProgramExtension, "") : name;
|
|
@@ -0,0 +1,23 @@
|
|
|
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 "@noldova/context.core";
|
|
9
|
+
import { TerminalShellKind } from "@noldova/terminal.protocol";
|
|
10
|
+
import { Resources } from "../resources.js";
|
|
11
|
+
export class FolderChangeLine {
|
|
12
|
+
static format(kind, folder) {
|
|
13
|
+
switch (kind) {
|
|
14
|
+
case TerminalShellKind.PowerShell:
|
|
15
|
+
return `${Resources.powerShellChangeFolder}${Resources.singleQuote}${folder.replace(Resources.powerShellSingleQuotes, "$&$&")}${Resources.singleQuote}`;
|
|
16
|
+
case TerminalShellKind.Bash:
|
|
17
|
+
case TerminalShellKind.Zsh:
|
|
18
|
+
return `${Resources.posixChangeFolder}${Resources.singleQuote}${folder.replaceAll(Resources.singleQuote, Resources.posixQuotedSingleQuote)}${Resources.singleQuote}`;
|
|
19
|
+
default:
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
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 "@noldova/context.core";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
import { Resources } from "../resources.js";
|
|
11
|
+
export class LeftoverFolders {
|
|
12
|
+
reader;
|
|
13
|
+
signaller;
|
|
14
|
+
temporaryFolder;
|
|
15
|
+
pid;
|
|
16
|
+
constructor(reader, signaller, temporaryFolder, pid) {
|
|
17
|
+
this.reader = reader;
|
|
18
|
+
this.signaller = signaller;
|
|
19
|
+
this.temporaryFolder = temporaryFolder;
|
|
20
|
+
this.pid = pid;
|
|
21
|
+
}
|
|
22
|
+
async findAsync(prefix, isWithoutPidLeftover = false) {
|
|
23
|
+
const found = [];
|
|
24
|
+
for (const name of await this.reader.readFolderNamesAsync(this.temporaryFolder)) {
|
|
25
|
+
if (!name.startsWith(prefix))
|
|
26
|
+
continue;
|
|
27
|
+
const suffix = name.slice(prefix.length);
|
|
28
|
+
const pid = LeftoverFolders.toPid(suffix);
|
|
29
|
+
const isLeftover = Object.isNull(pid)
|
|
30
|
+
? isWithoutPidLeftover && Resources.leftoverFolderSuffixWithoutPid.test(suffix)
|
|
31
|
+
: pid !== this.pid && !this.signaller.isRunning(pid);
|
|
32
|
+
if (isLeftover)
|
|
33
|
+
found.push(path.join(this.temporaryFolder, name));
|
|
34
|
+
}
|
|
35
|
+
return found;
|
|
36
|
+
}
|
|
37
|
+
static toPid(suffix) {
|
|
38
|
+
const match = Resources.leftoverFolderSuffix.exec(suffix);
|
|
39
|
+
const pid = Number(match?.[1]);
|
|
40
|
+
return Number.isSafeInteger(pid) && pid > 0 ? pid : null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
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 "@noldova/context.core";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
import { Resources } from "../resources.js";
|
|
11
|
+
import { ShellWords } from "./shell-words.js";
|
|
12
|
+
export class PosixShellAdapter {
|
|
13
|
+
ignoresCase;
|
|
14
|
+
separator = Resources.posixSeparator;
|
|
15
|
+
takesBareNames;
|
|
16
|
+
optionsKeys;
|
|
17
|
+
folderKeys;
|
|
18
|
+
looksUpMissing = false;
|
|
19
|
+
isGitBash;
|
|
20
|
+
constructor(isWindows, optionsKeys, folderKeys, isBash) {
|
|
21
|
+
this.ignoresCase = isWindows;
|
|
22
|
+
this.optionsKeys = optionsKeys;
|
|
23
|
+
this.folderKeys = folderKeys;
|
|
24
|
+
this.isGitBash = isWindows && isBash;
|
|
25
|
+
this.takesBareNames = this.isGitBash;
|
|
26
|
+
}
|
|
27
|
+
readWords(line) {
|
|
28
|
+
return ShellWords.read(line, false);
|
|
29
|
+
}
|
|
30
|
+
writeWord(value, quote, closesQuote, escapesWildcards, keepsHome) {
|
|
31
|
+
return ShellWords.write(value, quote, false, closesQuote, escapesWildcards, keepsHome);
|
|
32
|
+
}
|
|
33
|
+
escapesWildcards() {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
expandsHome(startsQuoted) {
|
|
37
|
+
return !startsQuoted;
|
|
38
|
+
}
|
|
39
|
+
listBuiltins(shellNames, shellBuiltins) {
|
|
40
|
+
return [...new Set([...shellBuiltins ?? [], ...shellNames ?? []])]
|
|
41
|
+
.filter(t => !t.startsWith(Resources.helperNamePrefix) && t !== Resources.autocdName && !t.startsWith(Resources.suffixAliasNameStart));
|
|
42
|
+
}
|
|
43
|
+
toLocalPath(value, temporaryFolder) {
|
|
44
|
+
if (!this.isGitBash || !value.startsWith(Resources.posixSeparator))
|
|
45
|
+
return value;
|
|
46
|
+
const temporary = Resources.gitBashTemporaryFolder;
|
|
47
|
+
if (!Object.isNull(temporaryFolder) && path.win32.isAbsolute(temporaryFolder)
|
|
48
|
+
&& (value === temporary || value.startsWith(`${temporary}${Resources.posixSeparator}`)))
|
|
49
|
+
return path.win32.join(temporaryFolder, value.slice(temporary.length));
|
|
50
|
+
if (!Resources.gitBashDrivePath.test(value))
|
|
51
|
+
return null;
|
|
52
|
+
return Resources.formatCompletionSourceWindowsDrivePath(value.charAt(1).toUpperCase(), value.slice(Resources.completionSourceGitBashDrivePrefixLength).replaceAll(Resources.posixSeparator, Resources.windowsSeparator));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
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 "@noldova/context.core";
|
|
9
|
+
import { Resources } from "../resources.js";
|
|
10
|
+
import { PowerShellBinding } from "./powershell-binding.js";
|
|
11
|
+
import { ShellWords } from "./shell-words.js";
|
|
12
|
+
export class PowerShellShellAdapter {
|
|
13
|
+
ignoresCase = true;
|
|
14
|
+
separator;
|
|
15
|
+
takesBareNames = false;
|
|
16
|
+
optionsKeys = Resources.powerShellOptionsKeys;
|
|
17
|
+
folderKeys = Resources.powerShellFolderKeys;
|
|
18
|
+
looksUpMissing = true;
|
|
19
|
+
binding;
|
|
20
|
+
constructor(isWindows) {
|
|
21
|
+
this.separator = isWindows ? Resources.windowsSeparator : Resources.posixSeparator;
|
|
22
|
+
this.binding = new PowerShellBinding(isWindows);
|
|
23
|
+
}
|
|
24
|
+
readWords(line) {
|
|
25
|
+
return ShellWords.read(line, true);
|
|
26
|
+
}
|
|
27
|
+
writeWord(value, quote, closesQuote, escapesWildcards, keepsHome) {
|
|
28
|
+
return ShellWords.write(value, quote, true, closesQuote, escapesWildcards, keepsHome);
|
|
29
|
+
}
|
|
30
|
+
escapesWildcards(words) {
|
|
31
|
+
return this.binding.bindsWildcardPath(words);
|
|
32
|
+
}
|
|
33
|
+
expandsHome() {
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
listBuiltins() {
|
|
37
|
+
return Resources.powerShellBuiltins;
|
|
38
|
+
}
|
|
39
|
+
toLocalPath(value) {
|
|
40
|
+
return value;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
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 { Resources } from "../resources.js";
|
|
9
|
+
import { EscapeStripper } from "./escape-stripper.js";
|
|
10
|
+
export class PrintedText {
|
|
11
|
+
stripper = new EscapeStripper();
|
|
12
|
+
line = [];
|
|
13
|
+
column = 0;
|
|
14
|
+
isVisible(data) {
|
|
15
|
+
for (const part of data.split(Resources.printedTextBreaks)) {
|
|
16
|
+
if (part === Resources.carriageReturn) {
|
|
17
|
+
this.column = 0;
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
if (part === Resources.lineFeed) {
|
|
21
|
+
if (!PrintedText.isBlank(this.line))
|
|
22
|
+
return true;
|
|
23
|
+
this.line = [];
|
|
24
|
+
this.column = 0;
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
for (const character of this.stripper.strip(part)) {
|
|
28
|
+
this.line[this.column] = character;
|
|
29
|
+
this.column++;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return !PrintedText.isBlank(this.line) && !PrintedText.isLineEndMark(this.line);
|
|
33
|
+
}
|
|
34
|
+
static isBlank(line) {
|
|
35
|
+
return line.join("").trim().length === 0;
|
|
36
|
+
}
|
|
37
|
+
static isLineEndMark(line) {
|
|
38
|
+
return Resources.lineEndMarks.includes(line.join("").trimEnd());
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -11,18 +11,22 @@ export class PseudoTerminal {
|
|
|
11
11
|
process;
|
|
12
12
|
listener;
|
|
13
13
|
isConPty;
|
|
14
|
+
asksAfterResize;
|
|
14
15
|
heldKeys = [];
|
|
15
16
|
hasExited = false;
|
|
16
17
|
isEnding = false;
|
|
17
18
|
openRequests = 0;
|
|
18
19
|
isResizeAsking = false;
|
|
20
|
+
isRequestShared = false;
|
|
21
|
+
requestTime = Number.NEGATIVE_INFINITY;
|
|
19
22
|
hasOutput = false;
|
|
20
23
|
outputEnd = "";
|
|
21
24
|
answerLimit = undefined;
|
|
22
|
-
constructor(process, listener, isConPty = false) {
|
|
25
|
+
constructor(process, listener, isConPty = false, asksAfterResize = isConPty) {
|
|
23
26
|
this.process = process;
|
|
24
27
|
this.listener = listener;
|
|
25
28
|
this.isConPty = isConPty;
|
|
29
|
+
this.asksAfterResize = isConPty && asksAfterResize;
|
|
26
30
|
this.process.onData(t => {
|
|
27
31
|
this.hasOutput = true;
|
|
28
32
|
if (this.isConPty)
|
|
@@ -65,9 +69,10 @@ export class PseudoTerminal {
|
|
|
65
69
|
if (this.hasExited)
|
|
66
70
|
return;
|
|
67
71
|
this.process.resize(size.columns, size.rows);
|
|
68
|
-
if (!this.
|
|
72
|
+
if (!this.asksAfterResize || !this.hasOutput || this.isResizeAsking)
|
|
69
73
|
return;
|
|
70
74
|
this.isResizeAsking = true;
|
|
75
|
+
this.isRequestShared = Date.now() - this.requestTime < Resources.cursorRequestFrameMilliseconds;
|
|
71
76
|
this.openRequests++;
|
|
72
77
|
this.limitAnswers();
|
|
73
78
|
}
|
|
@@ -93,6 +98,7 @@ export class PseudoTerminal {
|
|
|
93
98
|
this.outputEnd = text.slice(1 - Resources.cursorRequest.length);
|
|
94
99
|
if (requests === 0)
|
|
95
100
|
return;
|
|
101
|
+
this.requestTime = Date.now();
|
|
96
102
|
this.limitAnswers();
|
|
97
103
|
this.openRequests += this.isResizeAsking ? requests - 1 : requests;
|
|
98
104
|
this.isResizeAsking = false;
|
|
@@ -102,7 +108,7 @@ export class PseudoTerminal {
|
|
|
102
108
|
this.answerLimit = setTimeout(() => this.releaseUnanswered(), Resources.cursorAnswerMilliseconds);
|
|
103
109
|
}
|
|
104
110
|
releaseUnanswered() {
|
|
105
|
-
if (this.isResizeAsking)
|
|
111
|
+
if (this.isResizeAsking && !this.isRequestShared)
|
|
106
112
|
this.listener.onResizeUnasked?.();
|
|
107
113
|
this.releaseKeys();
|
|
108
114
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
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 "@noldova/context.core";
|
|
9
|
+
import { TerminalShellKind } from "@noldova/terminal.protocol";
|
|
10
|
+
import { Resources } from "../resources.js";
|
|
11
|
+
import { PosixShellAdapter } from "./posix-shell-adapter.js";
|
|
12
|
+
import { PowerShellShellAdapter } from "./powershell-shell-adapter.js";
|
|
13
|
+
export class ShellAdapters {
|
|
14
|
+
adapters;
|
|
15
|
+
constructor(isWindows) {
|
|
16
|
+
this.adapters = new Map([
|
|
17
|
+
[TerminalShellKind.PowerShell, new PowerShellShellAdapter(isWindows)],
|
|
18
|
+
[TerminalShellKind.Bash, new PosixShellAdapter(isWindows, null, null, true)],
|
|
19
|
+
[TerminalShellKind.Zsh, new PosixShellAdapter(isWindows, Resources.zshOptionsKeys, Resources.zshFolderKeys, false)]
|
|
20
|
+
]);
|
|
21
|
+
}
|
|
22
|
+
of(kind) {
|
|
23
|
+
return this.adapters.get(kind) ?? null;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -10,10 +10,10 @@ import path from "node:path";
|
|
|
10
10
|
import { TerminalHistoryPaths } from "../models/terminal-history-paths.js";
|
|
11
11
|
import { Resources } from "../resources.js";
|
|
12
12
|
import { FailureText } from "./failure-text.js";
|
|
13
|
+
import { LeftoverFolders } from "./leftover-folders.js";
|
|
13
14
|
export class TerminalHistoryFolder {
|
|
14
15
|
writer;
|
|
15
|
-
|
|
16
|
-
signaller;
|
|
16
|
+
leftovers;
|
|
17
17
|
temporaryFolder;
|
|
18
18
|
pid;
|
|
19
19
|
log;
|
|
@@ -21,8 +21,7 @@ export class TerminalHistoryFolder {
|
|
|
21
21
|
folder = null;
|
|
22
22
|
constructor(writer, reader, signaller, temporaryFolder, pid, log, access = null) {
|
|
23
23
|
this.writer = writer;
|
|
24
|
-
this.
|
|
25
|
-
this.signaller = signaller;
|
|
24
|
+
this.leftovers = new LeftoverFolders(reader, signaller, temporaryFolder, pid);
|
|
26
25
|
this.temporaryFolder = temporaryFolder;
|
|
27
26
|
this.pid = pid;
|
|
28
27
|
this.log = log;
|
|
@@ -74,11 +73,8 @@ export class TerminalHistoryFolder {
|
|
|
74
73
|
return folder;
|
|
75
74
|
}
|
|
76
75
|
async removeLeftoversAsync() {
|
|
77
|
-
for (const
|
|
78
|
-
|
|
79
|
-
if (!Object.isNull(pid) && pid !== this.pid && !this.signaller.isRunning(pid))
|
|
80
|
-
await this.removeFolderAsync(path.join(this.temporaryFolder, name));
|
|
81
|
-
}
|
|
76
|
+
for (const folder of await this.leftovers.findAsync(Resources.terminalHistoryFolderPrefix))
|
|
77
|
+
await this.removeFolderAsync(folder);
|
|
82
78
|
}
|
|
83
79
|
async removeFolderAsync(folder) {
|
|
84
80
|
try {
|
|
@@ -88,11 +84,4 @@ export class TerminalHistoryFolder {
|
|
|
88
84
|
this.log.write(Resources.formatTerminalHistoryRemovalFailed(folder, FailureText.read(error)));
|
|
89
85
|
}
|
|
90
86
|
}
|
|
91
|
-
static toPid(name) {
|
|
92
|
-
if (!name.startsWith(Resources.terminalHistoryFolderPrefix))
|
|
93
|
-
return null;
|
|
94
|
-
const match = Resources.terminalHistoryFolderFolderSuffix.exec(name.slice(Resources.terminalHistoryFolderPrefix.length));
|
|
95
|
-
const pid = Number(match?.[1]);
|
|
96
|
-
return Number.isSafeInteger(pid) && pid > 0 ? pid : null;
|
|
97
|
-
}
|
|
98
87
|
}
|