@noldova/terminal 0.0.9 → 0.0.10
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 +5 -4
- package/package.json +6 -6
- package/src/api/window.d.ts +64 -0
- package/src/api/window.js +1 -1
- package/src/models/hosted-terminal.js +1 -0
- package/src/models/terminal-events.js +11 -1
- package/src/resources.js +1 -0
- package/src/runtime-part.js +1 -1
- package/src/services/output-batcher.js +3 -0
- package/src/services/terminal-host.js +30 -5
- package/src/services/terminal-mirror.js +1 -0
- package/src/services/terminal-session.js +19 -4
package/module.json
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "terminal",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"displayName": "Terminal",
|
|
5
5
|
"description": "Runs shells in terminal panes, and lets AI agents run commands in them through permission requests.",
|
|
6
6
|
"parts": ["runtime", "window"],
|
|
7
7
|
"pseudoTerminals": true,
|
|
8
8
|
"dependencies": {},
|
|
9
|
-
"noldovaDesktop": ">=0.0.
|
|
9
|
+
"noldovaDesktop": ">=0.0.21 <0.1.0",
|
|
10
10
|
"contributes": {
|
|
11
11
|
"methods": [
|
|
12
12
|
"terminal.shells", "terminal.open", "terminal.close", "terminal.restart", "terminal.sessions", "terminal.attach", "terminal.input", "terminal.resize",
|
|
13
13
|
"terminal.ack", "terminal.visibility", "terminal.detach", "terminal.lines", "terminal.restore", "terminal.closeOwner", "terminal.launch",
|
|
14
14
|
"terminal.run", "terminal.runOutput", "terminal.windowStarted", "terminal.showOwner", "terminal.rename",
|
|
15
|
-
"terminal.complete", "terminal.findCommands"
|
|
15
|
+
"terminal.complete", "terminal.findCommands", "terminal.write"
|
|
16
16
|
],
|
|
17
17
|
"events": [
|
|
18
18
|
"terminal.output", "terminal.exited", "terminal.restarted", "terminal.titleChanged", "terminal.cwdChanged", "terminal.detached",
|
|
19
19
|
"terminal.closed", "terminal.opened", "terminal.launchCommandEnded", "terminal.runOpened", "terminal.runEnded",
|
|
20
|
-
"terminal.renamed", "terminal.commandAdded"
|
|
20
|
+
"terminal.renamed", "terminal.commandAdded", "terminal.commandStarted", "terminal.outputStarted",
|
|
21
|
+
"terminal.commandEnded", "terminal.promptStarted", "terminal.screenChanged"
|
|
21
22
|
],
|
|
22
23
|
"commands": ["terminal.new", "terminal.newWithShell", "terminal.toggle", "terminal.restartShell"],
|
|
23
24
|
"menus": ["terminal.tabRow", "terminal.shellMenu"],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@noldova/terminal",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"description": "The terminal module for apps on Noldova Desktop: terminal panes over real shells, and agent tools that run commands through permission requests.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -37,18 +37,18 @@
|
|
|
37
37
|
"registry": "https://registry.npmjs.org/"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@noldova/terminal.protocol": "0.0.
|
|
41
|
-
"@noldova/terminal.window": "0.0.
|
|
40
|
+
"@noldova/terminal.protocol": "0.0.10",
|
|
41
|
+
"@noldova/terminal.window": "0.0.10",
|
|
42
42
|
"@xterm/addon-serialize": "0.14.0",
|
|
43
43
|
"@xterm/headless": "6.0.0",
|
|
44
44
|
"node-pty": "1.2.0-beta.15"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
|
-
"@noldova/desktop.protocol": ">=0.0.
|
|
48
|
-
"@noldova/desktop.runtime": ">=0.0.
|
|
47
|
+
"@noldova/desktop.protocol": ">=0.0.21 <0.1.0",
|
|
48
|
+
"@noldova/desktop.runtime": ">=0.0.21 <0.1.0",
|
|
49
49
|
"@noldova/context.core": ">=0.0.18 <0.1.0",
|
|
50
50
|
"@noldova/context.exceptions": ">=0.0.18 <0.1.0",
|
|
51
51
|
"@noldova/context.json": ">=0.0.18 <0.1.0"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "2c149af6c1a395e79ed2e344947040781730ae2a"
|
|
54
54
|
}
|
package/src/api/window.d.ts
CHANGED
|
@@ -331,6 +331,70 @@ export { TerminalLaunch } from "@noldova/terminal.window";
|
|
|
331
331
|
*/
|
|
332
332
|
export { LaunchedTerminal } from "@noldova/terminal.window";
|
|
333
333
|
|
|
334
|
+
/**
|
|
335
|
+
* How a launched terminal's text is written, from `@noldova/terminal.window`.
|
|
336
|
+
*
|
|
337
|
+
* @example
|
|
338
|
+
* ```ts
|
|
339
|
+
* import type { ITerminalWriteOptions } from "@noldova/terminal/window";
|
|
340
|
+
*
|
|
341
|
+
* const options: ITerminalWriteOptions = { enter: true };
|
|
342
|
+
* console.log(options.enter);
|
|
343
|
+
* ```
|
|
344
|
+
*/
|
|
345
|
+
export type { ITerminalWriteOptions } from "@noldova/terminal.window";
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* Thrown when a launched terminal's text can't be written because it ended, from `@noldova/terminal.window`.
|
|
349
|
+
*
|
|
350
|
+
* @example
|
|
351
|
+
* ```ts
|
|
352
|
+
* import { TerminalEndedException } from "@noldova/terminal/window";
|
|
353
|
+
*
|
|
354
|
+
* console.log(new TerminalEndedException("session-1").sessionId);
|
|
355
|
+
* ```
|
|
356
|
+
*/
|
|
357
|
+
export { TerminalEndedException } from "@noldova/terminal.window";
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Tells an app the events of a terminal session it reaches, from `@noldova/terminal.window`.
|
|
361
|
+
*
|
|
362
|
+
* @example
|
|
363
|
+
* ```ts
|
|
364
|
+
* import { TerminalListener } from "@noldova/terminal/window";
|
|
365
|
+
*
|
|
366
|
+
* const stop = TerminalListener.listen("session-1", { onCommandEnded: t => console.log(t.exitCode) });
|
|
367
|
+
* stop();
|
|
368
|
+
* ```
|
|
369
|
+
*/
|
|
370
|
+
export { TerminalListener } from "@noldova/terminal.window";
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* A listener for `TerminalListener.listen`: the events of one terminal session, and its detaching, from `@noldova/terminal.window`.
|
|
374
|
+
*
|
|
375
|
+
* @example
|
|
376
|
+
* ```ts
|
|
377
|
+
* import type { ITerminalListener } from "@noldova/terminal/window";
|
|
378
|
+
*
|
|
379
|
+
* const listener: ITerminalListener = { onCommandEnded: t => console.log(t.exitCode), onDetached: () => console.log("stopped hearing the terminal") };
|
|
380
|
+
* console.log(Object.keys(listener));
|
|
381
|
+
* ```
|
|
382
|
+
*/
|
|
383
|
+
export type { ITerminalListener } from "@noldova/terminal.window";
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* The events of one terminal session, and the events' types, from `@noldova/terminal.window`.
|
|
387
|
+
*
|
|
388
|
+
* @example
|
|
389
|
+
* ```ts
|
|
390
|
+
* import type { ITerminalSessionEvents } from "@noldova/terminal/window";
|
|
391
|
+
*
|
|
392
|
+
* const events: ITerminalSessionEvents = { onExited: t => console.log(t.exit.endedBy) };
|
|
393
|
+
* console.log(Object.keys(events));
|
|
394
|
+
* ```
|
|
395
|
+
*/
|
|
396
|
+
export type { ITerminalSessionEvents, TerminalCommandEnded, TerminalCommandStart, TerminalCommandStarted, TerminalCwd, TerminalExited, TerminalReference, TerminalScreen } from "@noldova/terminal.window";
|
|
397
|
+
|
|
334
398
|
/**
|
|
335
399
|
* How a launched terminal's shell ended, from `@noldova/terminal.window`.
|
|
336
400
|
*
|
package/src/api/window.js
CHANGED
|
@@ -5,4 +5,4 @@
|
|
|
5
5
|
* This source code is licensed under the license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
|
-
export { EmbeddedRowsRefusedException, EmbeddedTerminal, LaunchArgumentRefusedException, LaunchedTerminal, LaunchFolderMissingException, LaunchPartInactiveException, LaunchRowsRefusedException, LaunchRowsWithoutTabException, LaunchTitleRefusedException, OwnersProvidedException, RunArgumentRefusedException, RunLinesRefusedException, RunPartInactiveException, RunShellKindsMissingException, StartFolderProvidedException, TerminalEnd, TerminalLaunch, TerminalLauncher, TerminalLaunchRefusedException, TerminalNotActiveException, TerminalLine, TerminalOwners, TerminalRun, TerminalRunBusy, TerminalRunEnd, TerminalRunNotFoundException, TerminalRunNotTypedException, TerminalRunOutcome, TerminalRunOutput, TerminalRunRefusedException, TerminalRunTarget, TerminalShellKind, TerminalStartFolder, TerminalTextRun, TerminalTextStyle, TerminalWindowException, windowPart } from "@noldova/terminal.window";
|
|
8
|
+
export { EmbeddedRowsRefusedException, EmbeddedTerminal, LaunchArgumentRefusedException, LaunchedTerminal, LaunchFolderMissingException, LaunchPartInactiveException, LaunchRowsRefusedException, LaunchRowsWithoutTabException, LaunchTitleRefusedException, OwnersProvidedException, RunArgumentRefusedException, RunLinesRefusedException, RunPartInactiveException, RunShellKindsMissingException, StartFolderProvidedException, TerminalEnd, TerminalLaunch, TerminalLauncher, TerminalLaunchRefusedException, TerminalEndedException, TerminalNotActiveException, TerminalLine, TerminalListener, TerminalOwners, TerminalRun, TerminalRunBusy, TerminalRunEnd, TerminalRunNotFoundException, TerminalRunNotTypedException, TerminalRunOutcome, TerminalRunOutput, TerminalRunRefusedException, TerminalRunTarget, TerminalShellKind, TerminalStartFolder, TerminalTextRun, TerminalTextStyle, TerminalWindowException, windowPart } from "@noldova/terminal.window";
|
|
@@ -19,7 +19,12 @@ export class TerminalEvents {
|
|
|
19
19
|
runEnded;
|
|
20
20
|
renamed;
|
|
21
21
|
commandAdded;
|
|
22
|
-
|
|
22
|
+
commandStarted;
|
|
23
|
+
outputStarted;
|
|
24
|
+
commandEnded;
|
|
25
|
+
promptStarted;
|
|
26
|
+
screenChanged;
|
|
27
|
+
constructor(output, exited, restarted, titleChanged, cwdChanged, detached, closed, opened, launchCommandEnded, runOpened, runEnded, renamed, commandAdded, commandStarted, outputStarted, commandEnded, promptStarted, screenChanged) {
|
|
23
28
|
this.output = output;
|
|
24
29
|
this.exited = exited;
|
|
25
30
|
this.restarted = restarted;
|
|
@@ -33,5 +38,10 @@ export class TerminalEvents {
|
|
|
33
38
|
this.runEnded = runEnded;
|
|
34
39
|
this.renamed = renamed;
|
|
35
40
|
this.commandAdded = commandAdded;
|
|
41
|
+
this.commandStarted = commandStarted;
|
|
42
|
+
this.outputStarted = outputStarted;
|
|
43
|
+
this.commandEnded = commandEnded;
|
|
44
|
+
this.promptStarted = promptStarted;
|
|
45
|
+
this.screenChanged = screenChanged;
|
|
36
46
|
}
|
|
37
47
|
}
|
package/src/resources.js
CHANGED
|
@@ -113,6 +113,7 @@ export class Resources {
|
|
|
113
113
|
static pasteEnd = "\u001b[201~";
|
|
114
114
|
static pasteLineBreaks = /\r?\n/gu;
|
|
115
115
|
static bracketedPastes = /\u001b\[200~[\s\S]*?(?:\u001b\[201~|$)/gu;
|
|
116
|
+
static pasteMarkers = /\u001b\[20[01]~/gu;
|
|
116
117
|
static leadingBlankLines = /^(?:[ \t]*\r?\n)+/u;
|
|
117
118
|
static trailingLineBreaks = /(?:\r?\n)+$/u;
|
|
118
119
|
static whitespace = /\s/gu;
|
package/src/runtime-part.js
CHANGED
|
@@ -52,7 +52,7 @@ export class RuntimePart {
|
|
|
52
52
|
const environment = ShellEnvironment.create(process.platform, process.env, new EnvironmentTools(new LineProcessStarter(context), runner, reader, writer, access, tmpdir()), context.log, Intl.DateTimeFormat().resolvedOptions().locale, MacEnvironment.hasSystemLocaleAsync);
|
|
53
53
|
environment.start();
|
|
54
54
|
try {
|
|
55
|
-
const events = new TerminalEvents(context.declareEvent(TerminalNames.outputEvent), context.declareEvent(TerminalNames.exitedEvent), context.declareEvent(TerminalNames.restartedEvent), context.declareEvent(TerminalNames.titleChangedEvent), context.declareEvent(TerminalNames.cwdChangedEvent), context.declareEvent(TerminalNames.detachedEvent), context.declareEvent(TerminalNames.closedEvent), context.declareEvent(TerminalNames.openedEvent), context.declareEvent(TerminalNames.launchCommandEndedEvent), context.declareEvent(TerminalNames.runOpenedEvent), context.declareEvent(TerminalNames.runEndedEvent), context.declareEvent(TerminalNames.renamedEvent), context.declareEvent(TerminalNames.commandAddedEvent));
|
|
55
|
+
const events = new TerminalEvents(context.declareEvent(TerminalNames.outputEvent), context.declareEvent(TerminalNames.exitedEvent), context.declareEvent(TerminalNames.restartedEvent), context.declareEvent(TerminalNames.titleChangedEvent), context.declareEvent(TerminalNames.cwdChangedEvent), context.declareEvent(TerminalNames.detachedEvent), context.declareEvent(TerminalNames.closedEvent), context.declareEvent(TerminalNames.openedEvent), context.declareEvent(TerminalNames.launchCommandEndedEvent), context.declareEvent(TerminalNames.runOpenedEvent), context.declareEvent(TerminalNames.runEndedEvent), context.declareEvent(TerminalNames.renamedEvent), context.declareEvent(TerminalNames.commandAddedEvent), context.declareEvent(TerminalNames.commandStartedEvent), context.declareEvent(TerminalNames.outputStartedEvent), context.declareEvent(TerminalNames.commandEndedEvent), context.declareEvent(TerminalNames.promptStartedEvent), context.declareEvent(TerminalNames.screenChangedEvent));
|
|
56
56
|
const host = new TerminalHost(new ContextPtySpawner(context), reader, new ShellIntegration(writer, tmpdir(), context.log, access, context.settings, process.platform), new TerminalHistoryFolder(writer, reader, new ProcessSignaller(), tmpdir(), process.pid, context.log, access), new ShellLocator(process.platform, process.arch, process.env, ShellLocator.readUserShell(), reader, runner, context.log), process.platform, release(), new LatestEnvironment(environment, process.env), homedir(), context.log, events, new SavedTerminals(context.database, context.log), new CompletionSource(reader, runner, process.platform, homedir(), context.log));
|
|
57
57
|
for (const name of TerminalNames.methods)
|
|
58
58
|
context.registerMethod(name, { handleAsync: t => host.handleAsync(name, t.payload, RequestClient.fromContext(t)) });
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import "@noldova/context.core";
|
|
9
9
|
import { randomUUID } from "node:crypto";
|
|
10
10
|
import { ArgumentException } from "@noldova/context.exceptions";
|
|
11
|
-
import { EndedBy, Resources as ProtocolResources, TerminalAckParams, TerminalCommandAdded, TerminalCommandEnded, TerminalCompleteParams, TerminalCompletion, TerminalExit, TerminalExited, TerminalFindCommandsParams, TerminalInputParams, TerminalLaunched, TerminalLaunchParams, TerminalLinesParams, TerminalName, TerminalNames, TerminalOpenParams, TerminalOwnerReference, TerminalPaneReference, TerminalReference, TerminalResizeParams, TerminalRestartParams, TerminalRestoreParams, TerminalRunBusy, TerminalRunEnded, TerminalRunEndedBy, TerminalRunOutcome, TerminalRunOutputParams, TerminalRunParams, TerminalRunResult, TerminalSessions, TerminalShellKind, TerminalShells, TerminalShowOwnerParams, TerminalSize, TerminalVisibilityParams, WindowsPty } from "@noldova/terminal.protocol";
|
|
11
|
+
import { EndedBy, Resources as ProtocolResources, TerminalAckParams, TerminalCommandAdded, TerminalCommandEnded, TerminalCompleteParams, TerminalCompletion, TerminalExit, TerminalExited, TerminalFindCommandsParams, TerminalInputParams, TerminalLaunched, TerminalLaunchParams, TerminalLinesParams, TerminalName, TerminalNames, TerminalOpenParams, TerminalOwnerReference, TerminalPaneReference, TerminalReference, TerminalResizeParams, TerminalRestartParams, TerminalRestoreParams, TerminalRunBusy, TerminalRunEnded, TerminalRunEndedBy, TerminalRunOutcome, TerminalRunOutputParams, TerminalRunParams, TerminalRunResult, TerminalSessions, TerminalShellKind, TerminalShells, TerminalShowOwnerParams, TerminalSize, TerminalVisibilityParams, TerminalWriteParams, WindowsPty } from "@noldova/terminal.protocol";
|
|
12
12
|
import { AgentTerminalRestartException } from "../exceptions/agent-terminal-restart.exception.js";
|
|
13
13
|
import { SystemRequirement } from "../enums/system-requirement.js";
|
|
14
14
|
import { ConnectionClosingException } from "../exceptions/connection-closing.exception.js";
|
|
@@ -103,6 +103,9 @@ export class TerminalHost {
|
|
|
103
103
|
case TerminalNames.inputMethod:
|
|
104
104
|
this.input(TerminalInputParams.fromJson(payload), client);
|
|
105
105
|
return null;
|
|
106
|
+
case TerminalNames.writeMethod:
|
|
107
|
+
await this.writeAsync(TerminalWriteParams.fromJson(payload), client);
|
|
108
|
+
return null;
|
|
106
109
|
case TerminalNames.resizeMethod:
|
|
107
110
|
this.resize(TerminalResizeParams.fromJson(payload), client);
|
|
108
111
|
return null;
|
|
@@ -295,14 +298,21 @@ export class TerminalHost {
|
|
|
295
298
|
onCommandEnded: t => {
|
|
296
299
|
this.endLaunchCommand(terminal, t.exitCode);
|
|
297
300
|
this.countRunEnd(terminal, t.exitCode, true);
|
|
301
|
+
publish(this.events.commandEnded, t.toJson());
|
|
298
302
|
},
|
|
299
|
-
onPromptStarted:
|
|
303
|
+
onPromptStarted: t => {
|
|
300
304
|
const offset = terminal.launchCommandOffset;
|
|
301
305
|
if (!Object.isNull(offset) && terminal.session.text.readRange(offset, terminal.session.text.endOffset).includes(Resources.lineFeed))
|
|
302
306
|
this.endLaunchCommand(terminal, null);
|
|
303
307
|
this.countRunEnd(terminal, null, false);
|
|
308
|
+
publish(this.events.promptStarted, t.toJson());
|
|
309
|
+
},
|
|
310
|
+
onCommandStarted: t => {
|
|
311
|
+
publish(this.events.commandStarted, t.toJson());
|
|
312
|
+
this.addCommand(shell.id, t.command);
|
|
304
313
|
},
|
|
305
|
-
|
|
314
|
+
onOutputStarted: t => publish(this.events.outputStarted, t.toJson()),
|
|
315
|
+
onScreenChanged: t => publish(this.events.screenChanged, t.toJson()),
|
|
306
316
|
onDetached: t => publish(this.events.detached, t.toJson()),
|
|
307
317
|
onFailed: (id, message) => this.log.write(Resources.formatStartedCommandUnread(id, message)),
|
|
308
318
|
onResizeUnasked: t => this.log.write(Resources.formatResizeUnasked(t))
|
|
@@ -324,7 +334,7 @@ export class TerminalHost {
|
|
|
324
334
|
async endLaunchesWithoutTabAsync(connection, window, page) {
|
|
325
335
|
await Promise.allSettled([...this.launches].filter(([, t]) => t.connection === connection && t.window === window).map(([t]) => t));
|
|
326
336
|
await Promise.all(this.terminals
|
|
327
|
-
.filter(t => t.connection === connection && t.launcher?.window === window && (Object.isNull(page) || t.launcher.page !== page))
|
|
337
|
+
.filter(t => t.connection === connection && t.launcher?.window === window && (Object.isNull(page) || (t.launcher.page !== page && !t.keepsAlive)))
|
|
328
338
|
.map(t => this.closeTerminalAsync(t.session.sessionId)));
|
|
329
339
|
}
|
|
330
340
|
trackLaunchAsync(launching, client) {
|
|
@@ -397,8 +407,10 @@ export class TerminalHost {
|
|
|
397
407
|
shellId = shell.id;
|
|
398
408
|
}
|
|
399
409
|
const terminal = await this.startTerminalAsync(shellId, folder, params.size, null, params.storedLimit, params.notice, false, null, client, randomUUID(), params.environment, false, params.opensTab, null);
|
|
400
|
-
if (!params.opensTab)
|
|
410
|
+
if (!params.opensTab) {
|
|
401
411
|
terminal.launcher = client;
|
|
412
|
+
terminal.keepsAlive = params.keepsAlive;
|
|
413
|
+
}
|
|
402
414
|
if (!Object.isNull(params.command))
|
|
403
415
|
void this.typeCommandAsync(terminal, params.command).then(t => {
|
|
404
416
|
terminal.launchCommandOffset = terminal.session.text.endOffset;
|
|
@@ -969,6 +981,19 @@ export class TerminalHost {
|
|
|
969
981
|
terminal.keyCount++;
|
|
970
982
|
terminal.session.write(params.data, !isReply);
|
|
971
983
|
}
|
|
984
|
+
async writeAsync(params, client) {
|
|
985
|
+
const terminal = this.findHosted(params.sessionId, client);
|
|
986
|
+
const session = terminal.session;
|
|
987
|
+
const text = params.text.replace(Resources.pasteMarkers, "").replace(Resources.pasteLineBreaks, Resources.enterKey);
|
|
988
|
+
const isBracketed = text.length > 0 && !session.hasExited && await session.isBracketedPasteAsync();
|
|
989
|
+
if (session.hasExited || this.sessions.get(params.sessionId) !== terminal)
|
|
990
|
+
throw new SessionNotFoundException(params.sessionId);
|
|
991
|
+
const written = `${isBracketed ? `${Resources.pasteStart}${text}${Resources.pasteEnd}` : text}${params.isEnter ? Resources.enterKey : ""}`;
|
|
992
|
+
if (written.length === 0)
|
|
993
|
+
return;
|
|
994
|
+
terminal.recordInput(false, written, true);
|
|
995
|
+
session.write(written);
|
|
996
|
+
}
|
|
972
997
|
resize(params, client) {
|
|
973
998
|
const terminal = this.findHosted(params.sessionId, client);
|
|
974
999
|
terminal.session.resize(params.size);
|
|
@@ -40,6 +40,7 @@ export class TerminalMirror {
|
|
|
40
40
|
this.reader = new TerminalLineReader(this.terminal.buffer.normal.getNullCell());
|
|
41
41
|
this.terminal.onData(t => this.listener.onReply(t));
|
|
42
42
|
this.terminal.onTitleChange(t => this.changeTitle(t));
|
|
43
|
+
this.terminal.buffer.onBufferChange(t => this.listener.onScreenChanged(t.type !== Resources.normalBufferType));
|
|
43
44
|
this.terminal.onScroll(() => this.capture());
|
|
44
45
|
this.terminal.parser.registerCsiHandler({ final: Resources.eraseInDisplayFinal }, t => this.eraseSaved(t));
|
|
45
46
|
this.terminal.parser.registerCsiHandler({ prefix: Resources.privatePrefix, final: Resources.eraseInDisplayFinal }, t => this.eraseSaved(t));
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
import "@noldova/context.core";
|
|
9
|
-
import { EndedBy, Resources as ProtocolResources, TerminalAttachment, TerminalCommandEnded, TerminalCwd, TerminalExit, TerminalExited, TerminalInputEdge, TerminalInputMark, TerminalOutput, TerminalPaneReference, TerminalReference, TerminalShellKind, TerminalSize, TerminalSummary, TerminalTitle } from "@noldova/terminal.protocol";
|
|
9
|
+
import { EndedBy, Resources as ProtocolResources, TerminalAttachment, TerminalCommandEnded, TerminalCommandStart, TerminalCommandStarted, TerminalCwd, TerminalExit, TerminalExited, TerminalInputEdge, TerminalInputMark, TerminalOutput, TerminalPaneReference, TerminalReference, TerminalScreen, TerminalShellKind, TerminalSize, TerminalSummary, TerminalTitle } from "@noldova/terminal.protocol";
|
|
10
10
|
import { MarkKind } from "../enums/mark-kind.js";
|
|
11
11
|
import { ShellMark } from "../models/shell-mark.js";
|
|
12
12
|
import { ShellOptionsReply } from "../models/shell-options-reply.js";
|
|
@@ -45,6 +45,8 @@ export class TerminalSession {
|
|
|
45
45
|
restartOffsets = [];
|
|
46
46
|
options = new ShellOptionsQueue();
|
|
47
47
|
isPromptNew = false;
|
|
48
|
+
enteredAt = null;
|
|
49
|
+
idleAt = 0;
|
|
48
50
|
hasAnsweredOptions = false;
|
|
49
51
|
disposal = new AbortController();
|
|
50
52
|
sessionId;
|
|
@@ -73,7 +75,8 @@ export class TerminalSession {
|
|
|
73
75
|
this.mirror = new TerminalMirror(size, this.history, {
|
|
74
76
|
onReply: t => this.terminal.answer(t),
|
|
75
77
|
onParsed: t => this.flow.acknowledgeMirror(t, this.history.backlog),
|
|
76
|
-
onTitleChanged: t => this.listener.onTitleChanged(new TerminalTitle(this.sessionId, t))
|
|
78
|
+
onTitleChanged: t => this.listener.onTitleChanged(new TerminalTitle(this.sessionId, t)),
|
|
79
|
+
onScreenChanged: t => this.listener.onScreenChanged(new TerminalScreen(this.sessionId, t))
|
|
77
80
|
});
|
|
78
81
|
this.batcher = new OutputBatcher({
|
|
79
82
|
onBatch: (offset, data, inputs) => this.listener.onOutput(new TerminalOutput(this.sessionId, offset, data, this.history.stored, inputs))
|
|
@@ -138,8 +141,10 @@ export class TerminalSession {
|
|
|
138
141
|
if (isKey)
|
|
139
142
|
this.options.cancel();
|
|
140
143
|
this.beforeInput();
|
|
141
|
-
for (let lines = data.replace(Resources.bracketedPastes, "").split(Resources.lineBreaks).length - 1; lines > 0; lines--)
|
|
144
|
+
for (let lines = data.replace(Resources.bracketedPastes, "").split(Resources.lineBreaks).length - 1; lines > 0; lines--) {
|
|
142
145
|
this.commands.enterLine();
|
|
146
|
+
this.enteredAt = Date.now();
|
|
147
|
+
}
|
|
143
148
|
this.terminal.write(data);
|
|
144
149
|
}
|
|
145
150
|
typeLine(text) {
|
|
@@ -258,6 +263,7 @@ export class TerminalSession {
|
|
|
258
263
|
}
|
|
259
264
|
receive(data) {
|
|
260
265
|
const marks = this.scanner?.scan(data, this.receivedOffset) ?? [];
|
|
266
|
+
const outputStart = this.batcher.end;
|
|
261
267
|
this.batcher.append(data, marks.flatMap(t => {
|
|
262
268
|
const edge = this.readInputEdge(t);
|
|
263
269
|
return Object.isNull(edge) ? [] : [new TerminalInputMark(t.offset - this.receivedOffset, edge)];
|
|
@@ -283,6 +289,10 @@ export class TerminalSession {
|
|
|
283
289
|
else if (edge === TerminalInputEdge.End)
|
|
284
290
|
this.endInput(mark.kind === MarkKind.OutputStart, mark.value);
|
|
285
291
|
this.applyMark(new ShellMark(mark.kind, mark.value, this.text.endOffset, mark.values));
|
|
292
|
+
if (mark.kind === MarkKind.CommandEnd || mark.kind === MarkKind.PromptStart)
|
|
293
|
+
this.idleAt = Date.now();
|
|
294
|
+
if (mark.kind === MarkKind.OutputStart)
|
|
295
|
+
this.startOutput(mark, outputStart + end);
|
|
286
296
|
}
|
|
287
297
|
this.mirror.write(data.slice(mirrored));
|
|
288
298
|
this.text.append(data.slice(position));
|
|
@@ -290,6 +300,11 @@ export class TerminalSession {
|
|
|
290
300
|
this.receivedOffset += data.length;
|
|
291
301
|
this.changes.notify();
|
|
292
302
|
}
|
|
303
|
+
startOutput(mark, offset) {
|
|
304
|
+
const enteredAt = Math.max(this.enteredAt ?? Date.now(), this.idleAt);
|
|
305
|
+
this.enteredAt = null;
|
|
306
|
+
this.listener.onOutputStarted(new TerminalCommandStart(this.sessionId, offset, enteredAt, TerminalSession.toCommand(mark.value)));
|
|
307
|
+
}
|
|
293
308
|
replacePromptLine(line) {
|
|
294
309
|
const previous = this.promptLine;
|
|
295
310
|
this.promptLine = line;
|
|
@@ -390,7 +405,7 @@ export class TerminalSession {
|
|
|
390
405
|
endInput(startsCommand, command) {
|
|
391
406
|
void this.mirror.endInput().then(t => {
|
|
392
407
|
if (startsCommand && !Object.isNull(t))
|
|
393
|
-
this.listener.onCommandStarted(TerminalSession.toCommand(command) ?? t);
|
|
408
|
+
this.listener.onCommandStarted(new TerminalCommandStarted(this.sessionId, TerminalSession.toCommand(command) ?? t));
|
|
394
409
|
}).catch((error) => this.listener.onFailed(this.sessionId, FailureText.read(error)));
|
|
395
410
|
}
|
|
396
411
|
readInputEdge(mark) {
|