anti-trace 0.1.0 → 0.1.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/README.en.md +155 -154
- package/README.md +154 -153
- package/byok.providers.example.json +81 -81
- package/dist/harness/compaction.js +88 -88
- package/dist/harness/prompt.js +16 -16
- package/dist/harness/tools/powershell.js +11 -11
- package/package.json +66 -66
- package/dist/cli/input/stash/cli-prompt.d.ts +0 -28
- package/dist/cli/input/stash/cli-prompt.js +0 -289
- package/dist/cli/input/stash/cli-prompt.js.map +0 -1
- package/dist/cli/input/stash/cli-renderer.d.ts +0 -24
- package/dist/cli/input/stash/cli-renderer.js +0 -221
- package/dist/cli/input/stash/cli-renderer.js.map +0 -1
- package/dist/cli/input/stash/draft.d.ts +0 -40
- package/dist/cli/input/stash/draft.js +0 -278
- package/dist/cli/input/stash/draft.js.map +0 -1
- package/dist/cli/input/stash/paste-burst.d.ts +0 -39
- package/dist/cli/input/stash/paste-burst.js +0 -120
- package/dist/cli/input/stash/paste-burst.js.map +0 -1
- package/dist/cli/input/stash/terminal.d.ts +0 -62
- package/dist/cli/input/stash/terminal.js +0 -353
- package/dist/cli/input/stash/terminal.js.map +0 -1
- package/dist/cli/utils/image.d.ts +0 -15
- package/dist/cli/utils/image.js +0 -175
- package/dist/cli/utils/image.js.map +0 -1
- package/dist/tui/permissions/permission-policy.d.ts +0 -42
- package/dist/tui/permissions/permission-policy.js +0 -144
- package/dist/tui/permissions/permission-policy.js.map +0 -1
|
@@ -1,289 +0,0 @@
|
|
|
1
|
-
import { stdin, stdout } from "node:process";
|
|
2
|
-
import { isImagePasteKey } from "../../utils/image.js";
|
|
3
|
-
import { CliRenderer } from "./cli-renderer.js";
|
|
4
|
-
import { DraftEditor } from "./draft.js";
|
|
5
|
-
import { PasteBurst } from "./paste-burst.js";
|
|
6
|
-
import { TerminalInput } from "./terminal.js";
|
|
7
|
-
/**
|
|
8
|
-
* Temporary line-oriented CLI adapter. TerminalInput, PasteBurst, and DraftEditor
|
|
9
|
-
* have no dependency on this renderer and can be reused by the future TUI.
|
|
10
|
-
*/
|
|
11
|
-
export class CliPrompt {
|
|
12
|
-
#input;
|
|
13
|
-
#output;
|
|
14
|
-
#renderer;
|
|
15
|
-
#editor = new DraftEditor();
|
|
16
|
-
#burst = new PasteBurst();
|
|
17
|
-
#onImagePaste;
|
|
18
|
-
#terminal;
|
|
19
|
-
#resolve;
|
|
20
|
-
#timer;
|
|
21
|
-
#label = "";
|
|
22
|
-
#pasteMode = false;
|
|
23
|
-
#allowPasteMode = false;
|
|
24
|
-
#sourceEnded = false;
|
|
25
|
-
constructor(options = {}) {
|
|
26
|
-
this.#input = options.input ?? stdin;
|
|
27
|
-
this.#output = options.output ?? stdout;
|
|
28
|
-
this.#renderer = new CliRenderer(this.#output);
|
|
29
|
-
this.#onImagePaste = options.onImagePaste;
|
|
30
|
-
}
|
|
31
|
-
read(label, options = {}) {
|
|
32
|
-
if (this.#resolve) {
|
|
33
|
-
throw new Error("A prompt is already active");
|
|
34
|
-
}
|
|
35
|
-
if (this.#sourceEnded || this.#input.readableEnded) {
|
|
36
|
-
return Promise.resolve({ type: "end" });
|
|
37
|
-
}
|
|
38
|
-
this.#label = label;
|
|
39
|
-
this.#pasteMode = false;
|
|
40
|
-
this.#allowPasteMode = options.allowPasteMode ?? false;
|
|
41
|
-
this.#editor.setText("");
|
|
42
|
-
this.#burst.reset();
|
|
43
|
-
const result = new Promise((resolve) => {
|
|
44
|
-
this.#resolve = resolve;
|
|
45
|
-
});
|
|
46
|
-
this.#render();
|
|
47
|
-
this.#terminal = new TerminalInput({
|
|
48
|
-
input: this.#input,
|
|
49
|
-
output: this.#output,
|
|
50
|
-
onEvent: (event) => this.#handleEvent(event),
|
|
51
|
-
});
|
|
52
|
-
try {
|
|
53
|
-
this.#terminal.start();
|
|
54
|
-
}
|
|
55
|
-
catch (error) {
|
|
56
|
-
this.#close({ type: "end" });
|
|
57
|
-
throw error;
|
|
58
|
-
}
|
|
59
|
-
return result;
|
|
60
|
-
}
|
|
61
|
-
dispose() {
|
|
62
|
-
this.#terminal?.stop();
|
|
63
|
-
this.#terminal = undefined;
|
|
64
|
-
this.#clearTimer();
|
|
65
|
-
if (this.#resolve) {
|
|
66
|
-
this.#close({ type: "end" });
|
|
67
|
-
}
|
|
68
|
-
this.#renderer.dispose();
|
|
69
|
-
}
|
|
70
|
-
#handleEvent(event) {
|
|
71
|
-
if (!this.#resolve)
|
|
72
|
-
return;
|
|
73
|
-
const now = Date.now();
|
|
74
|
-
switch (event.type) {
|
|
75
|
-
case "text":
|
|
76
|
-
this.#applyBurst(this.#burst.feedText(event.text, now));
|
|
77
|
-
this.#scheduleFlush();
|
|
78
|
-
return;
|
|
79
|
-
case "paste":
|
|
80
|
-
this.#applyBurst(this.#burst.flushAll(now));
|
|
81
|
-
if (!this.#resolve)
|
|
82
|
-
return;
|
|
83
|
-
this.#burst.reset();
|
|
84
|
-
this.#editor.insert(event.text);
|
|
85
|
-
this.#render();
|
|
86
|
-
return;
|
|
87
|
-
case "key":
|
|
88
|
-
this.#handleKey(event, now);
|
|
89
|
-
return;
|
|
90
|
-
case "end":
|
|
91
|
-
this.#sourceEnded = true;
|
|
92
|
-
if (this.#input.isTTY === true) {
|
|
93
|
-
this.#burst.reset();
|
|
94
|
-
this.#close({ type: "end" });
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
this.#applyBurst(this.#burst.flushAll(now));
|
|
98
|
-
this.#close(this.#editor.text.length > 0
|
|
99
|
-
? { type: "submit", text: this.#editor.submit() }
|
|
100
|
-
: { type: "end" });
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
#handleKey(event, now) {
|
|
105
|
-
if (event.key === "ctrl-c") {
|
|
106
|
-
this.#close({ type: "interrupt" });
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
if (event.key === "ctrl-d" && this.#pasteMode) {
|
|
110
|
-
this.#applyBurst(this.#burst.flushAll(now));
|
|
111
|
-
this.#pasteMode = false;
|
|
112
|
-
this.#render();
|
|
113
|
-
this.#notice("粘贴模式结束;检查草稿后按 Enter 发送");
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
if (event.key === "enter" && !event.shift && !event.ctrl && !event.alt && !this.#pasteMode) {
|
|
117
|
-
this.#applyBurst(this.#burst.feedDelimiter("enter", now));
|
|
118
|
-
this.#scheduleFlush();
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
if (event.key === "tab" && !event.shift && !event.ctrl && !event.alt) {
|
|
122
|
-
this.#applyBurst(this.#burst.feedDelimiter("tab", now));
|
|
123
|
-
this.#scheduleFlush();
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
this.#applyBurst(this.#burst.flushAll(now));
|
|
127
|
-
this.#clearTimer();
|
|
128
|
-
if (!this.#resolve)
|
|
129
|
-
return;
|
|
130
|
-
if (event.key === "enter" || event.key === "ctrl-j") {
|
|
131
|
-
this.#editor.newline();
|
|
132
|
-
}
|
|
133
|
-
else if (event.key === "ctrl-d") {
|
|
134
|
-
if (this.#editor.text.length === 0) {
|
|
135
|
-
this.#close({ type: "end" });
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
this.#editor.deleteForward();
|
|
139
|
-
}
|
|
140
|
-
else if (event.key === "backspace") {
|
|
141
|
-
this.#editor.backspace();
|
|
142
|
-
}
|
|
143
|
-
else if (event.key === "delete") {
|
|
144
|
-
this.#editor.deleteForward();
|
|
145
|
-
}
|
|
146
|
-
else if (event.key === "left") {
|
|
147
|
-
this.#editor.moveLeft();
|
|
148
|
-
}
|
|
149
|
-
else if (event.key === "right") {
|
|
150
|
-
this.#editor.moveRight();
|
|
151
|
-
}
|
|
152
|
-
else if (event.key === "home" || event.key === "ctrl-a") {
|
|
153
|
-
this.#editor.moveHome();
|
|
154
|
-
}
|
|
155
|
-
else if (event.key === "end" || event.key === "ctrl-e") {
|
|
156
|
-
this.#editor.moveEnd();
|
|
157
|
-
}
|
|
158
|
-
else if (event.key === "up" || event.key === "page-up") {
|
|
159
|
-
if (!this.#editor.moveUp())
|
|
160
|
-
this.#editor.previousHistory();
|
|
161
|
-
}
|
|
162
|
-
else if (event.key === "down" || event.key === "page-down") {
|
|
163
|
-
if (!this.#editor.moveDown())
|
|
164
|
-
this.#editor.nextHistory();
|
|
165
|
-
}
|
|
166
|
-
else if (event.key === "ctrl-u") {
|
|
167
|
-
const start = this.#editor.text.lastIndexOf("\n", this.#editor.cursor - 1) + 1;
|
|
168
|
-
this.#replaceRange(start, this.#editor.cursor);
|
|
169
|
-
}
|
|
170
|
-
else if (event.key === "ctrl-k") {
|
|
171
|
-
const next = this.#editor.text.indexOf("\n", this.#editor.cursor);
|
|
172
|
-
const end = next < 0 ? this.#editor.text.length : next === this.#editor.cursor ? next + 1 : next;
|
|
173
|
-
this.#replaceRange(this.#editor.cursor, end);
|
|
174
|
-
}
|
|
175
|
-
else if (event.key === "ctrl-w") {
|
|
176
|
-
this.#deletePreviousWord();
|
|
177
|
-
}
|
|
178
|
-
else if (event.key === "ctrl-l") {
|
|
179
|
-
this.#renderer.clear();
|
|
180
|
-
}
|
|
181
|
-
else if (event.key === "ctrl-v" || event.key === "alt-v") {
|
|
182
|
-
this.#handleImageKey(event);
|
|
183
|
-
}
|
|
184
|
-
else if (event.key === "tab") {
|
|
185
|
-
this.#editor.insert("\t");
|
|
186
|
-
}
|
|
187
|
-
this.#render();
|
|
188
|
-
}
|
|
189
|
-
#applyBurst(events) {
|
|
190
|
-
for (const event of events) {
|
|
191
|
-
if (!this.#resolve)
|
|
192
|
-
return;
|
|
193
|
-
if (event.type === "key") {
|
|
194
|
-
if (event.key === "enter") {
|
|
195
|
-
if (this.#allowPasteMode && this.#editor.text === "/paste") {
|
|
196
|
-
this.#editor.setText("");
|
|
197
|
-
this.#pasteMode = true;
|
|
198
|
-
this.#render();
|
|
199
|
-
this.#notice("粘贴模式:换行只进入草稿,按 Ctrl+D 结束粘贴模式");
|
|
200
|
-
}
|
|
201
|
-
else {
|
|
202
|
-
this.#close({ type: "submit", text: this.#editor.submit() });
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
else {
|
|
206
|
-
this.#editor.insert("\t");
|
|
207
|
-
this.#render();
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
else {
|
|
211
|
-
this.#editor.insert(event.text);
|
|
212
|
-
this.#render();
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
#scheduleFlush() {
|
|
217
|
-
this.#clearTimer();
|
|
218
|
-
const deadline = this.#burst.deadline;
|
|
219
|
-
if (!this.#resolve || deadline === undefined)
|
|
220
|
-
return;
|
|
221
|
-
this.#timer = setTimeout(() => {
|
|
222
|
-
this.#timer = undefined;
|
|
223
|
-
this.#applyBurst(this.#burst.flushIfDue(Date.now()));
|
|
224
|
-
this.#scheduleFlush();
|
|
225
|
-
}, Math.max(1, deadline - Date.now() + 1));
|
|
226
|
-
}
|
|
227
|
-
#clearTimer() {
|
|
228
|
-
if (this.#timer) {
|
|
229
|
-
clearTimeout(this.#timer);
|
|
230
|
-
this.#timer = undefined;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
#handleImageKey(event) {
|
|
234
|
-
if (!this.#onImagePaste || !isImagePasteKey({
|
|
235
|
-
name: "v",
|
|
236
|
-
ctrl: event.key === "ctrl-v",
|
|
237
|
-
meta: event.key === "alt-v",
|
|
238
|
-
shift: event.shift,
|
|
239
|
-
}))
|
|
240
|
-
return;
|
|
241
|
-
try {
|
|
242
|
-
this.#notice(this.#onImagePaste());
|
|
243
|
-
}
|
|
244
|
-
catch (error) {
|
|
245
|
-
this.#notice(error instanceof Error ? error.message : String(error));
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
#replaceRange(start, end) {
|
|
249
|
-
if (start >= end)
|
|
250
|
-
return;
|
|
251
|
-
const text = this.#editor.text;
|
|
252
|
-
this.#editor.setText(text.slice(0, start) + text.slice(end));
|
|
253
|
-
this.#editor.setCursor(start);
|
|
254
|
-
}
|
|
255
|
-
#deletePreviousWord() {
|
|
256
|
-
const before = this.#editor.text.slice(0, this.#editor.cursor);
|
|
257
|
-
const parts = [...new Intl.Segmenter(undefined, { granularity: "grapheme" }).segment(before)];
|
|
258
|
-
let index = parts.length;
|
|
259
|
-
while (index > 0 && /\s/u.test(parts[index - 1].segment))
|
|
260
|
-
index -= 1;
|
|
261
|
-
while (index > 0 && !/\s/u.test(parts[index - 1].segment))
|
|
262
|
-
index -= 1;
|
|
263
|
-
this.#replaceRange(parts[index]?.index ?? before.length, this.#editor.cursor);
|
|
264
|
-
}
|
|
265
|
-
#render() {
|
|
266
|
-
if (this.#output.isTTY) {
|
|
267
|
-
this.#renderer.show(this.#pasteMode ? "paste> " : this.#label, this.#editor.text, this.#editor.cursor);
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
#notice(message) {
|
|
271
|
-
if (this.#output.isTTY)
|
|
272
|
-
this.#renderer.print(message);
|
|
273
|
-
else
|
|
274
|
-
this.#output.write(`${message}\n`);
|
|
275
|
-
}
|
|
276
|
-
#close(result) {
|
|
277
|
-
const resolve = this.#resolve;
|
|
278
|
-
if (!resolve)
|
|
279
|
-
return;
|
|
280
|
-
this.#resolve = undefined;
|
|
281
|
-
this.#clearTimer();
|
|
282
|
-
this.#terminal?.stop();
|
|
283
|
-
this.#terminal = undefined;
|
|
284
|
-
if (this.#output.isTTY)
|
|
285
|
-
this.#renderer.finish();
|
|
286
|
-
resolve(result);
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
//# sourceMappingURL=cli-prompt.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cli-prompt.js","sourceRoot":"","sources":["../../../../src/cli/input/stash/cli-prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE7C,OAAO,EAAE,eAAe,EA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AAE,CAAC;QACnB,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,CAAC;QACvB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK;YAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,CAAC;QAChD,OAAO,CAAC,MAAM,CAAC,CAAC;IACjB,CAAC;CACD"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { WriteStream } from "node:tty";
|
|
2
|
-
/** The temporary CLI view of a reusable multiline input draft. */
|
|
3
|
-
export declare class CliRenderer {
|
|
4
|
-
private readonly output;
|
|
5
|
-
private active;
|
|
6
|
-
private prompt;
|
|
7
|
-
private text;
|
|
8
|
-
private cursorUtf16;
|
|
9
|
-
private cursorRow;
|
|
10
|
-
private endRow;
|
|
11
|
-
private endColumn;
|
|
12
|
-
private disposed;
|
|
13
|
-
private readonly onResize;
|
|
14
|
-
constructor(output: WriteStream);
|
|
15
|
-
show(prompt: string, text: string, cursorUtf16: number): void;
|
|
16
|
-
/** Remove the active draft from the screen while retaining it in memory. */
|
|
17
|
-
clear(): void;
|
|
18
|
-
/** Leave the submitted draft visible and start subsequent output below it. */
|
|
19
|
-
finish(): void;
|
|
20
|
-
/** Print a notice above an active draft, then restore the editable view. */
|
|
21
|
-
print(message: string): void;
|
|
22
|
-
dispose(): void;
|
|
23
|
-
private erase;
|
|
24
|
-
}
|
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
const segmenter = new Intl.Segmenter(undefined, { granularity: "grapheme" });
|
|
2
|
-
const emoji = /\p{Extended_Pictographic}|\p{Regional_Indicator}/u;
|
|
3
|
-
const combining = /\p{Mark}/u;
|
|
4
|
-
function isFullwidth(codePoint) {
|
|
5
|
-
return (codePoint >= 0x1100 &&
|
|
6
|
-
(codePoint <= 0x115f ||
|
|
7
|
-
codePoint === 0x2329 ||
|
|
8
|
-
codePoint === 0x232a ||
|
|
9
|
-
(codePoint >= 0x2e80 && codePoint <= 0xa4cf && codePoint !== 0x303f) ||
|
|
10
|
-
(codePoint >= 0xac00 && codePoint <= 0xd7a3) ||
|
|
11
|
-
(codePoint >= 0xf900 && codePoint <= 0xfaff) ||
|
|
12
|
-
(codePoint >= 0xfe10 && codePoint <= 0xfe19) ||
|
|
13
|
-
(codePoint >= 0xfe30 && codePoint <= 0xfe6f) ||
|
|
14
|
-
(codePoint >= 0xff00 && codePoint <= 0xff60) ||
|
|
15
|
-
(codePoint >= 0xffe0 && codePoint <= 0xffe6) ||
|
|
16
|
-
(codePoint >= 0x20000 && codePoint <= 0x3fffd)));
|
|
17
|
-
}
|
|
18
|
-
function graphemeWidth(grapheme) {
|
|
19
|
-
if (emoji.test(grapheme) || grapheme.includes("\u20e3") || grapheme.includes("\ufe0f")) {
|
|
20
|
-
return 2;
|
|
21
|
-
}
|
|
22
|
-
for (const character of grapheme) {
|
|
23
|
-
if (combining.test(character) || character === "\u200d" || character === "\ufe0e" || character === "\ufe0f") {
|
|
24
|
-
continue;
|
|
25
|
-
}
|
|
26
|
-
return isFullwidth(character.codePointAt(0) ?? 0) ? 2 : 1;
|
|
27
|
-
}
|
|
28
|
-
return 1;
|
|
29
|
-
}
|
|
30
|
-
function displayGrapheme(grapheme) {
|
|
31
|
-
if (grapheme === "\t") {
|
|
32
|
-
throw new Error("Tabs need the current column to determine their width");
|
|
33
|
-
}
|
|
34
|
-
if (grapheme.length === 1) {
|
|
35
|
-
const code = grapheme.charCodeAt(0);
|
|
36
|
-
if (code < 0x20 || code === 0x7f) {
|
|
37
|
-
return { text: `^${String.fromCharCode(code === 0x7f ? 0x3f : code + 0x40)}`, width: 2 };
|
|
38
|
-
}
|
|
39
|
-
if (code >= 0x80 && code <= 0x9f) {
|
|
40
|
-
return { text: "�", width: 1 };
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return { text: grapheme, width: graphemeWidth(grapheme) };
|
|
44
|
-
}
|
|
45
|
-
function layoutDraft(prompt, text, cursorUtf16, columns, screenRows) {
|
|
46
|
-
const width = Math.max(2, Math.floor(columns) || 80);
|
|
47
|
-
const boundedCursor = Math.max(0, Math.min(text.length, Math.floor(cursorUtf16) || 0));
|
|
48
|
-
let row = 0;
|
|
49
|
-
let column = 0;
|
|
50
|
-
const lines = [""];
|
|
51
|
-
let cursor = { row: 0, column: 0 };
|
|
52
|
-
function position() {
|
|
53
|
-
// A full row has a pending terminal autowrap. Its next insertion point
|
|
54
|
-
// is the beginning of the following row.
|
|
55
|
-
return column === width ? { row: row + 1, column: 0 } : { row, column };
|
|
56
|
-
}
|
|
57
|
-
function newline() {
|
|
58
|
-
row += 1;
|
|
59
|
-
column = 0;
|
|
60
|
-
lines.push("");
|
|
61
|
-
}
|
|
62
|
-
function appendVisible(value, cellWidth) {
|
|
63
|
-
if (column + cellWidth > width) {
|
|
64
|
-
newline();
|
|
65
|
-
}
|
|
66
|
-
lines[row] += value;
|
|
67
|
-
column += cellWidth;
|
|
68
|
-
}
|
|
69
|
-
function append(grapheme) {
|
|
70
|
-
if (grapheme === "\n" || grapheme === "\r\n") {
|
|
71
|
-
newline();
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
if (grapheme === "\t") {
|
|
75
|
-
const spaces = 8 - (column % 8);
|
|
76
|
-
for (let index = 0; index < spaces; index += 1) {
|
|
77
|
-
appendVisible(" ", 1);
|
|
78
|
-
}
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
const display = displayGrapheme(grapheme);
|
|
82
|
-
appendVisible(display.text, display.width);
|
|
83
|
-
}
|
|
84
|
-
for (const part of segmenter.segment(prompt)) {
|
|
85
|
-
append(part.segment);
|
|
86
|
-
}
|
|
87
|
-
cursor = position();
|
|
88
|
-
for (const part of segmenter.segment(text)) {
|
|
89
|
-
const end = part.index + part.segment.length;
|
|
90
|
-
const before = position();
|
|
91
|
-
append(part.segment);
|
|
92
|
-
if (boundedCursor >= end) {
|
|
93
|
-
cursor = position();
|
|
94
|
-
}
|
|
95
|
-
else if (boundedCursor > part.index && boundedCursor < end) {
|
|
96
|
-
// The editor normally supplies a grapheme boundary. If it does not,
|
|
97
|
-
// keep the terminal cursor before the complete grapheme.
|
|
98
|
-
cursor = before;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
if (column === width) {
|
|
102
|
-
// Materialize the last wrap so moving the cursor to the end is reliable.
|
|
103
|
-
newline();
|
|
104
|
-
}
|
|
105
|
-
const maxRows = Math.max(3, (Math.floor(screenRows) || 24) - 2);
|
|
106
|
-
if (lines.length <= maxRows) {
|
|
107
|
-
return { output: lines.join("\r\n"), cursor, end: { row, column } };
|
|
108
|
-
}
|
|
109
|
-
// Keep a bounded viewport around the insertion point. The draft remains
|
|
110
|
-
// complete in the input model; only the temporary CLI view is clipped.
|
|
111
|
-
const contentRows = maxRows - 2;
|
|
112
|
-
const start = Math.max(0, Math.min(lines.length - contentRows, cursor.row - Math.floor(contentRows / 2)));
|
|
113
|
-
const stop = start + contentRows;
|
|
114
|
-
const topMarker = start > 0 ? [`... ${start} lines above`.slice(0, width - 1)] : [];
|
|
115
|
-
const bottomMarker = stop < lines.length ? [`... ${lines.length - stop} lines below`.slice(0, width - 1)] : [];
|
|
116
|
-
const visible = [...topMarker, ...lines.slice(start, stop), ...bottomMarker];
|
|
117
|
-
return {
|
|
118
|
-
output: visible.join("\r\n"),
|
|
119
|
-
cursor: { row: cursor.row - start + topMarker.length, column: cursor.column },
|
|
120
|
-
end: { row: visible.length - 1, column: bottomMarker.length > 0 ? bottomMarker[0].length : column },
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
/** The temporary CLI view of a reusable multiline input draft. */
|
|
124
|
-
export class CliRenderer {
|
|
125
|
-
output;
|
|
126
|
-
active = false;
|
|
127
|
-
prompt = "";
|
|
128
|
-
text = "";
|
|
129
|
-
cursorUtf16 = 0;
|
|
130
|
-
cursorRow = 0;
|
|
131
|
-
endRow = 0;
|
|
132
|
-
endColumn = 0;
|
|
133
|
-
disposed = false;
|
|
134
|
-
onResize = () => {
|
|
135
|
-
if (this.active && !this.disposed) {
|
|
136
|
-
// Terminals may reflow already-painted rows when their width changes.
|
|
137
|
-
// The old cursor row is no longer a safe erase anchor. Start a fresh
|
|
138
|
-
// prompt below the old one; the future TUI can redraw the full screen.
|
|
139
|
-
this.active = false;
|
|
140
|
-
this.output.write("\x1b[999B\r\n");
|
|
141
|
-
this.show(this.prompt, this.text, this.cursorUtf16);
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
constructor(output) {
|
|
145
|
-
this.output = output;
|
|
146
|
-
this.output.on("resize", this.onResize);
|
|
147
|
-
}
|
|
148
|
-
show(prompt, text, cursorUtf16) {
|
|
149
|
-
if (this.disposed) {
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
if (this.active) {
|
|
153
|
-
this.erase();
|
|
154
|
-
}
|
|
155
|
-
const layout = layoutDraft(prompt, text, cursorUtf16, this.output.columns ?? 80, this.output.rows ?? 24);
|
|
156
|
-
this.output.write(layout.output);
|
|
157
|
-
this.output.write("\r");
|
|
158
|
-
if (layout.end.row > layout.cursor.row) {
|
|
159
|
-
this.output.write(`\x1b[${layout.end.row - layout.cursor.row}A`);
|
|
160
|
-
}
|
|
161
|
-
if (layout.cursor.column > 0) {
|
|
162
|
-
this.output.write(`\x1b[${layout.cursor.column}C`);
|
|
163
|
-
}
|
|
164
|
-
this.active = true;
|
|
165
|
-
this.prompt = prompt;
|
|
166
|
-
this.text = text;
|
|
167
|
-
this.cursorUtf16 = cursorUtf16;
|
|
168
|
-
this.cursorRow = layout.cursor.row;
|
|
169
|
-
this.endRow = layout.end.row;
|
|
170
|
-
this.endColumn = layout.end.column;
|
|
171
|
-
}
|
|
172
|
-
/** Remove the active draft from the screen while retaining it in memory. */
|
|
173
|
-
clear() {
|
|
174
|
-
if (this.active) {
|
|
175
|
-
this.erase();
|
|
176
|
-
this.active = false;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
/** Leave the submitted draft visible and start subsequent output below it. */
|
|
180
|
-
finish() {
|
|
181
|
-
if (!this.active) {
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
this.output.write("\r");
|
|
185
|
-
if (this.endRow > this.cursorRow) {
|
|
186
|
-
this.output.write(`\x1b[${this.endRow - this.cursorRow}B`);
|
|
187
|
-
}
|
|
188
|
-
if (this.endColumn > 0) {
|
|
189
|
-
this.output.write("\r\n");
|
|
190
|
-
}
|
|
191
|
-
this.active = false;
|
|
192
|
-
}
|
|
193
|
-
/** Print a notice above an active draft, then restore the editable view. */
|
|
194
|
-
print(message) {
|
|
195
|
-
const normalized = message.replace(/\r\n|\r|\n/g, "\n").replace(/\n/g, "\r\n");
|
|
196
|
-
const line = normalized.endsWith("\r\n") ? normalized : `${normalized}\r\n`;
|
|
197
|
-
if (this.active) {
|
|
198
|
-
this.erase();
|
|
199
|
-
this.active = false;
|
|
200
|
-
this.output.write(line);
|
|
201
|
-
this.show(this.prompt, this.text, this.cursorUtf16);
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
this.output.write(line);
|
|
205
|
-
}
|
|
206
|
-
dispose() {
|
|
207
|
-
if (this.disposed) {
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
this.output.off("resize", this.onResize);
|
|
211
|
-
this.disposed = true;
|
|
212
|
-
}
|
|
213
|
-
erase() {
|
|
214
|
-
this.output.write("\r");
|
|
215
|
-
if (this.cursorRow > 0) {
|
|
216
|
-
this.output.write(`\x1b[${this.cursorRow}A`);
|
|
217
|
-
}
|
|
218
|
-
this.output.write("\x1b[J");
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
//# sourceMappingURL=cli-renderer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cli-renderer.js","sourceRoot":"","sources":["../../../../src/cli/input/stash/cli-renderer.ts"],"names":[],"mappings":"AAUA,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE,E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,QAAQ,EAAE,CAAC;YACnB,OAAO;QACR,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;QACzC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;IACtB,CAAC;IAEO,KAAK;QACZ,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACxB,IAAI,IAAI,CAAC,SAAS,GAAG,CAAC,EAAE,CAAC;YACxB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC;QAC9C,CAAC;QACD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC7B,CAAC;CACD"}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A terminal-independent editable prompt. Input decoders decide whether bytes are
|
|
3
|
-
* typing, paste, or a key; renderers only read this state. Neither can submit the
|
|
4
|
-
* draft accidentally: submission happens only through submit().
|
|
5
|
-
*
|
|
6
|
-
* `cursor` is a UTF-16 offset into `text`. It is always on a grapheme boundary,
|
|
7
|
-
* so callers can use it with String.slice without splitting an emoji or accent.
|
|
8
|
-
*/
|
|
9
|
-
export declare class DraftEditor {
|
|
10
|
-
#private;
|
|
11
|
-
constructor(initialText?: string);
|
|
12
|
-
get text(): string;
|
|
13
|
-
/** UTF-16 offset into text, guaranteed to be a grapheme boundary. */
|
|
14
|
-
get cursor(): number;
|
|
15
|
-
/** Zero-based logical line and grapheme column. Screen wrapping is renderer-owned. */
|
|
16
|
-
get position(): {
|
|
17
|
-
row: number;
|
|
18
|
-
column: number;
|
|
19
|
-
};
|
|
20
|
-
setText(value: string): void;
|
|
21
|
-
/** Clamp an arbitrary UTF-16 offset to the preceding grapheme boundary. */
|
|
22
|
-
setCursor(offset: number): void;
|
|
23
|
-
/** Insert typed or pasted content exactly, except for CRLF/CR normalization. */
|
|
24
|
-
insert(value: string): void;
|
|
25
|
-
newline(): void;
|
|
26
|
-
backspace(): boolean;
|
|
27
|
-
deleteForward(): boolean;
|
|
28
|
-
moveLeft(): boolean;
|
|
29
|
-
moveRight(): boolean;
|
|
30
|
-
moveHome(): boolean;
|
|
31
|
-
moveEnd(): boolean;
|
|
32
|
-
moveUp(): boolean;
|
|
33
|
-
moveDown(): boolean;
|
|
34
|
-
/** Return the untrimmed draft and clear it. Callers decide whether to send it. */
|
|
35
|
-
submit(): string;
|
|
36
|
-
/** Recall previous submitted text, preserving the current unsent draft. */
|
|
37
|
-
previousHistory(): boolean;
|
|
38
|
-
/** Move toward the unsent draft after browsing history. */
|
|
39
|
-
nextHistory(): boolean;
|
|
40
|
-
}
|