@phren/cli 0.1.42 → 0.1.44
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/dist/capabilities/cli.js +1 -1
- package/dist/capabilities/mcp.js +1 -1
- package/dist/capabilities/vscode.js +3 -3
- package/dist/capabilities/web-ui.js +29 -29
- package/dist/cli/hooks-output.js +15 -6
- package/dist/cli/hooks.js +2 -2
- package/dist/governance/scores.d.ts +9 -1
- package/dist/governance/scores.js +12 -1
- package/dist/init/init-uninstall.js +12 -2
- package/dist/profile-store.d.ts +2 -0
- package/dist/profile-store.js +13 -17
- package/dist/shared/fragment-graph.js +7 -2
- package/dist/shared/retrieval.d.ts +10 -0
- package/dist/shared/retrieval.js +17 -4
- package/dist/shell/entry.d.ts +8 -0
- package/dist/shell/entry.js +114 -58
- package/dist/shell/input.d.ts +1 -1
- package/dist/shell/input.js +4 -1
- package/dist/shell/keys.d.ts +36 -0
- package/dist/shell/keys.js +107 -0
- package/dist/shell/render.d.ts +33 -0
- package/dist/shell/render.js +216 -46
- package/dist/shell/shell.js +16 -3
- package/dist/shell/view.js +2 -1
- package/dist/store-registry.d.ts +13 -0
- package/dist/store-registry.js +106 -34
- package/dist/tools/memory.js +12 -5
- package/dist/tools/ops.js +1 -1
- package/package.json +31 -4
- package/starter/global/skills/phren-consolidate/SKILL.md +152 -0
- package/starter/global/skills/phren-discover/SKILL.md +175 -0
- package/starter/global/skills/phren-init/SKILL.md +216 -0
- package/starter/global/skills/phren-profiles/SKILL.md +121 -0
- package/starter/global/skills/phren-sync/SKILL.md +261 -0
- package/dist/init-uninstall.d.ts +0 -3
- package/dist/init-uninstall.js +0 -514
- package/dist/init-walkthrough.d.ts +0 -55
- package/dist/init-walkthrough.js +0 -524
package/dist/shell/entry.js
CHANGED
|
@@ -3,30 +3,21 @@
|
|
|
3
3
|
* Extracted from shell.ts to keep the orchestrator under 300 lines.
|
|
4
4
|
*/
|
|
5
5
|
import { PhrenShell } from "./shell.js";
|
|
6
|
-
import { style, clearScreen,
|
|
6
|
+
import { style, clearScreen, paintFrame, enterFullscreen, exitFullscreen, shellStartupFrames, composeStartupFrame, fitFrame, } from "./render.js";
|
|
7
|
+
import { KeyDecoder, ESC_FLUSH_MS } from "./keys.js";
|
|
7
8
|
import { createPhrenAnimator } from "../phren-art.js";
|
|
8
9
|
import { errorMessage } from "../utils.js";
|
|
9
10
|
import { computePhrenLiveStateToken } from "../shared.js";
|
|
10
11
|
import { VERSION } from "../init/shared.js";
|
|
11
12
|
import { loadShellState, saveShellState } from "./state-store.js";
|
|
12
13
|
const LIVE_STATE_POLL_MS = 2000;
|
|
13
|
-
function renderIntroFrame(
|
|
14
|
-
|
|
15
|
-
process.stdout.write(footer ? `${frame}\n${footer}\n` : `${frame}\n`);
|
|
16
|
-
clearToEnd();
|
|
14
|
+
function renderIntroFrame(lines) {
|
|
15
|
+
paintFrame(fitFrame(lines));
|
|
17
16
|
}
|
|
18
17
|
function sleep(ms) {
|
|
19
18
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
20
19
|
}
|
|
21
|
-
|
|
22
|
-
await new Promise((resolve) => {
|
|
23
|
-
const onData = () => {
|
|
24
|
-
process.stdin.removeListener("data", onData);
|
|
25
|
-
resolve();
|
|
26
|
-
};
|
|
27
|
-
process.stdin.on("data", onData);
|
|
28
|
-
});
|
|
29
|
-
}
|
|
20
|
+
const noopWaiter = () => Promise.resolve();
|
|
30
21
|
export function resolveStartupIntroPlan(phrenPath, version = VERSION) {
|
|
31
22
|
const state = loadShellState(phrenPath);
|
|
32
23
|
const mode = state.introMode === "always" || state.introMode === "off" ? state.introMode : "once-per-version";
|
|
@@ -47,7 +38,7 @@ function markStartupIntroSeen(phrenPath, version = VERSION) {
|
|
|
47
38
|
return;
|
|
48
39
|
saveShellState(phrenPath, { ...state, introSeenVersion: version });
|
|
49
40
|
}
|
|
50
|
-
async function playStartupIntro(phrenPath, plan = resolveStartupIntroPlan(phrenPath)) {
|
|
41
|
+
async function playStartupIntro(phrenPath, plan = resolveStartupIntroPlan(phrenPath), waitForAnyKeypress = noopWaiter) {
|
|
51
42
|
if (!process.stdout.isTTY || plan.variant === "skip")
|
|
52
43
|
return;
|
|
53
44
|
const frames = shellStartupFrames(VERSION);
|
|
@@ -56,40 +47,15 @@ async function playStartupIntro(phrenPath, plan = resolveStartupIntroPlan(phrenP
|
|
|
56
47
|
: `${style.dim("Loading shell…")}`;
|
|
57
48
|
if (plan.variant === "full") {
|
|
58
49
|
for (const frame of frames.slice(0, -1)) {
|
|
59
|
-
renderIntroFrame(frame);
|
|
50
|
+
renderIntroFrame(frame.split("\n"));
|
|
60
51
|
await sleep(160);
|
|
61
52
|
}
|
|
62
53
|
}
|
|
63
54
|
// Start animated phren during loading
|
|
64
55
|
const animator = createPhrenAnimator({ facing: "right" });
|
|
65
56
|
animator.start();
|
|
66
|
-
const _cols = process.stdout.columns || 80;
|
|
67
|
-
const tagline = style.dim("local memory for working agents");
|
|
68
|
-
const versionBadge = badge(`v${VERSION}`, style.boldBlue);
|
|
69
|
-
const logoLines = [
|
|
70
|
-
"██████╗ ██╗ ██╗██████╗ ███████╗███╗ ██╗",
|
|
71
|
-
"██╔══██╗██║ ██║██╔══██╗██╔════╝████╗ ██║",
|
|
72
|
-
"██████╔╝███████║██████╔╝█████╗ ██╔██╗ ██║",
|
|
73
|
-
"██╔═══╝ ██╔══██║██╔══██╗██╔══╝ ██║╚██╗██║",
|
|
74
|
-
"██║ ██║ ██║██║ ██║███████╗██║ ╚████║",
|
|
75
|
-
"╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═══╝",
|
|
76
|
-
].map(l => gradient(l));
|
|
77
|
-
const infoLine = `${gradient("◆")} ${style.bold("phren")} ${versionBadge} ${tagline}`;
|
|
78
57
|
function renderAnimatedFrame(hint) {
|
|
79
|
-
|
|
80
|
-
const rightSide = ["", "", ...logoLines, "", infoLine];
|
|
81
|
-
const charWidth = 26;
|
|
82
|
-
const maxLines = Math.max(phrenLines.length, rightSide.length);
|
|
83
|
-
const merged = [""];
|
|
84
|
-
for (let i = 0; i < maxLines; i++) {
|
|
85
|
-
const left = (i < phrenLines.length ? phrenLines[i] : "").padEnd(charWidth);
|
|
86
|
-
const right = i < rightSide.length ? rightSide[i] : "";
|
|
87
|
-
merged.push(left + right);
|
|
88
|
-
}
|
|
89
|
-
if (hint)
|
|
90
|
-
merged.push("", ` ${hint}`);
|
|
91
|
-
merged.push("");
|
|
92
|
-
renderIntroFrame(merged.join("\n"));
|
|
58
|
+
renderIntroFrame(composeStartupFrame(animator.getFrame(), VERSION, hint));
|
|
93
59
|
}
|
|
94
60
|
// Animate during dwell/loading period
|
|
95
61
|
if (plan.holdForKeypress) {
|
|
@@ -173,10 +139,36 @@ export async function startShell(phrenPath, profile) {
|
|
|
173
139
|
process.stdin.setRawMode(true);
|
|
174
140
|
process.stdin.resume();
|
|
175
141
|
process.stdin.setEncoding("utf8");
|
|
176
|
-
|
|
142
|
+
enterFullscreen();
|
|
177
143
|
let exiting = false;
|
|
178
144
|
let cleanedUp = false;
|
|
179
|
-
|
|
145
|
+
// ── Painting ────────────────────────────────────────────────────────────
|
|
146
|
+
// render() is async (the Health view awaits a doctor snapshot) and repaints
|
|
147
|
+
// are triggered from three independent sources — keys, resize, and the live
|
|
148
|
+
// store poller — none of which await each other. Serialising them keeps two
|
|
149
|
+
// renders from interleaving their writes; a repaint requested mid-render is
|
|
150
|
+
// coalesced into a single trailing repaint instead of queueing up.
|
|
151
|
+
let painting = false;
|
|
152
|
+
let repaintQueued = false;
|
|
153
|
+
const repaint = async () => {
|
|
154
|
+
if (painting) {
|
|
155
|
+
repaintQueued = true;
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
painting = true;
|
|
159
|
+
try {
|
|
160
|
+
do {
|
|
161
|
+
repaintQueued = false;
|
|
162
|
+
const frame = await shell.render();
|
|
163
|
+
if (exiting)
|
|
164
|
+
return;
|
|
165
|
+
paintFrame(frame);
|
|
166
|
+
} while (repaintQueued);
|
|
167
|
+
}
|
|
168
|
+
finally {
|
|
169
|
+
painting = false;
|
|
170
|
+
}
|
|
171
|
+
};
|
|
180
172
|
let done;
|
|
181
173
|
const exitPromise = new Promise((resolve) => { done = resolve; });
|
|
182
174
|
const restoreTerminal = () => {
|
|
@@ -191,27 +183,81 @@ export async function startShell(phrenPath, profile) {
|
|
|
191
183
|
}
|
|
192
184
|
catch { }
|
|
193
185
|
try {
|
|
194
|
-
|
|
186
|
+
exitFullscreen();
|
|
195
187
|
}
|
|
196
188
|
catch { }
|
|
197
189
|
};
|
|
198
|
-
|
|
199
|
-
|
|
190
|
+
// ── Key delivery ────────────────────────────────────────────────────────
|
|
191
|
+
// stdin hands us whatever arrived in one read, which is often several keys
|
|
192
|
+
// (autorepeat, fast typing, paste). Decode the chunk into discrete keys, then
|
|
193
|
+
// drain them through one sequential pump so handlers never run concurrently,
|
|
194
|
+
// and repaint once per burst rather than once per key.
|
|
195
|
+
const decoder = new KeyDecoder();
|
|
196
|
+
const keyQueue = [];
|
|
197
|
+
let escTimer;
|
|
198
|
+
let introKeyWaiter;
|
|
199
|
+
// Keys pressed while the splash is on screen queue up rather than repainting
|
|
200
|
+
// the dashboard underneath a frame the intro is still animating over.
|
|
201
|
+
let introActive = true;
|
|
202
|
+
const dispatch = (keys) => {
|
|
203
|
+
if (!keys.length)
|
|
204
|
+
return;
|
|
205
|
+
if (introKeyWaiter) {
|
|
206
|
+
// The splash consumes the key that dismisses it; the rest still count.
|
|
207
|
+
const resolveIntro = introKeyWaiter;
|
|
208
|
+
introKeyWaiter = undefined;
|
|
209
|
+
keys = keys.slice(1);
|
|
210
|
+
resolveIntro();
|
|
211
|
+
}
|
|
212
|
+
keyQueue.push(...keys);
|
|
213
|
+
void pump();
|
|
214
|
+
};
|
|
215
|
+
let pumping = false;
|
|
216
|
+
const pump = async () => {
|
|
217
|
+
if (pumping || introActive)
|
|
200
218
|
return;
|
|
219
|
+
pumping = true;
|
|
201
220
|
try {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
221
|
+
while (!exiting && keyQueue.length) {
|
|
222
|
+
while (!exiting && keyQueue.length) {
|
|
223
|
+
const key = keyQueue.shift();
|
|
224
|
+
try {
|
|
225
|
+
const keep = await shell.handleRawKey(key);
|
|
226
|
+
if (!keep) {
|
|
227
|
+
exiting = true;
|
|
228
|
+
keyQueue.length = 0;
|
|
229
|
+
finish();
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
catch (err) {
|
|
234
|
+
shell.setMessage(`Error: ${errorMessage(err)}`);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
if (!exiting)
|
|
238
|
+
await repaint();
|
|
207
239
|
}
|
|
208
|
-
await repaint();
|
|
209
240
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
await repaint();
|
|
241
|
+
finally {
|
|
242
|
+
pumping = false;
|
|
213
243
|
}
|
|
214
244
|
};
|
|
245
|
+
const onData = (chunk) => {
|
|
246
|
+
if (exiting)
|
|
247
|
+
return;
|
|
248
|
+
if (escTimer) {
|
|
249
|
+
clearTimeout(escTimer);
|
|
250
|
+
escTimer = undefined;
|
|
251
|
+
}
|
|
252
|
+
dispatch(decoder.push(chunk));
|
|
253
|
+
if (decoder.hasPending()) {
|
|
254
|
+
// A trailing ESC is either the Escape key or the head of a sequence split
|
|
255
|
+
// across reads. Wait briefly for the rest before treating it as Escape.
|
|
256
|
+
escTimer = setTimeout(() => { escTimer = undefined; dispatch(decoder.flush()); }, ESC_FLUSH_MS);
|
|
257
|
+
escTimer.unref?.();
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
const waitForIntroKeypress = () => new Promise((resolve) => { introKeyWaiter = resolve; });
|
|
215
261
|
const onResize = async () => { if (!exiting)
|
|
216
262
|
await repaint(); };
|
|
217
263
|
const onSignal = () => {
|
|
@@ -227,6 +273,12 @@ export async function startShell(phrenPath, profile) {
|
|
|
227
273
|
return;
|
|
228
274
|
cleanedUp = true;
|
|
229
275
|
stopPoll();
|
|
276
|
+
if (escTimer) {
|
|
277
|
+
clearTimeout(escTimer);
|
|
278
|
+
escTimer = undefined;
|
|
279
|
+
}
|
|
280
|
+
introKeyWaiter?.();
|
|
281
|
+
introKeyWaiter = undefined;
|
|
230
282
|
process.stdin.removeListener("data", onData);
|
|
231
283
|
process.stdout.removeListener("resize", onResize);
|
|
232
284
|
process.removeListener("SIGINT", onSignal);
|
|
@@ -242,8 +294,12 @@ export async function startShell(phrenPath, profile) {
|
|
|
242
294
|
process.once("SIGTERM", onSignal);
|
|
243
295
|
process.once("exit", onProcessExit);
|
|
244
296
|
try {
|
|
245
|
-
await playStartupIntro(phrenPath);
|
|
246
|
-
|
|
297
|
+
await playStartupIntro(phrenPath, resolveStartupIntroPlan(phrenPath), waitForIntroKeypress);
|
|
298
|
+
introKeyWaiter = undefined;
|
|
299
|
+
introActive = false;
|
|
300
|
+
if (!exiting)
|
|
301
|
+
await repaint();
|
|
302
|
+
void pump();
|
|
247
303
|
await exitPromise;
|
|
248
304
|
}
|
|
249
305
|
finally {
|
package/dist/shell/input.d.ts
CHANGED
|
@@ -53,5 +53,5 @@ export declare function getListItems(phrenPath: string, profile: string, state:
|
|
|
53
53
|
* Returns true if the key was handled.
|
|
54
54
|
*/
|
|
55
55
|
export declare function applyViewShortcut(host: NavigationHost, key: string): boolean;
|
|
56
|
-
export declare function handleNavigateKey(host: NavigationHost,
|
|
56
|
+
export declare function handleNavigateKey(host: NavigationHost, rawKey: string): Promise<boolean>;
|
|
57
57
|
export {};
|
package/dist/shell/input.js
CHANGED
|
@@ -802,7 +802,10 @@ export function applyViewShortcut(host, key) {
|
|
|
802
802
|
return false;
|
|
803
803
|
}
|
|
804
804
|
// ── Navigate-mode key handler ─────────────────────────────────────────────────
|
|
805
|
-
export async function handleNavigateKey(host,
|
|
805
|
+
export async function handleNavigateKey(host, rawKey) {
|
|
806
|
+
// Terminals in application-cursor mode send SS3 (ESC O A) instead of CSI
|
|
807
|
+
// (ESC [ A) for the arrow keys; normalise so both spellings navigate.
|
|
808
|
+
const key = /^\x1bO[A-D]$/.test(rawKey) ? `\x1b[${rawKey[2]}` : rawKey;
|
|
806
809
|
if (key === "\x1b[A") {
|
|
807
810
|
host.moveCursor(-1);
|
|
808
811
|
showCursorPosition(host);
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Raw-mode stdin decoder.
|
|
3
|
+
*
|
|
4
|
+
* Node hands us whatever bytes happened to arrive in one read, not one keypress.
|
|
5
|
+
* Key autorepeat, fast typing, mouse-wheel-as-arrows, and paste all coalesce
|
|
6
|
+
* several keys into a single "data" chunk (e.g. "\x1b[B\x1b[B\x1b[B" or "ub"),
|
|
7
|
+
* and any handler that compares the whole chunk against a single key drops
|
|
8
|
+
* everything but an exact match. This splits a chunk back into discrete keys.
|
|
9
|
+
*
|
|
10
|
+
* A chunk can also end mid-sequence, so trailing partial escapes are buffered
|
|
11
|
+
* and prepended to the next chunk. A lone ESC is indistinguishable from the
|
|
12
|
+
* start of a split sequence, so the caller flushes on a short timer (see
|
|
13
|
+
* ESC_FLUSH_MS) to keep the Escape key responsive.
|
|
14
|
+
*/
|
|
15
|
+
/** How long to wait for the rest of an escape sequence before treating ESC as the Escape key. */
|
|
16
|
+
export declare const ESC_FLUSH_MS = 30;
|
|
17
|
+
/**
|
|
18
|
+
* Split `buf` into discrete keys.
|
|
19
|
+
*
|
|
20
|
+
* Returns the decoded keys plus any trailing bytes that form an incomplete
|
|
21
|
+
* escape sequence; the caller must prepend `pending` to the next chunk.
|
|
22
|
+
*/
|
|
23
|
+
export declare function decodeKeys(buf: string): {
|
|
24
|
+
keys: string[];
|
|
25
|
+
pending: string;
|
|
26
|
+
};
|
|
27
|
+
/** Stateful wrapper that carries incomplete sequences across chunk boundaries. */
|
|
28
|
+
export declare class KeyDecoder {
|
|
29
|
+
private pending;
|
|
30
|
+
/** Decode a stdin chunk into discrete keys. */
|
|
31
|
+
push(chunk: string): string[];
|
|
32
|
+
/** True when a partial sequence is buffered and a flush timer should be armed. */
|
|
33
|
+
hasPending(): boolean;
|
|
34
|
+
/** Emit buffered bytes as literal keys — call when no continuation arrived in time. */
|
|
35
|
+
flush(): string[];
|
|
36
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Raw-mode stdin decoder.
|
|
3
|
+
*
|
|
4
|
+
* Node hands us whatever bytes happened to arrive in one read, not one keypress.
|
|
5
|
+
* Key autorepeat, fast typing, mouse-wheel-as-arrows, and paste all coalesce
|
|
6
|
+
* several keys into a single "data" chunk (e.g. "\x1b[B\x1b[B\x1b[B" or "ub"),
|
|
7
|
+
* and any handler that compares the whole chunk against a single key drops
|
|
8
|
+
* everything but an exact match. This splits a chunk back into discrete keys.
|
|
9
|
+
*
|
|
10
|
+
* A chunk can also end mid-sequence, so trailing partial escapes are buffered
|
|
11
|
+
* and prepended to the next chunk. A lone ESC is indistinguishable from the
|
|
12
|
+
* start of a split sequence, so the caller flushes on a short timer (see
|
|
13
|
+
* ESC_FLUSH_MS) to keep the Escape key responsive.
|
|
14
|
+
*/
|
|
15
|
+
/** How long to wait for the rest of an escape sequence before treating ESC as the Escape key. */
|
|
16
|
+
export const ESC_FLUSH_MS = 30;
|
|
17
|
+
const ESC = "\x1b";
|
|
18
|
+
// One code point plus any trailing combining marks / variation selectors, so a
|
|
19
|
+
// surrogate pair or accented character is never split down the middle.
|
|
20
|
+
const GRAPHEME = /^(?:\P{M}\p{M}*)/u;
|
|
21
|
+
function nextChar(buf, i) {
|
|
22
|
+
const m = GRAPHEME.exec(buf.slice(i));
|
|
23
|
+
return m ? m[0] : buf[i];
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Split `buf` into discrete keys.
|
|
27
|
+
*
|
|
28
|
+
* Returns the decoded keys plus any trailing bytes that form an incomplete
|
|
29
|
+
* escape sequence; the caller must prepend `pending` to the next chunk.
|
|
30
|
+
*/
|
|
31
|
+
export function decodeKeys(buf) {
|
|
32
|
+
const keys = [];
|
|
33
|
+
let i = 0;
|
|
34
|
+
while (i < buf.length) {
|
|
35
|
+
const ch = buf[i];
|
|
36
|
+
if (ch !== ESC) {
|
|
37
|
+
const char = nextChar(buf, i);
|
|
38
|
+
keys.push(char);
|
|
39
|
+
i += char.length;
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
// ESC is the last byte we have — could be the Escape key or a split sequence.
|
|
43
|
+
if (i + 1 >= buf.length)
|
|
44
|
+
return { keys, pending: buf.slice(i) };
|
|
45
|
+
const next = buf[i + 1];
|
|
46
|
+
// ESC ESC — the first is a complete Escape keypress.
|
|
47
|
+
if (next === ESC) {
|
|
48
|
+
keys.push(ESC);
|
|
49
|
+
i += 1;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
// CSI: ESC [ params intermediates final
|
|
53
|
+
if (next === "[") {
|
|
54
|
+
let j = i + 2;
|
|
55
|
+
while (j < buf.length && buf[j] >= "\x30" && buf[j] <= "\x3f")
|
|
56
|
+
j++;
|
|
57
|
+
while (j < buf.length && buf[j] >= "\x20" && buf[j] <= "\x2f")
|
|
58
|
+
j++;
|
|
59
|
+
if (j >= buf.length)
|
|
60
|
+
return { keys, pending: buf.slice(i) };
|
|
61
|
+
if (buf[j] >= "\x40" && buf[j] <= "\x7e") {
|
|
62
|
+
keys.push(buf.slice(i, j + 1));
|
|
63
|
+
i = j + 1;
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
// Malformed — drop the ESC [ introducer and resync on the next byte.
|
|
67
|
+
i += 2;
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
// SS3: ESC O <final> — arrows in application cursor mode, F1-F4.
|
|
71
|
+
if (next === "O") {
|
|
72
|
+
if (i + 2 >= buf.length)
|
|
73
|
+
return { keys, pending: buf.slice(i) };
|
|
74
|
+
keys.push(buf.slice(i, i + 3));
|
|
75
|
+
i += 3;
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
// ESC followed by a printable character. The shell binds no Alt combos, so
|
|
79
|
+
// emitting them separately recovers both keys (Esc-then-shortcut is common)
|
|
80
|
+
// instead of dropping an unrecognised two-character token.
|
|
81
|
+
keys.push(ESC);
|
|
82
|
+
i += 1;
|
|
83
|
+
}
|
|
84
|
+
return { keys, pending: "" };
|
|
85
|
+
}
|
|
86
|
+
/** Stateful wrapper that carries incomplete sequences across chunk boundaries. */
|
|
87
|
+
export class KeyDecoder {
|
|
88
|
+
pending = "";
|
|
89
|
+
/** Decode a stdin chunk into discrete keys. */
|
|
90
|
+
push(chunk) {
|
|
91
|
+
const { keys, pending } = decodeKeys(this.pending + chunk);
|
|
92
|
+
this.pending = pending;
|
|
93
|
+
return keys;
|
|
94
|
+
}
|
|
95
|
+
/** True when a partial sequence is buffered and a flush timer should be armed. */
|
|
96
|
+
hasPending() { return this.pending.length > 0; }
|
|
97
|
+
/** Emit buffered bytes as literal keys — call when no continuation arrived in time. */
|
|
98
|
+
flush() {
|
|
99
|
+
if (!this.pending)
|
|
100
|
+
return [];
|
|
101
|
+
const buffered = this.pending;
|
|
102
|
+
this.pending = "";
|
|
103
|
+
// A lone ESC is the Escape key; anything longer is a sequence the terminal
|
|
104
|
+
// truncated, so surface it whole and let the handler ignore it.
|
|
105
|
+
return buffered === ESC ? [ESC] : [buffered];
|
|
106
|
+
}
|
|
107
|
+
}
|
package/dist/shell/render.d.ts
CHANGED
|
@@ -29,6 +29,8 @@ export declare const style: {
|
|
|
29
29
|
export declare function badge(label: string, colorFn: (s: string) => string): string;
|
|
30
30
|
export declare function separator(width?: number): string;
|
|
31
31
|
export declare function stripAnsi(s: string): string;
|
|
32
|
+
/** Terminal cells occupied by `s`, ignoring any ANSI escape codes it contains. */
|
|
33
|
+
export declare function displayWidth(s: string): number;
|
|
32
34
|
export declare function padToWidth(s: string, width: number): string;
|
|
33
35
|
export declare function truncateLine(s: string, cols: number): string;
|
|
34
36
|
export declare function renderWidth(columns?: number): number;
|
|
@@ -46,5 +48,36 @@ export declare function lineViewport(allLines: string[], cursorFirstLine: number
|
|
|
46
48
|
export declare function shellHelpText(): string;
|
|
47
49
|
export declare function clearScreen(): void;
|
|
48
50
|
export declare function clearToEnd(): void;
|
|
51
|
+
/** Switch to the alternate screen buffer and put the terminal in TUI mode. */
|
|
52
|
+
export declare function enterFullscreen(): void;
|
|
53
|
+
/** Undo enterFullscreen(). Safe to call more than once. */
|
|
54
|
+
export declare function exitFullscreen(): void;
|
|
55
|
+
/**
|
|
56
|
+
* Write one frame as a single synchronized write.
|
|
57
|
+
*
|
|
58
|
+
* The old path issued three separate writes (home, body, erase-to-end) with the
|
|
59
|
+
* cursor visible, which let a concurrent repaint interleave between them and
|
|
60
|
+
* dragged the caret across the screen on every keystroke.
|
|
61
|
+
*/
|
|
62
|
+
export declare function paintFrame(frame: string): void;
|
|
63
|
+
/**
|
|
64
|
+
* Lay out one splash frame from the character art the caller supplies (a live
|
|
65
|
+
* animation frame, or the static art).
|
|
66
|
+
*
|
|
67
|
+
* Every branch is chosen so the result fits the terminal it is about to be
|
|
68
|
+
* painted into: the wide layout needs room for art + gap + logo, the stacked
|
|
69
|
+
* one drops the logo rather than clipping it, and a terminal too short for the
|
|
70
|
+
* character drops the character rather than pushing the tagline off the bottom.
|
|
71
|
+
* A frame taller than the screen would scroll the alternate buffer, and once it
|
|
72
|
+
* scrolls every later cursor-home repaint lands on shifted rows, stacking the
|
|
73
|
+
* frames on top of each other.
|
|
74
|
+
*/
|
|
75
|
+
export declare function composeStartupFrame(artLines: string[], version: string, hint?: string): string[];
|
|
76
|
+
/**
|
|
77
|
+
* Clamp a frame to the terminal before painting: truncate each line to the
|
|
78
|
+
* render width, erase whatever the previous frame left to the right of it, and
|
|
79
|
+
* drop rows past the bottom so the frame can never scroll the screen.
|
|
80
|
+
*/
|
|
81
|
+
export declare function fitFrame(lines: string[]): string;
|
|
49
82
|
export declare function shellStartupFrames(version: string): string[];
|
|
50
83
|
export {};
|