@noldova/terminal.window 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 +38 -2
- package/package.json +69 -4
- package/src/api/index.d.ts +1850 -0
- package/src/api/index.js +40 -0
- package/src/api/index.js.map +1 -0
- package/src/app/components/terminal-pane/terminal-pane.component.js +451 -0
- package/src/app/components/terminal-pane/terminal-pane.component.js.map +1 -0
- package/src/app/components/terminal-panel/terminal-panel.component.js +108 -0
- package/src/app/components/terminal-panel/terminal-panel.component.js.map +1 -0
- package/src/app/components/terminal-session/terminal-session.component.js +115 -0
- package/src/app/components/terminal-session/terminal-session.component.js.map +1 -0
- package/src/app/enums/command-token-kind.js +19 -0
- package/src/app/enums/command-token-kind.js.map +1 -0
- package/src/app/enums/terminal-ended-by.js +13 -0
- package/src/app/enums/terminal-ended-by.js.map +1 -0
- package/src/app/exceptions/embedded-rows-refused.exception.js +22 -0
- package/src/app/exceptions/embedded-rows-refused.exception.js.map +1 -0
- package/src/app/exceptions/launch-argument-refused.exception.js +20 -0
- package/src/app/exceptions/launch-argument-refused.exception.js.map +1 -0
- package/src/app/exceptions/launch-folder-missing.exception.js +19 -0
- package/src/app/exceptions/launch-folder-missing.exception.js.map +1 -0
- package/src/app/exceptions/launch-part-inactive.exception.js +17 -0
- package/src/app/exceptions/launch-part-inactive.exception.js.map +1 -0
- package/src/app/exceptions/launch-rows-refused.exception.js +19 -0
- package/src/app/exceptions/launch-rows-refused.exception.js.map +1 -0
- package/src/app/exceptions/launch-rows-without-tab.exception.js +17 -0
- package/src/app/exceptions/launch-rows-without-tab.exception.js.map +1 -0
- package/src/app/exceptions/launch-title-refused.exception.js +19 -0
- package/src/app/exceptions/launch-title-refused.exception.js.map +1 -0
- package/src/app/exceptions/owners-provided.exception.js +16 -0
- package/src/app/exceptions/owners-provided.exception.js.map +1 -0
- package/src/app/exceptions/run-argument-refused.exception.js +20 -0
- package/src/app/exceptions/run-argument-refused.exception.js.map +1 -0
- package/src/app/exceptions/run-lines-refused.exception.js +20 -0
- package/src/app/exceptions/run-lines-refused.exception.js.map +1 -0
- package/src/app/exceptions/run-part-inactive.exception.js +17 -0
- package/src/app/exceptions/run-part-inactive.exception.js.map +1 -0
- package/src/app/exceptions/run-shell-kinds-missing.exception.js +19 -0
- package/src/app/exceptions/run-shell-kinds-missing.exception.js.map +1 -0
- package/src/app/exceptions/start-folder-provided.exception.js +16 -0
- package/src/app/exceptions/start-folder-provided.exception.js.map +1 -0
- package/src/app/exceptions/terminal-launch-refused.exception.js +15 -0
- package/src/app/exceptions/terminal-launch-refused.exception.js.map +1 -0
- package/src/app/exceptions/terminal-not-active.exception.js +16 -0
- package/src/app/exceptions/terminal-not-active.exception.js.map +1 -0
- package/src/app/exceptions/terminal-run-not-found.exception.js +20 -0
- package/src/app/exceptions/terminal-run-not-found.exception.js.map +1 -0
- package/src/app/exceptions/terminal-run-not-typed.exception.js +20 -0
- package/src/app/exceptions/terminal-run-not-typed.exception.js.map +1 -0
- package/src/app/exceptions/terminal-run-refused.exception.js +15 -0
- package/src/app/exceptions/terminal-run-refused.exception.js.map +1 -0
- package/src/app/exceptions/terminal-window.exception.js +15 -0
- package/src/app/exceptions/terminal-window.exception.js.map +1 -0
- package/src/app/interfaces/i-sized-pane.js +8 -0
- package/src/app/interfaces/i-sized-pane.js.map +1 -0
- package/src/app/interfaces/i-start-folder-provider.js +8 -0
- package/src/app/interfaces/i-start-folder-provider.js.map +1 -0
- package/src/app/interfaces/i-terminal-focus-target.js +8 -0
- package/src/app/interfaces/i-terminal-focus-target.js.map +1 -0
- package/src/app/interfaces/i-terminal-restart-target.js +8 -0
- package/src/app/interfaces/i-terminal-restart-target.js.map +1 -0
- package/src/app/interfaces/i-terminal-sink.js +8 -0
- package/src/app/interfaces/i-terminal-sink.js.map +1 -0
- package/src/app/models/command-color-run.js +23 -0
- package/src/app/models/command-color-run.js.map +1 -0
- package/src/app/models/command-color-span.js +39 -0
- package/src/app/models/command-color-span.js.map +1 -0
- package/src/app/models/command-colors.js +17 -0
- package/src/app/models/command-colors.js.map +1 -0
- package/src/app/models/command-continuation.js +16 -0
- package/src/app/models/command-continuation.js.map +1 -0
- package/src/app/models/command-token.js +18 -0
- package/src/app/models/command-token.js.map +1 -0
- package/src/app/models/ended-pane.js +20 -0
- package/src/app/models/ended-pane.js.map +1 -0
- package/src/app/models/launched-terminal.js +31 -0
- package/src/app/models/launched-terminal.js.map +1 -0
- package/src/app/models/stored-lines-window.js +66 -0
- package/src/app/models/stored-lines-window.js.map +1 -0
- package/src/app/models/terminal-appearance.js +20 -0
- package/src/app/models/terminal-appearance.js.map +1 -0
- package/src/app/models/terminal-dock-growth.js +15 -0
- package/src/app/models/terminal-dock-growth.js.map +1 -0
- package/src/app/models/terminal-end.js +16 -0
- package/src/app/models/terminal-end.js.map +1 -0
- package/src/app/models/terminal-launch.js +28 -0
- package/src/app/models/terminal-launch.js.map +1 -0
- package/src/app/models/terminal-new-arguments.js +46 -0
- package/src/app/models/terminal-new-arguments.js.map +1 -0
- package/src/app/models/terminal-run-end.js +16 -0
- package/src/app/models/terminal-run-end.js.map +1 -0
- package/src/app/models/terminal-run-target.js +17 -0
- package/src/app/models/terminal-run-target.js.map +1 -0
- package/src/app/models/terminal-run.js +20 -0
- package/src/app/models/terminal-run.js.map +1 -0
- package/src/app/models/terminal-tab-key.js +30 -0
- package/src/app/models/terminal-tab-key.js.map +1 -0
- package/src/app/models/terminal-tab-label.js +18 -0
- package/src/app/models/terminal-tab-label.js.map +1 -0
- package/src/app/services/command-coloring.js +259 -0
- package/src/app/services/command-coloring.js.map +1 -0
- package/src/app/services/command-line-tokens.js +267 -0
- package/src/app/services/command-line-tokens.js.map +1 -0
- package/src/app/services/command-suggestion.js +229 -0
- package/src/app/services/command-suggestion.js.map +1 -0
- package/src/app/services/completion-list.js +224 -0
- package/src/app/services/completion-list.js.map +1 -0
- package/src/app/services/embedded-terminal.js +99 -0
- package/src/app/services/embedded-terminal.js.map +1 -0
- package/src/app/services/key-router.js +33 -0
- package/src/app/services/key-router.js.map +1 -0
- package/src/app/services/link-policy.js +17 -0
- package/src/app/services/link-policy.js.map +1 -0
- package/src/app/services/pane-fitter.js +64 -0
- package/src/app/services/pane-fitter.js.map +1 -0
- package/src/app/services/pane-scrollbar.js +55 -0
- package/src/app/services/pane-scrollbar.js.map +1 -0
- package/src/app/services/paste-filter.js +14 -0
- package/src/app/services/paste-filter.js.map +1 -0
- package/src/app/services/renderer-switch.js +45 -0
- package/src/app/services/renderer-switch.js.map +1 -0
- package/src/app/services/session-sizing.js +61 -0
- package/src/app/services/session-sizing.js.map +1 -0
- package/src/app/services/terminal-connection.js +244 -0
- package/src/app/services/terminal-connection.js.map +1 -0
- package/src/app/services/terminal-dock-growths.js +27 -0
- package/src/app/services/terminal-dock-growths.js.map +1 -0
- package/src/app/services/terminal-focus.js +58 -0
- package/src/app/services/terminal-focus.js.map +1 -0
- package/src/app/services/terminal-launch-ends.js +23 -0
- package/src/app/services/terminal-launch-ends.js.map +1 -0
- package/src/app/services/terminal-launcher.js +143 -0
- package/src/app/services/terminal-launcher.js.map +1 -0
- package/src/app/services/terminal-line-encoder.js +45 -0
- package/src/app/services/terminal-line-encoder.js.map +1 -0
- package/src/app/services/terminal-owners.js +219 -0
- package/src/app/services/terminal-owners.js.map +1 -0
- package/src/app/services/terminal-pager.js +244 -0
- package/src/app/services/terminal-pager.js.map +1 -0
- package/src/app/services/terminal-part.js +21 -0
- package/src/app/services/terminal-part.js.map +1 -0
- package/src/app/services/terminal-restart-targets.js +28 -0
- package/src/app/services/terminal-restart-targets.js.map +1 -0
- package/src/app/services/terminal-run-ends.js +39 -0
- package/src/app/services/terminal-run-ends.js.map +1 -0
- package/src/app/services/terminal-run-notices.js +21 -0
- package/src/app/services/terminal-run-notices.js.map +1 -0
- package/src/app/services/terminal-runtime-client.js +231 -0
- package/src/app/services/terminal-runtime-client.js.map +1 -0
- package/src/app/services/terminal-shell-menu.js +48 -0
- package/src/app/services/terminal-shell-menu.js.map +1 -0
- package/src/app/services/terminal-start-folder.js +39 -0
- package/src/app/services/terminal-start-folder.js.map +1 -0
- package/src/app/services/terminal-theme-reader.js +93 -0
- package/src/app/services/terminal-theme-reader.js.map +1 -0
- package/src/app/services/terminal-window-part.js +164 -0
- package/src/app/services/terminal-window-part.js.map +1 -0
- package/src/app/services/url-link-provider.js +73 -0
- package/src/app/services/url-link-provider.js.map +1 -0
- package/src/app/types/ansi-color.js +8 -0
- package/src/app/types/ansi-color.js.map +1 -0
- package/src/app/types/ansi-key.js +8 -0
- package/src/app/types/ansi-key.js.map +1 -0
- package/src/resources.js +471 -0
- package/src/resources.js.map +1 -0
|
@@ -0,0 +1,17 @@
|
|
|
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 { TerminalRunBusy } from "@noldova/terminal.protocol";
|
|
9
|
+
export class TerminalRunTarget {
|
|
10
|
+
sessionId;
|
|
11
|
+
whenBusy;
|
|
12
|
+
constructor(sessionId, whenBusy = TerminalRunBusy.Refuse) {
|
|
13
|
+
this.sessionId = sessionId;
|
|
14
|
+
this.whenBusy = whenBusy;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=terminal-run-target.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"terminal-run-target.js","sourceRoot":"","sources":["../../../../../../src/noldova.terminal.window/src/app/models/terminal-run-target.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAE7D,MAAM,OAAO,iBAAiB;IACZ,SAAS,CAAS;IAClB,QAAQ,CAAkB;IAE1C,YAAmB,SAAiB,EAAE,WAA4B,eAAe,CAAC,MAAM;QACtF,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;CACF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
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 { TerminalRunEndedBy } from "@noldova/terminal.protocol";
|
|
9
|
+
import { TerminalRunEnd } from "./terminal-run-end.js";
|
|
10
|
+
export class TerminalRun {
|
|
11
|
+
sessionId;
|
|
12
|
+
runId;
|
|
13
|
+
ended;
|
|
14
|
+
constructor(sessionId, runId, ended = Promise.resolve(new TerminalRunEnd(TerminalRunEndedBy.TerminalEnded, null))) {
|
|
15
|
+
this.sessionId = sessionId;
|
|
16
|
+
this.runId = runId;
|
|
17
|
+
this.ended = ended;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=terminal-run.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"terminal-run.js","sourceRoot":"","sources":["../../../../../../src/noldova.terminal.window/src/app/models/terminal-run.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAEhE,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD,MAAM,OAAO,WAAW;IACN,SAAS,CAAS;IAClB,KAAK,CAAS;IACd,KAAK,CAA0B;IAE/C,YAAmB,SAAiB,EAAE,KAAa,EAAE,QAAiC,OAAO,CAAC,OAAO,CAAC,IAAI,cAAc,CAAC,kBAAkB,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC;QAC/J,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF"}
|
|
@@ -0,0 +1,30 @@
|
|
|
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 { JsonReader } from "@noldova/context.json";
|
|
9
|
+
import { Resources } from "../../resources.js";
|
|
10
|
+
export class TerminalTabKey {
|
|
11
|
+
view;
|
|
12
|
+
instance;
|
|
13
|
+
constructor(view, instance) {
|
|
14
|
+
this.view = view;
|
|
15
|
+
this.instance = instance;
|
|
16
|
+
}
|
|
17
|
+
static fromArguments(commandArguments) {
|
|
18
|
+
if (commandArguments === null || typeof commandArguments !== "object" || Array.isArray(commandArguments))
|
|
19
|
+
return null;
|
|
20
|
+
const reader = JsonReader.fromValue(commandArguments);
|
|
21
|
+
const tab = reader.hasField(Resources.tabArgument) ? reader.readValue(Resources.tabArgument) : null;
|
|
22
|
+
if (typeof tab !== "string")
|
|
23
|
+
return null;
|
|
24
|
+
const [kind, view = "", ...instance] = tab.split(Resources.tabKeySeparator);
|
|
25
|
+
if (kind !== Resources.viewTabKind || view === "")
|
|
26
|
+
return null;
|
|
27
|
+
return new TerminalTabKey(view, instance.length === 0 ? null : instance.join(Resources.tabKeySeparator));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=terminal-tab-key.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"terminal-tab-key.js","sourceRoot":"","sources":["../../../../../../src/noldova.terminal.window/src/app/models/terminal-tab-key.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,UAAU,EAAkB,MAAM,uBAAuB,CAAC;AAEnE,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,MAAM,O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of this source tree.
|
|
7
|
+
*/
|
|
8
|
+
export class TerminalTabLabel {
|
|
9
|
+
name;
|
|
10
|
+
shellName;
|
|
11
|
+
shellKind;
|
|
12
|
+
constructor(name, shellName, shellKind) {
|
|
13
|
+
this.name = name;
|
|
14
|
+
this.shellName = shellName;
|
|
15
|
+
this.shellKind = shellKind;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=terminal-tab-label.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"terminal-tab-label.js","sourceRoot":"","sources":["../../../../../../src/noldova.terminal.window/src/app/models/terminal-tab-label.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,MAAM,OAAO,gBAAgB;IACX,IAAI,CAAgB;IACpB,SAAS,CAAgB;IACzB,SAAS,CAAoB;IAE7C,YAAmB,IAAmB,EAAE,SAAwB,EAAE,SAA4B;QAC5F,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;CACF"}
|
|
@@ -0,0 +1,259 @@
|
|
|
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 as ProtocolResources, TerminalShellKind } from "@noldova/terminal.protocol";
|
|
9
|
+
import { Resources } from "../../resources.js";
|
|
10
|
+
import { CommandTokenKind } from "../enums/command-token-kind.js";
|
|
11
|
+
import { CommandColorRun } from "../models/command-color-run.js";
|
|
12
|
+
import { CommandColorSpan } from "../models/command-color-span.js";
|
|
13
|
+
import { CommandColors } from "../models/command-colors.js";
|
|
14
|
+
import { CommandContinuation } from "../models/command-continuation.js";
|
|
15
|
+
import { CommandLineTokens } from "./command-line-tokens.js";
|
|
16
|
+
export class CommandColoring {
|
|
17
|
+
terminal;
|
|
18
|
+
log;
|
|
19
|
+
subscriptions;
|
|
20
|
+
isEnabled = false;
|
|
21
|
+
isPowerShell = false;
|
|
22
|
+
isZsh = false;
|
|
23
|
+
asksNames = false;
|
|
24
|
+
colors = new CommandColors();
|
|
25
|
+
start = null;
|
|
26
|
+
startColumn = 0;
|
|
27
|
+
rightPrompt = null;
|
|
28
|
+
rightPromptColumn = 0;
|
|
29
|
+
continuations = [];
|
|
30
|
+
runs = [];
|
|
31
|
+
drawn = "";
|
|
32
|
+
kept = [];
|
|
33
|
+
find = null;
|
|
34
|
+
missing = new Map();
|
|
35
|
+
isAsking = false;
|
|
36
|
+
finders = 0;
|
|
37
|
+
constructor(terminal, log) {
|
|
38
|
+
this.terminal = terminal;
|
|
39
|
+
this.log = log;
|
|
40
|
+
this.subscriptions = [
|
|
41
|
+
terminal.onWriteParsed(() => this.update()),
|
|
42
|
+
terminal.onResize(() => this.update())
|
|
43
|
+
];
|
|
44
|
+
}
|
|
45
|
+
enable(isEnabled) {
|
|
46
|
+
this.isEnabled = isEnabled;
|
|
47
|
+
if (!isEnabled)
|
|
48
|
+
this.drop(this.kept.splice(0));
|
|
49
|
+
this.update();
|
|
50
|
+
}
|
|
51
|
+
setShell(kind) {
|
|
52
|
+
this.isPowerShell = kind === TerminalShellKind.PowerShell;
|
|
53
|
+
this.isZsh = kind === TerminalShellKind.Zsh;
|
|
54
|
+
this.asksNames = kind === TerminalShellKind.Bash || kind === TerminalShellKind.Zsh || kind === TerminalShellKind.PowerShell;
|
|
55
|
+
this.update();
|
|
56
|
+
}
|
|
57
|
+
setFinder(find) {
|
|
58
|
+
this.find = find;
|
|
59
|
+
this.finders++;
|
|
60
|
+
this.isAsking = false;
|
|
61
|
+
this.missing = new Map();
|
|
62
|
+
this.update();
|
|
63
|
+
}
|
|
64
|
+
setColors(colors) {
|
|
65
|
+
this.colors = colors;
|
|
66
|
+
for (const run of [...this.kept, ...this.runs])
|
|
67
|
+
this.paint(run);
|
|
68
|
+
}
|
|
69
|
+
startInput() {
|
|
70
|
+
this.startInputAt(0, this.terminal.buffer.active.cursorX);
|
|
71
|
+
}
|
|
72
|
+
startInputAt(rowsAbove, column, rightPrompt = null) {
|
|
73
|
+
this.keep();
|
|
74
|
+
this.leaveLine();
|
|
75
|
+
this.missing = new Map();
|
|
76
|
+
const isNormal = this.terminal.buffer.active.type !== Resources.alternateBuffer;
|
|
77
|
+
this.start = isNormal ? this.terminal.registerMarker(-rowsAbove) : null;
|
|
78
|
+
this.startColumn = column;
|
|
79
|
+
this.rightPrompt = isNormal && rightPrompt !== null ? this.terminal.registerMarker(-rowsAbove) : null;
|
|
80
|
+
this.rightPromptColumn = rightPrompt ?? 0;
|
|
81
|
+
this.update();
|
|
82
|
+
}
|
|
83
|
+
markRightPrompt() {
|
|
84
|
+
const start = this.start;
|
|
85
|
+
const buffer = this.terminal.buffer.active;
|
|
86
|
+
if (start === null || start.isDisposed || buffer.baseY + buffer.cursorY !== start.line)
|
|
87
|
+
return;
|
|
88
|
+
this.rightPrompt?.dispose();
|
|
89
|
+
this.rightPrompt = this.terminal.registerMarker(0);
|
|
90
|
+
this.rightPromptColumn = buffer.cursorX;
|
|
91
|
+
this.update();
|
|
92
|
+
}
|
|
93
|
+
continueInput() {
|
|
94
|
+
const start = this.start;
|
|
95
|
+
const buffer = this.terminal.buffer.active;
|
|
96
|
+
if (start === null || start.isDisposed || buffer.baseY + buffer.cursorY <= (this.continuations.at(-1)?.marker ?? start).line)
|
|
97
|
+
return;
|
|
98
|
+
this.continuations.push(new CommandContinuation(this.terminal.registerMarker(0), buffer.cursorX));
|
|
99
|
+
this.update();
|
|
100
|
+
}
|
|
101
|
+
endInput() {
|
|
102
|
+
this.keep();
|
|
103
|
+
this.leaveLine();
|
|
104
|
+
}
|
|
105
|
+
dispose() {
|
|
106
|
+
for (const subscription of this.subscriptions)
|
|
107
|
+
subscription.dispose();
|
|
108
|
+
this.leaveLine();
|
|
109
|
+
this.drop(this.runs.splice(0));
|
|
110
|
+
this.drop(this.kept.splice(0));
|
|
111
|
+
this.drawn = "";
|
|
112
|
+
}
|
|
113
|
+
update() {
|
|
114
|
+
this.dropErased();
|
|
115
|
+
const found = this.read();
|
|
116
|
+
const drawn = found.map(t => t.toString()).join(Resources.commandWordSeparator);
|
|
117
|
+
if (drawn === this.drawn)
|
|
118
|
+
return;
|
|
119
|
+
const buffer = this.terminal.buffer.active;
|
|
120
|
+
const cursorRow = buffer.baseY + buffer.cursorY;
|
|
121
|
+
this.drop(this.runs);
|
|
122
|
+
this.runs = found.map(t => new CommandColorRun(this.terminal.registerMarker(t.row - cursorRow), t.x, t.width, t.kind, t.text));
|
|
123
|
+
this.drawn = drawn;
|
|
124
|
+
for (const run of this.runs)
|
|
125
|
+
this.paint(run);
|
|
126
|
+
}
|
|
127
|
+
read() {
|
|
128
|
+
let text = "";
|
|
129
|
+
if (!this.walk((_row, _x, _width, _isPlain, characters) => {
|
|
130
|
+
text += characters;
|
|
131
|
+
}))
|
|
132
|
+
return [];
|
|
133
|
+
const kinds = new Array(text.length);
|
|
134
|
+
const unasked = new Set();
|
|
135
|
+
for (const token of CommandLineTokens.read(text, this.isPowerShell, this.isZsh)) {
|
|
136
|
+
const name = text.slice(token.start, token.end);
|
|
137
|
+
const isAsked = token.kind === CommandTokenKind.Command && this.asksNames && Resources.askedCommandPattern.test(name);
|
|
138
|
+
if (isAsked && !this.missing.has(name))
|
|
139
|
+
unasked.add(name);
|
|
140
|
+
kinds.fill(isAsked && this.missing.get(name) === true ? CommandTokenKind.NotFound : token.kind, token.start, token.end);
|
|
141
|
+
}
|
|
142
|
+
this.ask([...unasked]);
|
|
143
|
+
const found = [];
|
|
144
|
+
let unit = 0;
|
|
145
|
+
let open = null;
|
|
146
|
+
this.walk((row, x, width, isPlain, characters) => {
|
|
147
|
+
const kind = isPlain ? kinds[unit] : undefined;
|
|
148
|
+
unit += characters.length;
|
|
149
|
+
if (open?.continuesAt(row, x, kind) === true)
|
|
150
|
+
open.extend(width, characters);
|
|
151
|
+
else {
|
|
152
|
+
if (open !== null)
|
|
153
|
+
found.push(open);
|
|
154
|
+
open = kind === undefined ? null : new CommandColorSpan(row, x, width, kind, characters);
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
if (open !== null)
|
|
158
|
+
found.push(open);
|
|
159
|
+
return found;
|
|
160
|
+
}
|
|
161
|
+
walk(visit) {
|
|
162
|
+
const start = this.start;
|
|
163
|
+
const buffer = this.terminal.buffer.active;
|
|
164
|
+
if (!this.isEnabled || start === null || start.isDisposed || buffer.type === Resources.alternateBuffer)
|
|
165
|
+
return false;
|
|
166
|
+
for (const [index, { marker, column }] of [new CommandContinuation(start, this.startColumn), ...this.continuations].entries()) {
|
|
167
|
+
if (index > 0)
|
|
168
|
+
visit(marker.line, column, 0, false, Resources.commandLineBreak);
|
|
169
|
+
for (let row = marker.line;; row++) {
|
|
170
|
+
const line = buffer.getLine(row);
|
|
171
|
+
if (line === undefined || row > marker.line && !line.isWrapped)
|
|
172
|
+
break;
|
|
173
|
+
const first = row === marker.line ? column : 0;
|
|
174
|
+
const limit = Math.min(line.length, this.findRightPrompt(row));
|
|
175
|
+
const end = buffer.getLine(row + 1)?.isWrapped === true ? limit : this.findTextEnd(line, first, limit);
|
|
176
|
+
for (let x = first; x < end; x++) {
|
|
177
|
+
const cell = line.getCell(x);
|
|
178
|
+
if (cell !== undefined && cell.getWidth() > 0) {
|
|
179
|
+
const characters = cell.getChars();
|
|
180
|
+
visit(row, x, cell.getWidth(), cell.isFgDefault(), characters.length > 0 ? characters : Resources.emptyCellText);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return true;
|
|
186
|
+
}
|
|
187
|
+
ask(names) {
|
|
188
|
+
const find = this.find;
|
|
189
|
+
if (find === null || this.isAsking || names.length === 0)
|
|
190
|
+
return;
|
|
191
|
+
const asked = names.slice(0, ProtocolResources.maximumLookedUpCommands);
|
|
192
|
+
const missing = this.missing;
|
|
193
|
+
const finder = this.finders;
|
|
194
|
+
this.isAsking = true;
|
|
195
|
+
void find(asked).then(found => {
|
|
196
|
+
for (const name of asked)
|
|
197
|
+
missing.set(name, found.includes(name));
|
|
198
|
+
}, (error) => {
|
|
199
|
+
this.log(Resources.formatCommandLookupFailed(error));
|
|
200
|
+
if (this.finders === finder)
|
|
201
|
+
this.find = null;
|
|
202
|
+
}).finally(() => {
|
|
203
|
+
if (this.finders !== finder)
|
|
204
|
+
return;
|
|
205
|
+
this.isAsking = false;
|
|
206
|
+
this.update();
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
findTextEnd(line, first, limit) {
|
|
210
|
+
for (let x = limit - 1; x >= first; x--) {
|
|
211
|
+
const cell = line.getCell(x);
|
|
212
|
+
if (cell !== undefined && cell.getChars().trim() !== "")
|
|
213
|
+
return x + cell.getWidth();
|
|
214
|
+
}
|
|
215
|
+
return first;
|
|
216
|
+
}
|
|
217
|
+
findRightPrompt(row) {
|
|
218
|
+
const marker = this.rightPrompt;
|
|
219
|
+
return marker !== null && !marker.isDisposed && marker.line === row ? this.rightPromptColumn : this.terminal.cols;
|
|
220
|
+
}
|
|
221
|
+
paint(run) {
|
|
222
|
+
run.decoration?.dispose();
|
|
223
|
+
const color = this.colors.colorOf(run.kind);
|
|
224
|
+
run.decoration = color === undefined || run.marker.isDisposed ? undefined
|
|
225
|
+
: this.terminal.registerDecoration({ marker: run.marker, x: run.x, width: run.width, foregroundColor: color, layer: Resources.commandColorDecorationLayer });
|
|
226
|
+
}
|
|
227
|
+
keep() {
|
|
228
|
+
const runs = this.runs.splice(0);
|
|
229
|
+
this.drawn = "";
|
|
230
|
+
this.kept = this.kept.filter(t => !t.marker.isDisposed);
|
|
231
|
+
this.kept.push(...runs);
|
|
232
|
+
}
|
|
233
|
+
dropErased() {
|
|
234
|
+
const buffer = this.terminal.buffer.active;
|
|
235
|
+
if (buffer.type === Resources.alternateBuffer)
|
|
236
|
+
return;
|
|
237
|
+
const erased = this.kept.filter(t => !t.marker.isDisposed && t.marker.line >= buffer.baseY
|
|
238
|
+
&& buffer.getLine(t.marker.line)?.translateToString(false, t.x, t.x + t.width) !== t.text);
|
|
239
|
+
if (erased.length === 0)
|
|
240
|
+
return;
|
|
241
|
+
this.drop(erased);
|
|
242
|
+
this.kept = this.kept.filter(t => !erased.includes(t));
|
|
243
|
+
}
|
|
244
|
+
leaveLine() {
|
|
245
|
+
this.start?.dispose();
|
|
246
|
+
this.start = null;
|
|
247
|
+
this.rightPrompt?.dispose();
|
|
248
|
+
this.rightPrompt = null;
|
|
249
|
+
for (const continuation of this.continuations.splice(0))
|
|
250
|
+
continuation.marker.dispose();
|
|
251
|
+
}
|
|
252
|
+
drop(runs) {
|
|
253
|
+
for (const run of runs) {
|
|
254
|
+
run.decoration?.dispose();
|
|
255
|
+
run.marker.dispose();
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
//# sourceMappingURL=command-coloring.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"command-coloring.js","sourceRoot":"","sources":["../../../../../../src/noldova.terminal.window/src/app/services/command-coloring.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,SAAS,IAAI,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAG/F,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CA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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 { CommandTokenKind } from "../enums/command-token-kind.js";
|
|
10
|
+
import { CommandToken } from "../models/command-token.js";
|
|
11
|
+
export class CommandLineTokens {
|
|
12
|
+
static read(text, isPowerShell, isZsh) {
|
|
13
|
+
const kinds = Array.from({ length: text.length }, () => null);
|
|
14
|
+
const operators = isPowerShell ? Resources.powerShellOperators : Resources.posixOperators;
|
|
15
|
+
const joinedBreak = (isPowerShell ? Resources.powerShellEscape : Resources.posixEscape) + Resources.commandLineBreak;
|
|
16
|
+
const delimiters = [];
|
|
17
|
+
let expectsCommand = true;
|
|
18
|
+
let afterBlock = false;
|
|
19
|
+
let expectsDelimiter = false;
|
|
20
|
+
let afterModifier = false;
|
|
21
|
+
let modifier = null;
|
|
22
|
+
let expectsOptionValue = false;
|
|
23
|
+
let expectsTarget = false;
|
|
24
|
+
let inLoopNames = false;
|
|
25
|
+
let inLoopWords = false;
|
|
26
|
+
let afterBrace = false;
|
|
27
|
+
let afterRepeat = false;
|
|
28
|
+
const modifiers = isPowerShell ? []
|
|
29
|
+
: isZsh ? [...Resources.posixPrecommandModifiers, ...Resources.zshPrecommandModifiers] : Resources.posixPrecommandModifiers;
|
|
30
|
+
let index = 0;
|
|
31
|
+
while (index < text.length) {
|
|
32
|
+
const character = text.charAt(index);
|
|
33
|
+
if (Resources.commandBlanks.includes(character))
|
|
34
|
+
index++;
|
|
35
|
+
else if (text.startsWith(joinedBreak, index))
|
|
36
|
+
index += joinedBreak.length;
|
|
37
|
+
else if (character === Resources.commandLineBreak) {
|
|
38
|
+
expectsCommand = true;
|
|
39
|
+
afterBlock = false;
|
|
40
|
+
afterModifier = false;
|
|
41
|
+
expectsOptionValue = false;
|
|
42
|
+
expectsTarget = false;
|
|
43
|
+
afterRepeat = false;
|
|
44
|
+
inLoopNames = false;
|
|
45
|
+
index = CommandLineTokens.readHereDocuments(text, index + 1, delimiters, kinds);
|
|
46
|
+
}
|
|
47
|
+
else if (!isZsh && character === Resources.commentStart) {
|
|
48
|
+
const lineEnd = text.indexOf(Resources.commandLineBreak, index);
|
|
49
|
+
const end = lineEnd === -1 ? text.length : lineEnd;
|
|
50
|
+
CommandLineTokens.fill(kinds, index, end, CommandTokenKind.Comment);
|
|
51
|
+
index = end;
|
|
52
|
+
}
|
|
53
|
+
else if (text.startsWith(Resources.subexpressionStart, index)) {
|
|
54
|
+
CommandLineTokens.fill(kinds, index, index + Resources.subexpressionStart.length, CommandTokenKind.Operator);
|
|
55
|
+
expectsCommand = true;
|
|
56
|
+
afterModifier = false;
|
|
57
|
+
index += Resources.subexpressionStart.length;
|
|
58
|
+
}
|
|
59
|
+
else if (operators.includes(character) || CommandLineTokens.matchAt(Resources.redirectionStartPattern, text, index) > 0) {
|
|
60
|
+
const end = isZsh && text.startsWith(Resources.zshDisownOperator, index) ? index + Resources.zshDisownOperator.length
|
|
61
|
+
: CommandLineTokens.findOperatorEnd(text, index, operators);
|
|
62
|
+
const operator = text.slice(index, end);
|
|
63
|
+
CommandLineTokens.fill(kinds, index, end, CommandTokenKind.Operator);
|
|
64
|
+
if (!Resources.redirectionPattern.test(operator))
|
|
65
|
+
expectsCommand = Resources.commandOpeningPattern.test(operator);
|
|
66
|
+
afterBlock = isPowerShell && operator.endsWith(Resources.blockEnd);
|
|
67
|
+
expectsDelimiter = !isPowerShell && operator.endsWith(Resources.hereDocumentOperator) && !operator.endsWith(Resources.hereStringOperator);
|
|
68
|
+
expectsTarget = !isPowerShell && !expectsDelimiter && Resources.redirectionPattern.test(operator) && Resources.targetedRedirectionPattern.test(operator);
|
|
69
|
+
if (inLoopNames && operator === Resources.listStart) {
|
|
70
|
+
inLoopWords = true;
|
|
71
|
+
expectsCommand = false;
|
|
72
|
+
}
|
|
73
|
+
else if (inLoopWords && operator.startsWith(Resources.listEnd)) {
|
|
74
|
+
inLoopWords = false;
|
|
75
|
+
expectsCommand = true;
|
|
76
|
+
}
|
|
77
|
+
afterModifier = afterModifier && expectsTarget;
|
|
78
|
+
afterRepeat = false;
|
|
79
|
+
inLoopNames = false;
|
|
80
|
+
afterBrace = false;
|
|
81
|
+
index = end;
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
const end = CommandLineTokens.readWord(text, index, isPowerShell, operators, kinds);
|
|
85
|
+
const word = text.slice(index, end);
|
|
86
|
+
if (expectsDelimiter) {
|
|
87
|
+
const isIndented = word.startsWith(Resources.hereDocumentTabsOption);
|
|
88
|
+
const delimiter = isIndented ? word.slice(Resources.hereDocumentTabsOption.length) : word;
|
|
89
|
+
delimiters.push([delimiter.replace(Resources.delimiterQuotingPattern, ""), isIndented]);
|
|
90
|
+
expectsDelimiter = false;
|
|
91
|
+
}
|
|
92
|
+
else if (expectsTarget || expectsOptionValue)
|
|
93
|
+
CommandLineTokens.markWord(word, index, isPowerShell, isZsh, false, kinds);
|
|
94
|
+
else if (afterBlock && Resources.powerShellKeywords.includes(word.toLowerCase())) {
|
|
95
|
+
CommandLineTokens.fill(kinds, index, end, CommandTokenKind.Keyword);
|
|
96
|
+
expectsCommand = false;
|
|
97
|
+
}
|
|
98
|
+
else if (afterBrace && word === Resources.zshAlwaysKeyword) {
|
|
99
|
+
CommandLineTokens.fill(kinds, index, end, CommandTokenKind.Keyword);
|
|
100
|
+
expectsCommand = true;
|
|
101
|
+
}
|
|
102
|
+
else if (expectsCommand && modifiers.includes(word)) {
|
|
103
|
+
CommandLineTokens.fill(kinds, index, end, CommandTokenKind.Keyword);
|
|
104
|
+
afterModifier = true;
|
|
105
|
+
modifier = word;
|
|
106
|
+
}
|
|
107
|
+
else if (afterModifier && word.length > 1 && word.startsWith(Resources.optionStart))
|
|
108
|
+
CommandLineTokens.fill(kinds, index, end, CommandTokenKind.Option);
|
|
109
|
+
else {
|
|
110
|
+
const startsLoop = isZsh && expectsCommand && Resources.zshLoopKeywords.includes(word);
|
|
111
|
+
const startsRepeat = isZsh && expectsCommand && word === Resources.zshRepeatKeyword;
|
|
112
|
+
expectsCommand = CommandLineTokens.markWord(word, index, isPowerShell, isZsh, expectsCommand, kinds) || afterRepeat;
|
|
113
|
+
afterModifier = false;
|
|
114
|
+
afterRepeat = startsRepeat;
|
|
115
|
+
inLoopNames = startsLoop || inLoopNames && word !== Resources.loopListKeyword;
|
|
116
|
+
}
|
|
117
|
+
expectsOptionValue = !expectsTarget && !expectsOptionValue && afterModifier && modifier !== null
|
|
118
|
+
&& Resources.precommandValueOptions.get(modifier)?.includes(word) === true;
|
|
119
|
+
expectsTarget = false;
|
|
120
|
+
afterBrace = isZsh && word === Resources.blockEnd;
|
|
121
|
+
afterBlock = false;
|
|
122
|
+
index = end;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return CommandLineTokens.collect(kinds);
|
|
126
|
+
}
|
|
127
|
+
static readHereDocuments(text, start, delimiters, kinds) {
|
|
128
|
+
if (delimiters.length === 0)
|
|
129
|
+
return start;
|
|
130
|
+
let lineStart = start;
|
|
131
|
+
for (let open = delimiters[0]; open !== undefined && lineStart < text.length; open = delimiters[0]) {
|
|
132
|
+
const found = text.indexOf(Resources.commandLineBreak, lineStart);
|
|
133
|
+
const lineEnd = found === -1 ? text.length : found;
|
|
134
|
+
const line = text.slice(lineStart, lineEnd);
|
|
135
|
+
if ((open[1] ? line.replace(Resources.hereDocumentIndentPattern, "") : line) === open[0])
|
|
136
|
+
delimiters.shift();
|
|
137
|
+
lineStart = lineEnd + 1;
|
|
138
|
+
}
|
|
139
|
+
const end = Math.min(lineStart - 1, text.length);
|
|
140
|
+
CommandLineTokens.fill(kinds, start, end, CommandTokenKind.String);
|
|
141
|
+
return Math.max(end, start);
|
|
142
|
+
}
|
|
143
|
+
static findOperatorEnd(text, start, operators) {
|
|
144
|
+
let end = start + CommandLineTokens.matchAt(Resources.redirectionStartPattern, text, start);
|
|
145
|
+
while (end < text.length && operators.includes(text.charAt(end)))
|
|
146
|
+
end++;
|
|
147
|
+
const operator = text.slice(start, end);
|
|
148
|
+
return operator.endsWith(Resources.duplicateOutputOperator) || operator.endsWith(Resources.duplicateInputOperator)
|
|
149
|
+
? end + CommandLineTokens.matchAt(Resources.duplicatedStreamPattern, text, end) : end;
|
|
150
|
+
}
|
|
151
|
+
static readWord(text, start, isPowerShell, operators, kinds) {
|
|
152
|
+
const escape = isPowerShell ? Resources.powerShellEscape : Resources.posixEscape;
|
|
153
|
+
const variable = isPowerShell ? Resources.powerShellVariablePattern : Resources.posixVariablePattern;
|
|
154
|
+
let index = start;
|
|
155
|
+
while (index < text.length) {
|
|
156
|
+
const character = text.charAt(index);
|
|
157
|
+
if (Resources.commandBlanks.includes(character) || operators.includes(character) || character === Resources.commandLineBreak
|
|
158
|
+
|| character === escape && text.charAt(index + 1) === Resources.commandLineBreak || index > start && text.startsWith(Resources.subexpressionStart, index))
|
|
159
|
+
break;
|
|
160
|
+
if (character === escape)
|
|
161
|
+
index += 2;
|
|
162
|
+
else if (character === Resources.singleQuote)
|
|
163
|
+
index = CommandLineTokens.readSingleQuoted(text, index, isPowerShell, kinds);
|
|
164
|
+
else if (character === Resources.doubleQuote)
|
|
165
|
+
index = CommandLineTokens.readDoubleQuoted(text, index, escape, variable, isPowerShell, kinds);
|
|
166
|
+
else {
|
|
167
|
+
const length = character === Resources.variableStart ? CommandLineTokens.matchAt(variable, text, index) : 0;
|
|
168
|
+
CommandLineTokens.fill(kinds, index, index + length, CommandTokenKind.Variable);
|
|
169
|
+
index += Math.max(length, 1);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return Math.min(index, text.length);
|
|
173
|
+
}
|
|
174
|
+
static readSingleQuoted(text, start, isPowerShell, kinds) {
|
|
175
|
+
let end = start + 1;
|
|
176
|
+
while (end < text.length) {
|
|
177
|
+
if (text.charAt(end) !== Resources.singleQuote)
|
|
178
|
+
end++;
|
|
179
|
+
else if (isPowerShell && text.charAt(end + 1) === Resources.singleQuote)
|
|
180
|
+
end += 2;
|
|
181
|
+
else {
|
|
182
|
+
end++;
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
const closed = Math.min(end, text.length);
|
|
187
|
+
CommandLineTokens.fill(kinds, start, closed, CommandTokenKind.String);
|
|
188
|
+
return closed;
|
|
189
|
+
}
|
|
190
|
+
static readDoubleQuoted(text, start, escape, variable, isPowerShell, kinds) {
|
|
191
|
+
let end = start + 1;
|
|
192
|
+
while (end < text.length) {
|
|
193
|
+
const character = text.charAt(end);
|
|
194
|
+
if (character === escape)
|
|
195
|
+
end += 2;
|
|
196
|
+
else if (character === Resources.doubleQuote && isPowerShell && text.charAt(end + 1) === Resources.doubleQuote)
|
|
197
|
+
end += 2;
|
|
198
|
+
else if (character === Resources.doubleQuote) {
|
|
199
|
+
end++;
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
const length = character === Resources.variableStart ? CommandLineTokens.matchAt(variable, text, end) : 0;
|
|
204
|
+
CommandLineTokens.fill(kinds, end, end + length, CommandTokenKind.Variable);
|
|
205
|
+
end += Math.max(length, 1);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
const closed = Math.min(end, text.length);
|
|
209
|
+
CommandLineTokens.fill(kinds, start, closed, CommandTokenKind.String);
|
|
210
|
+
return closed;
|
|
211
|
+
}
|
|
212
|
+
static markWord(word, start, isPowerShell, isZsh, expectsCommand, kinds) {
|
|
213
|
+
const end = start + word.length;
|
|
214
|
+
if (isZsh && Resources.zshEqualsPattern.test(word)) {
|
|
215
|
+
CommandLineTokens.fill(kinds, start, end, CommandTokenKind.Path);
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
218
|
+
if (isZsh && word === Resources.blockEnd) {
|
|
219
|
+
CommandLineTokens.fill(kinds, start, end, CommandTokenKind.Keyword);
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
if (expectsCommand) {
|
|
223
|
+
if (!isPowerShell && Resources.posixAssignmentPattern.test(word))
|
|
224
|
+
return true;
|
|
225
|
+
if (isPowerShell && word.startsWith(Resources.variableStart))
|
|
226
|
+
return false;
|
|
227
|
+
if (isPowerShell ? Resources.powerShellKeywords.includes(word.toLowerCase())
|
|
228
|
+
: Resources.posixKeywords.includes(word) || isZsh && Resources.zshKeywords.includes(word)) {
|
|
229
|
+
CommandLineTokens.fill(kinds, start, end, CommandTokenKind.Keyword);
|
|
230
|
+
return !isPowerShell && Resources.posixCommandKeywords.includes(word);
|
|
231
|
+
}
|
|
232
|
+
CommandLineTokens.fill(kinds, start, end, CommandTokenKind.Command);
|
|
233
|
+
return false;
|
|
234
|
+
}
|
|
235
|
+
if (word.length > 1 && word.startsWith(Resources.optionStart))
|
|
236
|
+
CommandLineTokens.fill(kinds, start, end, CommandTokenKind.Option);
|
|
237
|
+
else if (CommandLineTokens.isPath(word, isPowerShell))
|
|
238
|
+
CommandLineTokens.fill(kinds, start, end, CommandTokenKind.Path);
|
|
239
|
+
return false;
|
|
240
|
+
}
|
|
241
|
+
static isPath(word, isPowerShell) {
|
|
242
|
+
const separators = isPowerShell ? Resources.powerShellSeparators : Resources.posixSeparators;
|
|
243
|
+
return word.startsWith(Resources.homeStart) || word.startsWith(Resources.currentFolderStart) || [...word].some(t => separators.includes(t));
|
|
244
|
+
}
|
|
245
|
+
static fill(kinds, start, end, kind) {
|
|
246
|
+
for (let index = start; index < Math.min(end, kinds.length); index++)
|
|
247
|
+
kinds[index] ??= kind;
|
|
248
|
+
}
|
|
249
|
+
static matchAt(pattern, text, index) {
|
|
250
|
+
pattern.lastIndex = index;
|
|
251
|
+
return pattern.exec(text)?.[0].length ?? 0;
|
|
252
|
+
}
|
|
253
|
+
static collect(kinds) {
|
|
254
|
+
const tokens = [];
|
|
255
|
+
let start = 0;
|
|
256
|
+
for (let index = 1; index <= kinds.length; index++) {
|
|
257
|
+
const kind = kinds[start];
|
|
258
|
+
if (index < kinds.length && kinds[index] === kind)
|
|
259
|
+
continue;
|
|
260
|
+
if (kind !== null && kind !== undefined)
|
|
261
|
+
tokens.push(new CommandToken(start, index, kind));
|
|
262
|
+
start = index;
|
|
263
|
+
}
|
|
264
|
+
return tokens;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
//# sourceMappingURL=command-line-tokens.js.map
|