@noldova/terminal 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/module.json +2 -2
- package/package.json +8 -8
- package/src/exceptions/connection-closing.exception.js +14 -0
- package/src/exceptions/read-dropped.exception.js +14 -0
- package/src/interfaces/i-queued-read.js +8 -0
- package/src/models/hosted-terminal.js +27 -1
- package/src/models/shared-read.js +33 -0
- package/src/models/terminal-opening.js +18 -0
- package/src/resources.js +15 -1
- package/src/runtime-part.js +2 -1
- package/src/services/bounded-reads.js +14 -6
- package/src/services/command-tracker.js +5 -0
- package/src/services/completion-source.js +7 -3
- package/src/services/context-pty-process.js +2 -2
- package/src/services/deferred-pty-process.js +2 -2
- package/src/services/file-system.reader.js +4 -1
- package/src/services/latest-environment.js +31 -0
- package/src/services/pseudo-terminal.js +25 -6
- package/src/services/shared-reads.js +42 -15
- package/src/services/shell-command.js +8 -3
- package/src/services/shell-integration.js +48 -34
- package/src/services/terminal-host.js +242 -64
- package/src/services/terminal-session.js +12 -3
- package/src/services/windows-environment.js +1 -1
|
@@ -12,6 +12,7 @@ import { OutputChunk } from "../tools/models/output-chunk.js";
|
|
|
12
12
|
export class ShellCommand {
|
|
13
13
|
session;
|
|
14
14
|
line;
|
|
15
|
+
run;
|
|
15
16
|
isKilled = false;
|
|
16
17
|
givenUp = null;
|
|
17
18
|
method = RunMethod.InShell;
|
|
@@ -19,6 +20,7 @@ export class ShellCommand {
|
|
|
19
20
|
constructor(session, command, timeoutMilliseconds, logFile) {
|
|
20
21
|
this.session = session;
|
|
21
22
|
this.logFile = logFile;
|
|
23
|
+
this.run = session.run;
|
|
22
24
|
this.line = session.typeLine(command);
|
|
23
25
|
if (timeoutMilliseconds > 0) {
|
|
24
26
|
const limit = new AbortController();
|
|
@@ -35,7 +37,7 @@ export class ShellCommand {
|
|
|
35
37
|
return CommandStatus.Killed;
|
|
36
38
|
if (this.tracked?.hasEnded === true || this.unmarkedEnd !== null)
|
|
37
39
|
return this.isKilled ? CommandStatus.Killed : CommandStatus.Exited;
|
|
38
|
-
if (this.session.hasExited)
|
|
40
|
+
if (this.restartEnd !== null || this.session.hasExited)
|
|
39
41
|
return CommandStatus.Killed;
|
|
40
42
|
return this.session.text.isAwaitingSecret ? CommandStatus.AwaitingInput : CommandStatus.Running;
|
|
41
43
|
}
|
|
@@ -46,7 +48,7 @@ export class ShellCommand {
|
|
|
46
48
|
return this.givenUp === null ? this.tracked?.cwd ?? null : null;
|
|
47
49
|
}
|
|
48
50
|
get hasEnded() {
|
|
49
|
-
return this.givenUp !== null || this.tracked?.hasEnded === true || this.unmarkedEnd !== null || this.session.hasExited;
|
|
51
|
+
return this.givenUp !== null || this.tracked?.hasEnded === true || this.unmarkedEnd !== null || this.restartEnd !== null || this.session.hasExited;
|
|
50
52
|
}
|
|
51
53
|
get outputStart() {
|
|
52
54
|
if (this.givenUp !== null)
|
|
@@ -55,7 +57,10 @@ export class ShellCommand {
|
|
|
55
57
|
return tracked?.hasOutputStart === true ? tracked.outputStart : this.line.startOffset;
|
|
56
58
|
}
|
|
57
59
|
get outputEnd() {
|
|
58
|
-
return this.givenUp?.[1] ?? this.tracked?.outputEnd ?? this.unmarkedEnd ?? this.session.text.endOffset;
|
|
60
|
+
return this.givenUp?.[1] ?? this.tracked?.outputEnd ?? this.unmarkedEnd ?? this.restartEnd ?? this.session.text.endOffset;
|
|
61
|
+
}
|
|
62
|
+
get restartEnd() {
|
|
63
|
+
return this.session.endOfRun(this.run);
|
|
59
64
|
}
|
|
60
65
|
get unmarkedEnd() {
|
|
61
66
|
return this.line.endOffset;
|
|
@@ -30,40 +30,9 @@ export class ShellIntegration {
|
|
|
30
30
|
this.platform = platform;
|
|
31
31
|
}
|
|
32
32
|
async prepareAsync(shell, nonce, environment, note = null) {
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (family === ShellFamily.Other)
|
|
37
|
-
return new ShellLaunch(shell.file, shell.args, {}, null);
|
|
38
|
-
if (family === ShellFamily.PowerShell)
|
|
39
|
-
await this.makeSharedMemoryFolderAsync(environment);
|
|
40
|
-
const folder = await this.writeScriptsOrNullAsync();
|
|
41
|
-
const nonceFile = folder === null ? null : await this.writeNonceOrNullAsync(folder, nonce);
|
|
42
|
-
if (folder === null || nonceFile === null)
|
|
43
|
-
return ShellIntegration.toPlainLaunch(shell, family);
|
|
44
|
-
const noteVariables = note === null ? {} : { [Resources.noteVariable]: note };
|
|
45
|
-
if (family === ShellFamily.PowerShell)
|
|
46
|
-
return new ShellLaunch(shell.file, [...shell.args, ...Resources.powerShellIntegrationArguments, ShellIntegration.encode([Resources.shellIntegrationPowerShellNonce, Resources.shellIntegrationPowerShellNote, Resources.shellIntegrationPowerShellProfiles, shell.startCommand,
|
|
47
|
-
Resources.shellIntegrationPowerShellScript].filter(t => t !== null).join(Resources.lineFeed))], {
|
|
48
|
-
[Resources.nonceFileVariable]: nonceFile,
|
|
49
|
-
...noteVariables
|
|
50
|
-
}, nonce, nonceFile, note !== null);
|
|
51
|
-
if (family === ShellFamily.Bash) {
|
|
52
|
-
const bashScript = path.join(folder, Resources.bashScriptFile).replaceAll(Resources.windowsSeparator, Resources.posixSeparator);
|
|
53
|
-
const isLogin = shell.args.some(t => Resources.loginArguments.includes(t));
|
|
54
|
-
return new ShellLaunch(shell.file, [Resources.initFileArgument, bashScript, Resources.interactiveArgument], {
|
|
55
|
-
[Resources.nonceFileVariable]: nonceFile.replaceAll(Resources.windowsSeparator, Resources.posixSeparator),
|
|
56
|
-
...(isLogin ? { [Resources.loginVariable]: Resources.shellIntegrationLoginValue } : {}),
|
|
57
|
-
...noteVariables
|
|
58
|
-
}, nonce, nonceFile, note !== null);
|
|
59
|
-
}
|
|
60
|
-
const userFolder = environment[Resources.zdotdirVariable];
|
|
61
|
-
return new ShellLaunch(shell.file, shell.args, {
|
|
62
|
-
[Resources.nonceFileVariable]: nonceFile,
|
|
63
|
-
[Resources.zdotdirVariable]: folder,
|
|
64
|
-
...(userFolder === undefined ? {} : { [Resources.userZdotdirVariable]: userFolder }),
|
|
65
|
-
...noteVariables
|
|
66
|
-
}, nonce, nonceFile, note !== null);
|
|
33
|
+
const launch = await this.prepareShellAsync(shell, nonce, environment, note);
|
|
34
|
+
return this.platform === Resources.macPlatform && ShellIntegration.toFamily(shell.file) === ShellFamily.PowerShell
|
|
35
|
+
? ShellIntegration.toPowerShellLoginLaunch(launch) : launch;
|
|
67
36
|
}
|
|
68
37
|
watch(process, launch) {
|
|
69
38
|
const { nonce, nonceFile } = launch;
|
|
@@ -113,6 +82,42 @@ export class ShellIntegration {
|
|
|
113
82
|
this.log.write(Resources.formatSuggestionsUnwatched(FailureText.read(error)));
|
|
114
83
|
}
|
|
115
84
|
}
|
|
85
|
+
async prepareShellAsync(shell, nonce, environment, note) {
|
|
86
|
+
const family = ShellIntegration.toFamily(shell.file);
|
|
87
|
+
if (family === ShellFamily.CommandPrompt)
|
|
88
|
+
return ShellIntegration.toCommandPromptLaunch(shell, note);
|
|
89
|
+
if (family === ShellFamily.Other)
|
|
90
|
+
return new ShellLaunch(shell.file, shell.args, {}, null);
|
|
91
|
+
if (family === ShellFamily.PowerShell)
|
|
92
|
+
await this.makeSharedMemoryFolderAsync(environment);
|
|
93
|
+
const folder = await this.writeScriptsOrNullAsync();
|
|
94
|
+
const nonceFile = folder === null ? null : await this.writeNonceOrNullAsync(folder, nonce);
|
|
95
|
+
if (folder === null || nonceFile === null)
|
|
96
|
+
return ShellIntegration.toPlainLaunch(shell, family);
|
|
97
|
+
const noteVariables = note === null ? {} : { [Resources.noteVariable]: note };
|
|
98
|
+
if (family === ShellFamily.PowerShell)
|
|
99
|
+
return new ShellLaunch(shell.file, [...shell.args, ...Resources.powerShellIntegrationArguments, ShellIntegration.encode([Resources.shellIntegrationPowerShellNonce, Resources.shellIntegrationPowerShellNote, Resources.shellIntegrationPowerShellProfiles, shell.startCommand,
|
|
100
|
+
Resources.shellIntegrationPowerShellScript].filter(t => t !== null).join(Resources.lineFeed))], {
|
|
101
|
+
[Resources.nonceFileVariable]: nonceFile,
|
|
102
|
+
...noteVariables
|
|
103
|
+
}, nonce, nonceFile, note !== null);
|
|
104
|
+
if (family === ShellFamily.Bash) {
|
|
105
|
+
const bashScript = path.join(folder, Resources.bashScriptFile).replaceAll(Resources.windowsSeparator, Resources.posixSeparator);
|
|
106
|
+
const isLogin = shell.args.some(t => Resources.loginArguments.includes(t));
|
|
107
|
+
return new ShellLaunch(shell.file, [Resources.initFileArgument, bashScript, Resources.interactiveArgument], {
|
|
108
|
+
[Resources.nonceFileVariable]: nonceFile.replaceAll(Resources.windowsSeparator, Resources.posixSeparator),
|
|
109
|
+
...(isLogin ? { [Resources.loginVariable]: Resources.shellIntegrationLoginValue } : {}),
|
|
110
|
+
...noteVariables
|
|
111
|
+
}, nonce, nonceFile, note !== null);
|
|
112
|
+
}
|
|
113
|
+
const userFolder = environment[Resources.zdotdirVariable];
|
|
114
|
+
return new ShellLaunch(shell.file, shell.args, {
|
|
115
|
+
[Resources.nonceFileVariable]: nonceFile,
|
|
116
|
+
[Resources.zdotdirVariable]: folder,
|
|
117
|
+
...(userFolder === undefined ? {} : { [Resources.userZdotdirVariable]: userFolder }),
|
|
118
|
+
...noteVariables
|
|
119
|
+
}, nonce, nonceFile, note !== null);
|
|
120
|
+
}
|
|
116
121
|
makeSharedMemoryFolderAsync(environment) {
|
|
117
122
|
const runtimeFolder = environment[Resources.runtimeFolderVariable];
|
|
118
123
|
if (this.platform !== Resources.linuxPlatform || runtimeFolder === undefined || !path.posix.isAbsolute(runtimeFolder))
|
|
@@ -185,6 +190,15 @@ export class ShellIntegration {
|
|
|
185
190
|
return new ShellLaunch(shell.file, shell.args, {}, null);
|
|
186
191
|
return new ShellLaunch(shell.file, [...shell.args, ...Resources.powerShellArguments, ShellIntegration.encode(shell.startCommand)], {}, null);
|
|
187
192
|
}
|
|
193
|
+
static toPowerShellLoginLaunch(launch) {
|
|
194
|
+
const [first, ...rest] = [launch.args].flat();
|
|
195
|
+
if (first === undefined || !ShellIntegration.isPowerShellLogin(first))
|
|
196
|
+
return launch;
|
|
197
|
+
return new ShellLaunch(Resources.powerShellLoginShell, [...Resources.powerShellLoginShellArguments, launch.file, ...rest], { ...launch.environment, [Resources.powerShellLoginCheckedVariable]: Resources.powerShellLoginCheckedValue }, launch.nonce, launch.nonceFile, launch.printsNote);
|
|
198
|
+
}
|
|
199
|
+
static isPowerShellLogin(argument) {
|
|
200
|
+
return argument.length > 1 && Resources.powerShellLoginParameter.startsWith(argument.toLowerCase());
|
|
201
|
+
}
|
|
188
202
|
static toFamily(file) {
|
|
189
203
|
const name = path.win32.parse(file).name.toLowerCase();
|
|
190
204
|
switch (name) {
|