@noldova/terminal 0.0.0-stage → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +10 -2
- package/menus.json +53 -0
- package/module.json +28 -0
- package/package.json +50 -4
- package/settings.json +83 -0
- package/src/api/index.d.ts +131 -0
- package/src/api/index.js +11 -0
- package/src/api/window.d.ts +467 -0
- package/src/api/window.js +8 -0
- package/src/enums/escape-state.js +15 -0
- package/src/enums/escape-stripper-state.js +15 -0
- package/src/enums/mark-kind.js +18 -0
- package/src/enums/shell-family.js +14 -0
- package/src/enums/system-requirement.js +11 -0
- package/src/exceptions/agent-terminal-restart.exception.js +16 -0
- package/src/exceptions/command-exited.exception.js +23 -0
- package/src/exceptions/command-failed.exception.js +13 -0
- package/src/exceptions/command-not-started.exception.js +17 -0
- package/src/exceptions/command-output-too-long.exception.js +18 -0
- package/src/exceptions/command-timed-out.exception.js +18 -0
- package/src/exceptions/command-variable-not-set.exception.js +18 -0
- package/src/exceptions/default-shell-not-found.exception.js +14 -0
- package/src/exceptions/environment-export-invalid.exception.js +14 -0
- package/src/exceptions/environment-key-unreadable.exception.js +17 -0
- package/src/exceptions/environment-unreadable.exception.js +13 -0
- package/src/exceptions/folder-not-found.exception.js +16 -0
- package/src/exceptions/host-ended.exception.js +14 -0
- package/src/exceptions/session-not-found.exception.js +18 -0
- package/src/exceptions/shell-kind-not-found.exception.js +16 -0
- package/src/exceptions/shell-not-found.exception.js +18 -0
- package/src/exceptions/shells-unreadable.exception.js +13 -0
- package/src/exceptions/stored-lines-damaged.exception.js +15 -0
- package/src/exceptions/stored-lines-unwritable.exception.js +15 -0
- package/src/exceptions/system-root-missing.exception.js +14 -0
- package/src/exceptions/terminal.exception.js +13 -0
- package/src/exceptions/unknown-method.exception.js +16 -0
- package/src/exceptions/unsupported-system.exception.js +18 -0
- package/src/exceptions/visual-studio-unreadable.exception.js +15 -0
- package/src/exceptions/wsl-distributions-unreadable.exception.js +15 -0
- package/src/interfaces/i-command-runner.js +8 -0
- package/src/interfaces/i-disposable.js +8 -0
- package/src/interfaces/i-environment-source.js +8 -0
- package/src/interfaces/i-file-system-reader.js +8 -0
- package/src/interfaces/i-file-system-writer.js +8 -0
- package/src/interfaces/i-flow-controller-listener.js +8 -0
- package/src/interfaces/i-folder-access.js +8 -0
- package/src/interfaces/i-line-process-listener.js +8 -0
- package/src/interfaces/i-line-process-starter.js +8 -0
- package/src/interfaces/i-line-process.js +8 -0
- package/src/interfaces/i-output-batcher-listener.js +8 -0
- package/src/interfaces/i-process-signaller.js +8 -0
- package/src/interfaces/i-pseudo-terminal-listener.js +8 -0
- package/src/interfaces/i-pty-exit-event.js +8 -0
- package/src/interfaces/i-pty-process.js +8 -0
- package/src/interfaces/i-pty-spawner.js +8 -0
- package/src/interfaces/i-terminal-mirror-listener.js +8 -0
- package/src/interfaces/i-terminal-session-listener.js +8 -0
- package/src/interfaces/i-waiting-options-request.js +8 -0
- package/src/models/command-listing.js +17 -0
- package/src/models/completion-candidate.js +19 -0
- package/src/models/environment-tools.js +23 -0
- package/src/models/environment-variable.js +15 -0
- package/src/models/folder-entry.js +15 -0
- package/src/models/hosted-terminal.js +116 -0
- package/src/models/mirror-line.js +27 -0
- package/src/models/mirror-snapshot.js +19 -0
- package/src/models/one-shot-launch.js +42 -0
- package/src/models/pane-progress.js +15 -0
- package/src/models/powershell-cmdlet.js +21 -0
- package/src/models/powershell-lookup.js +17 -0
- package/src/models/powershell-parameter.js +19 -0
- package/src/models/registry-value.js +15 -0
- package/src/models/request-client.js +23 -0
- package/src/models/saved-terminal.js +25 -0
- package/src/models/shell-launch.js +23 -0
- package/src/models/shell-line.js +21 -0
- package/src/models/shell-mark.js +19 -0
- package/src/models/shell-options-reply.js +17 -0
- package/src/models/shell.js +29 -0
- package/src/models/started-shell.js +21 -0
- package/src/models/system-shortfall.js +15 -0
- package/src/models/terminal-events.js +37 -0
- package/src/models/terminal-history-paths.js +15 -0
- package/src/models/terminal-prompt.js +28 -0
- package/src/models/tracked-command.js +26 -0
- package/src/models/typed-line.js +40 -0
- package/src/models/visual-studio-installation.js +22 -0
- package/src/models/waiting-run.js +25 -0
- package/src/resources.js +1725 -0
- package/src/runtime-part.js +84 -0
- package/src/services/agent-terminal.js +137 -0
- package/src/services/agent-terminals.js +55 -0
- package/src/services/bounded-reads.js +57 -0
- package/src/services/change-signal.js +33 -0
- package/src/services/command-history.js +20 -0
- package/src/services/command-runner.js +67 -0
- package/src/services/command-tracker.js +161 -0
- package/src/services/completion-source.js +316 -0
- package/src/services/context-pty-process.js +79 -0
- package/src/services/context-pty-spawner.js +26 -0
- package/src/services/deferred-pty-process.js +94 -0
- package/src/services/escape-sequence-tracker.js +126 -0
- package/src/services/escape-stripper.js +91 -0
- package/src/services/failure-text.js +15 -0
- package/src/services/file-system-writer.js +35 -0
- package/src/services/file-system.reader.js +54 -0
- package/src/services/flow-controller.js +102 -0
- package/src/services/folder-access.js +19 -0
- package/src/services/inherited-environment.js +20 -0
- package/src/services/line-process-starter.js +17 -0
- package/src/services/line-process.js +72 -0
- package/src/services/log-file.js +57 -0
- package/src/services/mac-environment.js +81 -0
- package/src/services/mac-folder-access.js +17 -0
- package/src/services/mark-scanner.js +94 -0
- package/src/services/one-shot-command.js +119 -0
- package/src/services/output-batcher.js +62 -0
- package/src/services/output-log.js +50 -0
- package/src/services/powershell-binding.js +61 -0
- package/src/services/process-signaller.js +19 -0
- package/src/services/pseudo-terminal.js +54 -0
- package/src/services/registry-export.js +108 -0
- package/src/services/resize-wakeup.js +39 -0
- package/src/services/saved-terminals.js +52 -0
- package/src/services/shared-reads.js +41 -0
- package/src/services/shell-command.js +90 -0
- package/src/services/shell-environment.js +20 -0
- package/src/services/shell-integration.js +207 -0
- package/src/services/shell-locator.js +177 -0
- package/src/services/shell-options-queue.js +34 -0
- package/src/services/shell-words.js +80 -0
- package/src/services/system-requirements.js +46 -0
- package/src/services/terminal-audience.js +83 -0
- package/src/services/terminal-history-folder.js +97 -0
- package/src/services/terminal-history-segment.js +109 -0
- package/src/services/terminal-history.js +130 -0
- package/src/services/terminal-host.js +931 -0
- package/src/services/terminal-line-reader.js +101 -0
- package/src/services/terminal-mirror.js +221 -0
- package/src/services/terminal-owner.service.js +27 -0
- package/src/services/terminal-session.js +398 -0
- package/src/services/visual-studio.reader.js +76 -0
- package/src/services/windows-environment.js +218 -0
- package/src/services/windows-folder-access.js +23 -0
- package/src/services/wsl-distribution.reader.js +49 -0
- package/src/services/xterm-headless-loader.js +14 -0
- package/src/tools/enums/command-status.js +13 -0
- package/src/tools/enums/run-method.js +11 -0
- package/src/tools/exceptions/abort-reason-unknown.exception.js +17 -0
- package/src/tools/exceptions/stale-terminal.exception.js +16 -0
- package/src/tools/interfaces/i-agent-command.js +8 -0
- package/src/tools/interfaces/i-agent-terminal.js +8 -0
- package/src/tools/interfaces/i-agent-terminals.js +8 -0
- package/src/tools/interfaces/i-output-source.js +8 -0
- package/src/tools/interfaces/i-terminal-prompt.js +8 -0
- package/src/tools/models/agent-terminal-access.js +25 -0
- package/src/tools/models/agent-terminal-opening.js +29 -0
- package/src/tools/models/command-line.js +28 -0
- package/src/tools/models/key-sequence.js +27 -0
- package/src/tools/models/output-chunk.js +18 -0
- package/src/tools/models/output-excerpt.js +31 -0
- package/src/tools/models/permission-ask.js +34 -0
- package/src/tools/models/read-cursor.js +26 -0
- package/src/tools/models/read-cursors.js +25 -0
- package/src/tools/models/terminal-open-input.js +34 -0
- package/src/tools/models/terminal-output-report.js +61 -0
- package/src/tools/models/terminal-read-input.js +39 -0
- package/src/tools/models/terminal-run-input.js +52 -0
- package/src/tools/models/terminal-target-input.js +34 -0
- package/src/tools/models/terminal-write-input.js +38 -0
- package/src/tools/models/tool-call-context.js +61 -0
- package/src/tools/services/abort-reason-reader.js +25 -0
- package/src/tools/services/permission-details.js +42 -0
- package/src/tools/services/permission-gate.js +35 -0
- package/src/tools/services/signal-race.js +24 -0
- package/src/tools/services/terminal-access-policy.js +57 -0
- package/src/tools/services/terminal-close-tool.js +57 -0
- package/src/tools/services/terminal-interrupt-tool.js +57 -0
- package/src/tools/services/terminal-list-tool.js +69 -0
- package/src/tools/services/terminal-open-tool.js +71 -0
- package/src/tools/services/terminal-read-tool.js +58 -0
- package/src/tools/services/terminal-run-tool.js +78 -0
- package/src/tools/services/terminal-text-escaper.js +40 -0
- package/src/tools/services/terminal-tool.js +47 -0
- package/src/tools/services/terminal-tools.js +60 -0
- package/src/tools/services/terminal-write-tool.js +75 -0
- package/src/tools/services/tool-failures.js +28 -0
- package/src/tools/services/tool-results.js +13 -0
|
@@ -0,0 +1,101 @@
|
|
|
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, TerminalLine, TerminalTextRun, TerminalTextStyle } from "@noldova/terminal.protocol";
|
|
9
|
+
import { Resources } from "../resources.js";
|
|
10
|
+
export class TerminalLineReader {
|
|
11
|
+
cell;
|
|
12
|
+
constructor(cell) {
|
|
13
|
+
this.cell = cell;
|
|
14
|
+
}
|
|
15
|
+
read(line, isContinued) {
|
|
16
|
+
const end = isContinued ? line.length : this.contentEnd(line);
|
|
17
|
+
return this.isPlain(line, end) ? TerminalLineReader.readPlain(line, end) : this.readRuns(line, end);
|
|
18
|
+
}
|
|
19
|
+
isPlain(line, end) {
|
|
20
|
+
for (let x = 0; x < end; x++)
|
|
21
|
+
if (line.getCell(x, this.cell)?.isAttributeDefault() === false)
|
|
22
|
+
return false;
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
readRuns(line, end) {
|
|
26
|
+
const runs = [];
|
|
27
|
+
let text = "";
|
|
28
|
+
let length = 0;
|
|
29
|
+
let foreground = ProtocolResources.defaultColor;
|
|
30
|
+
let background = ProtocolResources.defaultColor;
|
|
31
|
+
let style = 0;
|
|
32
|
+
for (let x = 0; x < end; x++) {
|
|
33
|
+
const cell = line.getCell(x, this.cell);
|
|
34
|
+
if (cell === undefined || cell.getWidth() === 0)
|
|
35
|
+
continue;
|
|
36
|
+
const chars = cell.getChars() || Resources.blankCell;
|
|
37
|
+
const isPlain = cell.isAttributeDefault();
|
|
38
|
+
const cellForeground = isPlain ? ProtocolResources.defaultColor : TerminalLineReader.foregroundOf(cell);
|
|
39
|
+
const cellBackground = isPlain ? ProtocolResources.defaultColor : TerminalLineReader.backgroundOf(cell);
|
|
40
|
+
const cellStyle = isPlain ? 0 : TerminalLineReader.styleOf(cell);
|
|
41
|
+
if (length > 0 && (cellForeground !== foreground || cellBackground !== background || cellStyle !== style)) {
|
|
42
|
+
runs.push(new TerminalTextRun(length, foreground, background, style));
|
|
43
|
+
length = 0;
|
|
44
|
+
}
|
|
45
|
+
foreground = cellForeground;
|
|
46
|
+
background = cellBackground;
|
|
47
|
+
style = cellStyle;
|
|
48
|
+
text += chars;
|
|
49
|
+
length += chars.length;
|
|
50
|
+
}
|
|
51
|
+
runs.push(new TerminalTextRun(length, foreground, background, style));
|
|
52
|
+
return new TerminalLine(text, line.isWrapped, runs);
|
|
53
|
+
}
|
|
54
|
+
static readPlain(line, end) {
|
|
55
|
+
const text = line.translateToString(false, 0, end);
|
|
56
|
+
const runs = text.length === 0 ? [] : [new TerminalTextRun(text.length, ProtocolResources.defaultColor, ProtocolResources.defaultColor, 0)];
|
|
57
|
+
return new TerminalLine(text, line.isWrapped, runs);
|
|
58
|
+
}
|
|
59
|
+
contentEnd(line) {
|
|
60
|
+
let end = line.length;
|
|
61
|
+
while (end > 0 && this.isBlank(line.getCell(end - 1, this.cell)))
|
|
62
|
+
end -= 1;
|
|
63
|
+
return end;
|
|
64
|
+
}
|
|
65
|
+
isBlank(cell) {
|
|
66
|
+
return cell !== undefined && ((cell.getCode() === 0 && cell.isAttributeDefault()) || (cell.getChars().trim().length === 0 && cell.isBgDefault() &&
|
|
67
|
+
!cell.isInverse() && !cell.isUnderline() && !cell.isStrikethrough() && !cell.isOverline()));
|
|
68
|
+
}
|
|
69
|
+
static foregroundOf(cell) {
|
|
70
|
+
if (cell.isFgDefault())
|
|
71
|
+
return ProtocolResources.defaultColor;
|
|
72
|
+
return cell.isFgRGB() ? ProtocolResources.rgbColor + cell.getFgColor() : cell.getFgColor();
|
|
73
|
+
}
|
|
74
|
+
static backgroundOf(cell) {
|
|
75
|
+
if (cell.isBgDefault())
|
|
76
|
+
return ProtocolResources.defaultColor;
|
|
77
|
+
return cell.isBgRGB() ? ProtocolResources.rgbColor + cell.getBgColor() : cell.getBgColor();
|
|
78
|
+
}
|
|
79
|
+
static styleOf(cell) {
|
|
80
|
+
let style = 0;
|
|
81
|
+
if (cell.isBold())
|
|
82
|
+
style |= TerminalTextStyle.Bold;
|
|
83
|
+
if (cell.isDim())
|
|
84
|
+
style |= TerminalTextStyle.Dim;
|
|
85
|
+
if (cell.isItalic())
|
|
86
|
+
style |= TerminalTextStyle.Italic;
|
|
87
|
+
if (cell.isUnderline())
|
|
88
|
+
style |= TerminalTextStyle.Underline;
|
|
89
|
+
if (cell.isBlink())
|
|
90
|
+
style |= TerminalTextStyle.Blink;
|
|
91
|
+
if (cell.isInverse())
|
|
92
|
+
style |= TerminalTextStyle.Inverse;
|
|
93
|
+
if (cell.isInvisible())
|
|
94
|
+
style |= TerminalTextStyle.Invisible;
|
|
95
|
+
if (cell.isStrikethrough())
|
|
96
|
+
style |= TerminalTextStyle.Strikethrough;
|
|
97
|
+
if (cell.isOverline())
|
|
98
|
+
style |= TerminalTextStyle.Overline;
|
|
99
|
+
return style;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -0,0 +1,221 @@
|
|
|
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, TerminalInputStart, TerminalRunOutput } from "@noldova/terminal.protocol";
|
|
9
|
+
import { SerializeAddon } from "@xterm/addon-serialize";
|
|
10
|
+
import { MirrorLine } from "../models/mirror-line.js";
|
|
11
|
+
import { MirrorSnapshot } from "../models/mirror-snapshot.js";
|
|
12
|
+
import { Resources } from "../resources.js";
|
|
13
|
+
import { EscapeSequenceTracker } from "./escape-sequence-tracker.js";
|
|
14
|
+
import { TerminalLineReader } from "./terminal-line-reader.js";
|
|
15
|
+
import { XtermHeadlessLoader } from "./xterm-headless-loader.js";
|
|
16
|
+
export class TerminalMirror {
|
|
17
|
+
terminal;
|
|
18
|
+
serializer;
|
|
19
|
+
tracker = new EscapeSequenceTracker();
|
|
20
|
+
history;
|
|
21
|
+
reader;
|
|
22
|
+
listener;
|
|
23
|
+
anchors = new Map();
|
|
24
|
+
writtenOffset = 0;
|
|
25
|
+
removedLines = 0;
|
|
26
|
+
currentTitle = "";
|
|
27
|
+
oldest = null;
|
|
28
|
+
oldestMarker = null;
|
|
29
|
+
inputStart = undefined;
|
|
30
|
+
inputColumn = 0;
|
|
31
|
+
rightPrompt = null;
|
|
32
|
+
isDisposed = false;
|
|
33
|
+
constructor(size, history, listener) {
|
|
34
|
+
this.history = history;
|
|
35
|
+
this.listener = listener;
|
|
36
|
+
this.terminal = XtermHeadlessLoader.createTerminal({ allowProposedApi: true, cols: size.columns, rows: size.rows, scrollback: Resources.scrollback });
|
|
37
|
+
this.serializer = new SerializeAddon();
|
|
38
|
+
this.terminal.loadAddon(this.serializer);
|
|
39
|
+
this.reader = new TerminalLineReader(this.terminal.buffer.normal.getNullCell());
|
|
40
|
+
this.terminal.onData(t => this.listener.onReply(t));
|
|
41
|
+
this.terminal.onTitleChange(t => this.changeTitle(t));
|
|
42
|
+
this.terminal.onScroll(() => this.capture());
|
|
43
|
+
this.terminal.parser.registerCsiHandler({ final: Resources.eraseInDisplayFinal }, t => this.eraseSaved(t));
|
|
44
|
+
this.terminal.parser.registerCsiHandler({ prefix: Resources.privatePrefix, final: Resources.eraseInDisplayFinal }, t => this.eraseSaved(t));
|
|
45
|
+
this.terminal.parser.registerEscHandler({ final: Resources.fullResetFinal }, () => this.reset());
|
|
46
|
+
}
|
|
47
|
+
get title() {
|
|
48
|
+
return this.currentTitle;
|
|
49
|
+
}
|
|
50
|
+
write(data) {
|
|
51
|
+
this.writtenOffset += data.length;
|
|
52
|
+
this.tracker.track(data);
|
|
53
|
+
const offset = this.writtenOffset;
|
|
54
|
+
this.terminal.write(data, () => this.listener.onParsed(offset));
|
|
55
|
+
}
|
|
56
|
+
resize(size) {
|
|
57
|
+
this.terminal.write("", () => this.resizeNow(size));
|
|
58
|
+
}
|
|
59
|
+
snapshotAsync() {
|
|
60
|
+
const offset = this.writtenOffset;
|
|
61
|
+
const pending = this.tracker.pending;
|
|
62
|
+
return new Promise(resolve => this.terminal.write("", () => resolve(new MirrorSnapshot(this.serializer.serialize({ scrollback: Resources.scrollback }), pending, offset, this.readInputStart()))));
|
|
63
|
+
}
|
|
64
|
+
startInput() {
|
|
65
|
+
this.terminal.write("", () => {
|
|
66
|
+
this.inputStart?.dispose();
|
|
67
|
+
const buffer = this.terminal.buffer.active;
|
|
68
|
+
this.inputStart = buffer.type === Resources.normalBufferType ? this.terminal.registerMarker(0) : undefined;
|
|
69
|
+
this.inputColumn = buffer.cursorX;
|
|
70
|
+
this.rightPrompt = null;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
markRightPrompt() {
|
|
74
|
+
this.terminal.write("", () => {
|
|
75
|
+
const start = this.inputStart;
|
|
76
|
+
const buffer = this.terminal.buffer.active;
|
|
77
|
+
if (start !== undefined && !start.isDisposed && buffer.baseY + buffer.cursorY === start.line)
|
|
78
|
+
this.rightPrompt = buffer.cursorX;
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
endInput() {
|
|
82
|
+
return new Promise(resolve => this.terminal.write("", () => {
|
|
83
|
+
const line = this.isDisposed ? null : this.readInput();
|
|
84
|
+
this.inputStart?.dispose();
|
|
85
|
+
this.inputStart = undefined;
|
|
86
|
+
resolve(line);
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
isBracketedPasteAsync() {
|
|
90
|
+
return new Promise(resolve => this.terminal.write("", () => resolve(this.terminal.modes.bracketedPasteMode)));
|
|
91
|
+
}
|
|
92
|
+
anchorAsync(at) {
|
|
93
|
+
return new Promise(resolve => this.terminal.write("", () => {
|
|
94
|
+
const buffer = this.terminal.buffer.normal;
|
|
95
|
+
const cursor = buffer.baseY + buffer.cursorY;
|
|
96
|
+
const index = at === null ? cursor : at.index;
|
|
97
|
+
const marker = index === null || this.terminal.buffer.active.type !== Resources.normalBufferType ? undefined
|
|
98
|
+
: this.terminal.registerMarker(index - cursor);
|
|
99
|
+
const line = new MirrorLine(at?.number ?? this.removedLines + cursor, marker);
|
|
100
|
+
if (marker !== undefined) {
|
|
101
|
+
this.anchors.set(line, marker);
|
|
102
|
+
marker.onDispose(() => this.anchors.delete(line));
|
|
103
|
+
}
|
|
104
|
+
resolve(line);
|
|
105
|
+
}));
|
|
106
|
+
}
|
|
107
|
+
readLinesAsync(start, end, maximum) {
|
|
108
|
+
return new Promise(resolve => this.terminal.write("", () => resolve(this.readLines(start.number, end?.number ?? null, maximum))));
|
|
109
|
+
}
|
|
110
|
+
dispose() {
|
|
111
|
+
this.isDisposed = true;
|
|
112
|
+
this.releaseOldest();
|
|
113
|
+
this.terminal.dispose();
|
|
114
|
+
}
|
|
115
|
+
readInput() {
|
|
116
|
+
const start = this.inputStart;
|
|
117
|
+
if (start === undefined || start.isDisposed)
|
|
118
|
+
return null;
|
|
119
|
+
const buffer = this.terminal.buffer.normal;
|
|
120
|
+
let text = "";
|
|
121
|
+
let line = buffer.getLine(start.line);
|
|
122
|
+
for (let index = start.line; line !== undefined; index++) {
|
|
123
|
+
const next = buffer.getLine(index + 1);
|
|
124
|
+
const continues = next?.isWrapped === true;
|
|
125
|
+
const end = index === start.line && !continues ? this.findRightPrompt(line) : undefined;
|
|
126
|
+
text += line.translateToString(!continues, index === start.line ? this.inputColumn : 0, end);
|
|
127
|
+
line = continues ? next : undefined;
|
|
128
|
+
}
|
|
129
|
+
if (Resources.terminalMirrorLeadingWhiteSpace.test(text))
|
|
130
|
+
return null;
|
|
131
|
+
const command = text.trim().slice(0, ProtocolResources.maximumSuggestionLength).trim();
|
|
132
|
+
return command.length === 0 ? null : command;
|
|
133
|
+
}
|
|
134
|
+
findRightPrompt(line) {
|
|
135
|
+
const column = this.rightPrompt;
|
|
136
|
+
return column !== null && column > this.inputColumn && line.translateToString(false, column - 1, column).trim().length === 0 ? column : undefined;
|
|
137
|
+
}
|
|
138
|
+
readInputStart() {
|
|
139
|
+
const buffer = this.terminal.buffer.active;
|
|
140
|
+
const start = this.inputStart;
|
|
141
|
+
const cursor = buffer.baseY + buffer.cursorY;
|
|
142
|
+
if (start === undefined || start.isDisposed || buffer.type !== Resources.normalBufferType || start.line > cursor)
|
|
143
|
+
return null;
|
|
144
|
+
return new TerminalInputStart(cursor - start.line, this.inputColumn, this.rightPrompt);
|
|
145
|
+
}
|
|
146
|
+
readLines(start, end, maximum) {
|
|
147
|
+
const buffer = this.terminal.buffer.normal;
|
|
148
|
+
const last = Math.min(end ?? this.removedLines + buffer.baseY + buffer.cursorY + 1, this.removedLines + buffer.length);
|
|
149
|
+
let first = Math.max(start, last - maximum, this.removedLines);
|
|
150
|
+
while (first < last && buffer.getLine(first - this.removedLines)?.isWrapped === true)
|
|
151
|
+
first++;
|
|
152
|
+
const lines = [];
|
|
153
|
+
let line = buffer.getLine(first - this.removedLines);
|
|
154
|
+
for (let number = first; number < last && line !== undefined; number++) {
|
|
155
|
+
const next = buffer.getLine(number + 1 - this.removedLines);
|
|
156
|
+
lines.push(this.reader.read(line, next?.isWrapped === true));
|
|
157
|
+
line = next;
|
|
158
|
+
}
|
|
159
|
+
return new TerminalRunOutput(lines, Math.max(0, Math.min(first, last) - start));
|
|
160
|
+
}
|
|
161
|
+
resizeNow(size) {
|
|
162
|
+
if (this.isDisposed)
|
|
163
|
+
return;
|
|
164
|
+
this.releaseOldest();
|
|
165
|
+
const buffer = this.terminal.buffer.normal;
|
|
166
|
+
this.terminal.options.scrollback = Math.max(Resources.scrollback, buffer.length * Math.ceil(this.terminal.cols / size.columns));
|
|
167
|
+
this.terminal.resize(size.columns, size.rows);
|
|
168
|
+
const excess = buffer.baseY - Resources.scrollback;
|
|
169
|
+
let line = buffer.getLine(0);
|
|
170
|
+
for (let y = 0; y < excess && line !== undefined; y++) {
|
|
171
|
+
const next = buffer.getLine(y + 1);
|
|
172
|
+
this.store(this.reader.read(line, next?.isWrapped === true));
|
|
173
|
+
line = next;
|
|
174
|
+
}
|
|
175
|
+
this.terminal.options.scrollback = Resources.scrollback;
|
|
176
|
+
this.capture();
|
|
177
|
+
for (const [anchor, marker] of this.anchors)
|
|
178
|
+
anchor.renumber(this.removedLines + marker.line);
|
|
179
|
+
}
|
|
180
|
+
capture() {
|
|
181
|
+
if (this.oldestMarker?.isDisposed === true && this.oldest !== null)
|
|
182
|
+
this.store(this.oldest);
|
|
183
|
+
this.releaseOldest();
|
|
184
|
+
const buffer = this.terminal.buffer.normal;
|
|
185
|
+
if (buffer.baseY === Resources.scrollback) {
|
|
186
|
+
this.oldestMarker = this.terminal.registerMarker(-buffer.baseY - buffer.cursorY) ?? null;
|
|
187
|
+
const line = buffer.getLine(0);
|
|
188
|
+
if (this.oldestMarker !== null && line !== undefined)
|
|
189
|
+
this.oldest = this.reader.read(line, buffer.getLine(1)?.isWrapped === true);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
releaseOldest() {
|
|
193
|
+
this.oldestMarker?.dispose();
|
|
194
|
+
this.oldestMarker = null;
|
|
195
|
+
this.oldest = null;
|
|
196
|
+
}
|
|
197
|
+
store(line) {
|
|
198
|
+
this.history.append(line);
|
|
199
|
+
this.removedLines++;
|
|
200
|
+
}
|
|
201
|
+
eraseSaved(params) {
|
|
202
|
+
if (params[0] === Resources.eraseSavedLinesParameter && this.terminal.buffer.active.type === Resources.normalBufferType) {
|
|
203
|
+
this.removedLines += this.terminal.buffer.normal.baseY;
|
|
204
|
+
this.forgetStored();
|
|
205
|
+
}
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
reset() {
|
|
209
|
+
this.removedLines += this.terminal.buffer.normal.length;
|
|
210
|
+
return this.forgetStored();
|
|
211
|
+
}
|
|
212
|
+
forgetStored() {
|
|
213
|
+
this.releaseOldest();
|
|
214
|
+
this.history.clear();
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
changeTitle(title) {
|
|
218
|
+
this.currentTitle = title.slice(0, ProtocolResources.maximumTitleLength);
|
|
219
|
+
this.listener.onTitleChanged(this.currentTitle);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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 { ArgumentValidator, RuntimeTerminalOwners, TerminalOwnerReference } from "@noldova/terminal.protocol";
|
|
9
|
+
import { Resources } from "../resources.js";
|
|
10
|
+
export class TerminalOwnerService extends RuntimeTerminalOwners {
|
|
11
|
+
host;
|
|
12
|
+
constructor(host) {
|
|
13
|
+
super();
|
|
14
|
+
this.host = host;
|
|
15
|
+
}
|
|
16
|
+
async closeAsync(owner) {
|
|
17
|
+
await this.host.closeOwnerAsync(new TerminalOwnerReference(owner).owner, null);
|
|
18
|
+
}
|
|
19
|
+
bindAgentSession(agentSessionId, owner) {
|
|
20
|
+
ArgumentValidator.requireIdentifier(Resources.terminalOwnerServiceAgentSessionIdField, agentSessionId);
|
|
21
|
+
this.host.bindAgentSession(agentSessionId, new TerminalOwnerReference(owner).owner);
|
|
22
|
+
}
|
|
23
|
+
unbindAgentSession(agentSessionId) {
|
|
24
|
+
ArgumentValidator.requireIdentifier(Resources.terminalOwnerServiceAgentSessionIdField, agentSessionId);
|
|
25
|
+
this.host.unbindAgentSession(agentSessionId);
|
|
26
|
+
}
|
|
27
|
+
}
|