@carrieros/cli 0.1.0
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.md +305 -0
- package/dist/commands/chat.js +93 -0
- package/dist/commands/doctor.js +54 -0
- package/dist/commands/files.js +33 -0
- package/dist/commands/help.js +35 -0
- package/dist/commands/history.js +47 -0
- package/dist/commands/login.js +59 -0
- package/dist/commands/logout.js +15 -0
- package/dist/commands/mode-model.js +28 -0
- package/dist/commands/models.js +28 -0
- package/dist/commands/modes.js +27 -0
- package/dist/commands/sessions.js +123 -0
- package/dist/commands/upload.js +50 -0
- package/dist/commands/usage.js +31 -0
- package/dist/commands/version.js +28 -0
- package/dist/commands/whoami.js +40 -0
- package/dist/main.js +94 -0
- package/dist/services/api.js +115 -0
- package/dist/services/config.js +72 -0
- package/dist/services/context.js +42 -0
- package/dist/services/login-flow.js +15 -0
- package/dist/services/meta.js +13 -0
- package/dist/services/output.js +54 -0
- package/dist/services/spinner.js +18 -0
- package/dist/shell/shell-chat.js +280 -0
- package/dist/shell/shell-commands.js +168 -0
- package/dist/shell/shell-prompt.js +48 -0
- package/dist/shell/shell-renderer.js +70 -0
- package/dist/shell/shell-router.js +21 -0
- package/dist/shell/shell.js +139 -0
- package/dist/types/index.js +4 -0
- package/dist/ui/activity.js +77 -0
- package/dist/ui/banner.js +70 -0
- package/dist/ui/chat-renderer.js +269 -0
- package/dist/ui/code-block.js +52 -0
- package/dist/ui/color-picker.js +79 -0
- package/dist/ui/colors.js +47 -0
- package/dist/ui/command-filter.js +57 -0
- package/dist/ui/command-item.js +6 -0
- package/dist/ui/command-palette.js +306 -0
- package/dist/ui/command-registry.js +47 -0
- package/dist/ui/command-renderer.js +55 -0
- package/dist/ui/composer-layout.js +27 -0
- package/dist/ui/live.js +124 -0
- package/dist/ui/logo.js +58 -0
- package/dist/ui/markdown.js +151 -0
- package/dist/ui/message.js +38 -0
- package/dist/ui/select.js +114 -0
- package/dist/ui/spinner.js +23 -0
- package/dist/ui/sticky-stream.js +64 -0
- package/dist/ui/theme.js +63 -0
- package/dist/ui/ui.js +75 -0
- package/package.json +64 -0
package/dist/ui/live.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import * as readline from "node:readline";
|
|
2
|
+
import { c } from "./colors.js";
|
|
3
|
+
import { MARGIN, contentWidth } from "./composer-layout.js";
|
|
4
|
+
/** Non-TTY fallback: commits print normally, the bar/status are no-ops. */
|
|
5
|
+
const passthrough = {
|
|
6
|
+
setStatus: () => { },
|
|
7
|
+
commitStatus: () => { },
|
|
8
|
+
commit: (lines) => {
|
|
9
|
+
if (lines.length)
|
|
10
|
+
process.stdout.write(lines.join("\n") + "\n");
|
|
11
|
+
},
|
|
12
|
+
stop: () => { }
|
|
13
|
+
};
|
|
14
|
+
export function startLiveComposer(footer = "") {
|
|
15
|
+
const stdout = process.stdout;
|
|
16
|
+
if (!stdout.isTTY)
|
|
17
|
+
return passthrough;
|
|
18
|
+
let status = [];
|
|
19
|
+
let shown = []; // the transient region currently on screen (status + bar)
|
|
20
|
+
const ANSI = /\x1b\[[0-9;]*m/g;
|
|
21
|
+
// Full row width (margin + fixed content column) — used only to pad rows so an
|
|
22
|
+
// overwrite fully covers the previous content; the composer itself is fixed.
|
|
23
|
+
const width = () => MARGIN.length + contentWidth() + 1;
|
|
24
|
+
const pad = (s) => {
|
|
25
|
+
const vis = s.replace(ANSI, "").length;
|
|
26
|
+
const w = width();
|
|
27
|
+
return vis >= w ? s : s + " ".repeat(w - vis);
|
|
28
|
+
};
|
|
29
|
+
const barLines = () => {
|
|
30
|
+
const inner = contentWidth();
|
|
31
|
+
const rule = MARGIN + c.rule("─".repeat(inner));
|
|
32
|
+
const prompt = MARGIN + c.brand("❯") + " " + " ".repeat(Math.max(0, inner - 2));
|
|
33
|
+
return footer ? [rule, prompt, rule, footer] : [rule, prompt, rule];
|
|
34
|
+
};
|
|
35
|
+
const region = () => [...status, ...barLines()];
|
|
36
|
+
// Move the cursor from the bottom of the current region up to its top row.
|
|
37
|
+
const toTop = () => {
|
|
38
|
+
const bottom = Math.max(0, shown.length - 1);
|
|
39
|
+
if (bottom > 0)
|
|
40
|
+
readline.moveCursor(stdout, 0, -bottom);
|
|
41
|
+
readline.cursorTo(stdout, 0);
|
|
42
|
+
};
|
|
43
|
+
// In-place, line-diffed repaint. Only rewrites lines that changed, and writes
|
|
44
|
+
// each row padded to full width so the new content OVERWRITES the old with no
|
|
45
|
+
// intermediate clear — no blank flash, so no flicker. Navigation uses relative
|
|
46
|
+
// cursor moves (existing rows), never "\n", so nothing scrolls.
|
|
47
|
+
const repaint = () => {
|
|
48
|
+
const next = region();
|
|
49
|
+
toTop();
|
|
50
|
+
const n = Math.max(next.length, shown.length);
|
|
51
|
+
for (let i = 0; i < n; i++) {
|
|
52
|
+
readline.cursorTo(stdout, 0);
|
|
53
|
+
if (i >= next.length) {
|
|
54
|
+
stdout.write(pad("")); // blank a now-removed row (full-width spaces)
|
|
55
|
+
}
|
|
56
|
+
else if (next[i] !== shown[i]) {
|
|
57
|
+
stdout.write(pad(next[i]));
|
|
58
|
+
}
|
|
59
|
+
if (i < n - 1)
|
|
60
|
+
readline.moveCursor(stdout, 0, 1);
|
|
61
|
+
}
|
|
62
|
+
// Park the cursor at the bottom row of the new region.
|
|
63
|
+
const cur = n - 1;
|
|
64
|
+
const bottom = Math.max(0, next.length - 1);
|
|
65
|
+
if (cur > bottom)
|
|
66
|
+
readline.moveCursor(stdout, 0, -(cur - bottom));
|
|
67
|
+
readline.cursorTo(stdout, 0);
|
|
68
|
+
shown = next;
|
|
69
|
+
};
|
|
70
|
+
// Print permanent lines above the bar, then redraw the region beneath them.
|
|
71
|
+
// Full-width overwrites (no clears) + "\n" so growth scrolls into history.
|
|
72
|
+
const commit = (committed) => {
|
|
73
|
+
toTop();
|
|
74
|
+
const next = region();
|
|
75
|
+
const block = [...committed, ...next];
|
|
76
|
+
for (let i = 0; i < block.length; i++) {
|
|
77
|
+
readline.cursorTo(stdout, 0);
|
|
78
|
+
stdout.write(pad(block[i]));
|
|
79
|
+
if (i < block.length - 1)
|
|
80
|
+
stdout.write("\n");
|
|
81
|
+
}
|
|
82
|
+
// If the previous region was taller than the block, blank the leftover rows.
|
|
83
|
+
const extra = shown.length - block.length;
|
|
84
|
+
for (let k = 0; k < extra; k++) {
|
|
85
|
+
stdout.write("\n");
|
|
86
|
+
readline.cursorTo(stdout, 0);
|
|
87
|
+
stdout.write(pad(""));
|
|
88
|
+
}
|
|
89
|
+
if (extra > 0)
|
|
90
|
+
readline.moveCursor(stdout, 0, -extra);
|
|
91
|
+
shown = next;
|
|
92
|
+
};
|
|
93
|
+
// Hide the real cursor while the region redraws — otherwise it visibly
|
|
94
|
+
// flickers as it jumps between the spinner and the bar on every frame.
|
|
95
|
+
stdout.write("\x1b[?25l");
|
|
96
|
+
// Initial draw.
|
|
97
|
+
stdout.write(region().join("\n"));
|
|
98
|
+
shown = region();
|
|
99
|
+
return {
|
|
100
|
+
setStatus: (lines) => {
|
|
101
|
+
status = lines;
|
|
102
|
+
// Same height → in-place diff (flicker-free spinner frames). Height change
|
|
103
|
+
// (spinner appearing/clearing) → scroll-safe redraw via commit([]).
|
|
104
|
+
if (region().length === shown.length)
|
|
105
|
+
repaint();
|
|
106
|
+
else
|
|
107
|
+
commit([]);
|
|
108
|
+
},
|
|
109
|
+
commitStatus: () => {
|
|
110
|
+
// The status lines are already drawn where they'll stay; re-emit them as
|
|
111
|
+
// committed (with an empty status) so the on-screen result is identical.
|
|
112
|
+
const promoted = status;
|
|
113
|
+
status = [];
|
|
114
|
+
commit(promoted);
|
|
115
|
+
},
|
|
116
|
+
commit,
|
|
117
|
+
stop: () => {
|
|
118
|
+
toTop();
|
|
119
|
+
readline.clearScreenDown(stdout);
|
|
120
|
+
stdout.write("\x1b[?25h"); // restore the cursor for the interactive reader
|
|
121
|
+
shown = [];
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
}
|
package/dist/ui/logo.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// Terminal-native Carrier OS logo — pure Unicode + block-drawing characters,
|
|
2
|
+
// no images / sixel / iTerm protocol. Coloring is applied in ui/banner.ts via
|
|
3
|
+
// ui/colors.ts; these are stored plain so they stay portable and testable.
|
|
4
|
+
/** Neural-network node mark (rendered in bright green). */
|
|
5
|
+
export const NEURAL_NODE = ` ◉
|
|
6
|
+
╱──┼──╲
|
|
7
|
+
◉───●───◉
|
|
8
|
+
╲──┼──╱
|
|
9
|
+
◉`;
|
|
10
|
+
/**
|
|
11
|
+
* A decorative "neural constellation" scene shown above the wordmark — glowing
|
|
12
|
+
* nodes wired into a small network amongst a scattering of stars, framed by a
|
|
13
|
+
* dotted rule. Carrier's own take on a premium welcome scene.
|
|
14
|
+
*/
|
|
15
|
+
export const SCENE = [
|
|
16
|
+
"· · · · · · · · · · · · · · · · · · · · · · · · · · ·",
|
|
17
|
+
" ✦ · ◦ ·",
|
|
18
|
+
" ◉───────────●───────────◉ ·",
|
|
19
|
+
" ╲ ╱ ╲ ╱ ✦",
|
|
20
|
+
" · ●───────◉ ◉───────● ◦",
|
|
21
|
+
" ╱ ╲ ╱ ╲ ·",
|
|
22
|
+
" ◉───────────●───────────◉ ✦",
|
|
23
|
+
" · ✦ ◦",
|
|
24
|
+
"· · · · · · · · · · · · · · · · · · · · · · · · · · ·"
|
|
25
|
+
].join("\n");
|
|
26
|
+
// The "CARRIER OS" wordmark, composed letter-by-letter so we can control the gap
|
|
27
|
+
// between glyphs (the packed font ran them together). A space glyph gives a wider
|
|
28
|
+
// word break between CARRIER and OS.
|
|
29
|
+
const GLYPHS = {
|
|
30
|
+
C: [" ██████╗", "██╔════╝", "██║ ", "██║ ", "╚██████╗", " ╚═════╝"],
|
|
31
|
+
A: [" █████╗ ", "██╔══██╗", "███████║", "██╔══██║", "██║ ██║", "╚═╝ ╚═╝"],
|
|
32
|
+
R: ["██████╗ ", "██╔══██╗", "██████╔╝", "██╔══██╗", "██║ ╚██╗", "╚═╝ ╚═╝"],
|
|
33
|
+
I: ["██╗", "██║", "██║", "██║", "██║", "╚═╝"],
|
|
34
|
+
E: ["███████╗", "██╔════╝", "█████╗ ", "██╔══╝ ", "███████╗", "╚══════╝"],
|
|
35
|
+
O: [" ██████╗ ", "██╔═══██╗", "██║ ██║", "██║ ██║", "╚██████╔╝", " ╚═════╝ "],
|
|
36
|
+
S: ["███████╗", "██╔════╝", "███████╗", "╚════██║", "███████║", "╚══════╝"],
|
|
37
|
+
" ": [" ", " ", " ", " ", " ", " "]
|
|
38
|
+
};
|
|
39
|
+
// A gentle forward-lean (italic) shear applied per row, top → bottom. Upper rows
|
|
40
|
+
// shift right so each letter slants slightly, like an italic wordmark.
|
|
41
|
+
const SHEAR = [1, 1, 1, 0, 0, 0];
|
|
42
|
+
/** Skew a 6-row glyph and pad it back to a fixed-width box. */
|
|
43
|
+
function shearGlyph(rows) {
|
|
44
|
+
const shifted = rows.map((r, i) => " ".repeat(SHEAR[i] ?? 0) + r);
|
|
45
|
+
const w = Math.max(...shifted.map((r) => [...r].length));
|
|
46
|
+
return shifted.map((r) => r.padEnd(w));
|
|
47
|
+
}
|
|
48
|
+
function composeWordmark(word, gap = " ") {
|
|
49
|
+
const letters = [...word].map((ch) => shearGlyph(GLYPHS[ch]));
|
|
50
|
+
const rows = [];
|
|
51
|
+
for (let r = 0; r < 6; r++)
|
|
52
|
+
rows.push(letters.map((g) => g[r]).join(gap));
|
|
53
|
+
return rows.join("\n");
|
|
54
|
+
}
|
|
55
|
+
/** "CARRIER OS" slightly-inclined block wordmark (rendered in white). */
|
|
56
|
+
export const WORDMARK = composeWordmark("CARRIER OS", " ");
|
|
57
|
+
/** Compact mark for very narrow terminals (avoids wrapping the block art). */
|
|
58
|
+
export const COMPACT_MARK = "◉─●─◉";
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import { c } from "./colors.js";
|
|
3
|
+
import { renderCodeBlock } from "./code-block.js";
|
|
4
|
+
import { textWidth } from "./composer-layout.js";
|
|
5
|
+
/**
|
|
6
|
+
* Self-contained Markdown → ANSI renderer (no dependency). Supports headings,
|
|
7
|
+
* bold/italic, inline code, links, bullet/numbered/task lists, blockquotes,
|
|
8
|
+
* horizontal rules, tables and fenced code blocks — with soft word-wrap so long
|
|
9
|
+
* paragraphs never overflow or cut words. Returns col-0 lines; callers indent.
|
|
10
|
+
*/
|
|
11
|
+
export function renderMarkdown(md) {
|
|
12
|
+
const wrap = Math.max(20, textWidth() - 4);
|
|
13
|
+
const out = [];
|
|
14
|
+
const lines = md.replace(/\r/g, "").split("\n");
|
|
15
|
+
let i = 0;
|
|
16
|
+
const flushTable = (rows) => {
|
|
17
|
+
out.push(...renderTable(rows));
|
|
18
|
+
};
|
|
19
|
+
while (i < lines.length) {
|
|
20
|
+
const raw = lines[i];
|
|
21
|
+
// Fenced code block.
|
|
22
|
+
const fence = raw.match(/^\s*```(.*)$/);
|
|
23
|
+
if (fence) {
|
|
24
|
+
const lang = fence[1].trim();
|
|
25
|
+
const body = [];
|
|
26
|
+
i++;
|
|
27
|
+
while (i < lines.length && !/^\s*```/.test(lines[i]))
|
|
28
|
+
body.push(lines[i++]);
|
|
29
|
+
i++; // closing fence
|
|
30
|
+
out.push(...renderCodeBlock(body.join("\n"), lang));
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
// Table block (consecutive pipe rows).
|
|
34
|
+
if (/^\s*\|.*\|\s*$/.test(raw)) {
|
|
35
|
+
const rows = [];
|
|
36
|
+
while (i < lines.length && /^\s*\|.*\|\s*$/.test(lines[i]))
|
|
37
|
+
rows.push(lines[i++]);
|
|
38
|
+
flushTable(rows);
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
// Horizontal rule.
|
|
42
|
+
if (/^\s*([-*_])\1{2,}\s*$/.test(raw)) {
|
|
43
|
+
out.push(c.rule("─".repeat(Math.min(wrap, 40))));
|
|
44
|
+
i++;
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
// Heading.
|
|
48
|
+
const h = raw.match(/^(#{1,6})\s+(.*)$/);
|
|
49
|
+
if (h) {
|
|
50
|
+
out.push(h[1].length === 1 ? c.brand(inline(h[2])) : c.title(inline(h[2])));
|
|
51
|
+
i++;
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
// Blockquote.
|
|
55
|
+
const quote = raw.match(/^\s*>\s?(.*)$/);
|
|
56
|
+
if (quote) {
|
|
57
|
+
for (const w of wrapText(quote[1], wrap - 2))
|
|
58
|
+
out.push(c.rule("│ ") + c.dim(inline(w)));
|
|
59
|
+
i++;
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
// Task list.
|
|
63
|
+
const task = raw.match(/^(\s*)[-*+]\s+\[([ xX])\]\s+(.*)$/);
|
|
64
|
+
if (task) {
|
|
65
|
+
const box = task[2].trim() ? c.ok("☑") : c.dim("☐");
|
|
66
|
+
const wrapped = wrapText(task[3], wrap - task[1].length - 4);
|
|
67
|
+
out.push(`${task[1]} ${box} ${inline(wrapped[0] ?? "")}`);
|
|
68
|
+
for (const w of wrapped.slice(1))
|
|
69
|
+
out.push(`${task[1]} ${inline(w)}`);
|
|
70
|
+
i++;
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
// Bullet list.
|
|
74
|
+
const bullet = raw.match(/^(\s*)[-*+]\s+(.*)$/);
|
|
75
|
+
if (bullet) {
|
|
76
|
+
const wrapped = wrapText(bullet[2], wrap - bullet[1].length - 4);
|
|
77
|
+
out.push(`${bullet[1]} ${c.accent("•")} ${inline(wrapped[0] ?? "")}`);
|
|
78
|
+
for (const w of wrapped.slice(1))
|
|
79
|
+
out.push(`${bullet[1]} ${inline(w)}`);
|
|
80
|
+
i++;
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
// Numbered list.
|
|
84
|
+
const num = raw.match(/^(\s*)(\d+)\.\s+(.*)$/);
|
|
85
|
+
if (num) {
|
|
86
|
+
const marker = `${num[2]}.`;
|
|
87
|
+
const wrapped = wrapText(num[3], wrap - num[1].length - marker.length - 3);
|
|
88
|
+
out.push(`${num[1]} ${c.accent(marker)} ${inline(wrapped[0] ?? "")}`);
|
|
89
|
+
for (const w of wrapped.slice(1))
|
|
90
|
+
out.push(`${num[1]}${" ".repeat(marker.length + 3)}${inline(w)}`);
|
|
91
|
+
i++;
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
// Blank line.
|
|
95
|
+
if (raw.trim() === "") {
|
|
96
|
+
out.push("");
|
|
97
|
+
i++;
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
// Paragraph — soft wrap.
|
|
101
|
+
for (const w of wrapText(raw, wrap))
|
|
102
|
+
out.push(inline(w));
|
|
103
|
+
i++;
|
|
104
|
+
}
|
|
105
|
+
return out;
|
|
106
|
+
}
|
|
107
|
+
/** Word-wrap plain text to `width`, never cutting a word. */
|
|
108
|
+
function wrapText(text, width) {
|
|
109
|
+
const w = Math.max(20, width);
|
|
110
|
+
const words = text.trim().split(/\s+/).filter(Boolean);
|
|
111
|
+
if (!words.length)
|
|
112
|
+
return [""];
|
|
113
|
+
const lines = [];
|
|
114
|
+
let cur = "";
|
|
115
|
+
for (const word of words) {
|
|
116
|
+
if (cur && [...cur].length + 1 + [...word].length > w) {
|
|
117
|
+
lines.push(cur);
|
|
118
|
+
cur = word;
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
cur = cur ? `${cur} ${word}` : word;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (cur)
|
|
125
|
+
lines.push(cur);
|
|
126
|
+
return lines;
|
|
127
|
+
}
|
|
128
|
+
/** Inline spans: links, `code`, **bold**, *italic*, ~~strike~~. */
|
|
129
|
+
function inline(text) {
|
|
130
|
+
return text
|
|
131
|
+
.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (_m, label) => c.accent(label))
|
|
132
|
+
.replace(/`([^`]+)`/g, (_m, code) => c.accent(code))
|
|
133
|
+
.replace(/\*\*([^*]+)\*\*/g, (_m, b) => chalk.bold(b))
|
|
134
|
+
.replace(/~~([^~]+)~~/g, (_m, s) => chalk.strikethrough(s))
|
|
135
|
+
.replace(/(^|[^*])\*([^*]+)\*/g, (_m, pre, it) => `${pre}${chalk.italic(it)}`);
|
|
136
|
+
}
|
|
137
|
+
/** Render a Markdown table with aligned columns. */
|
|
138
|
+
function renderTable(rows) {
|
|
139
|
+
const cells = rows.map((r) => r.trim().replace(/^\|/, "").replace(/\|$/, "").split("|").map((x) => x.trim()));
|
|
140
|
+
const body = cells.filter((r) => !r.every((x) => /^:?-{2,}:?$/.test(x)));
|
|
141
|
+
if (body.length === 0)
|
|
142
|
+
return [];
|
|
143
|
+
const cols = Math.max(...body.map((r) => r.length));
|
|
144
|
+
const widths = Array.from({ length: cols }, (_, i) => Math.max(...body.map((r) => (r[i] ?? "").length)));
|
|
145
|
+
const row = (r, color) => r.map((cell, i) => color((cell ?? "").padEnd(widths[i]))).join(c.rule(" │ "));
|
|
146
|
+
const out = [row(body[0], c.title)];
|
|
147
|
+
out.push(widths.map((w) => c.rule("─".repeat(w))).join(c.rule("──┼──")));
|
|
148
|
+
for (const r of body.slice(1))
|
|
149
|
+
out.push(row(r, c.value));
|
|
150
|
+
return out;
|
|
151
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import { line } from "../services/output.js";
|
|
3
|
+
import { MARGIN, contentWidth } from "./composer-layout.js";
|
|
4
|
+
/**
|
|
5
|
+
* Renders a user turn as a subtly-shaded bar led by a `❯` — the Claude-style
|
|
6
|
+
* "your message" band. Fixed to the composer width (never full-terminal), so it
|
|
7
|
+
* stays a stable UI block on resize. Long messages wrap within the bar.
|
|
8
|
+
*/
|
|
9
|
+
const BAR_BG = "#2b2b2e";
|
|
10
|
+
export function renderUserMessage(text) {
|
|
11
|
+
const w = contentWidth();
|
|
12
|
+
const bar = chalk.bgHex(BAR_BG).white;
|
|
13
|
+
for (const [i, l] of wrap(text, w - 3).entries()) {
|
|
14
|
+
const content = (i === 0 ? "❯ " : " ") + l;
|
|
15
|
+
line(MARGIN + bar(content.padEnd(w)));
|
|
16
|
+
}
|
|
17
|
+
line(); // single trailing blank — the next block leads straight in
|
|
18
|
+
}
|
|
19
|
+
function wrap(text, width) {
|
|
20
|
+
const w = Math.max(20, width);
|
|
21
|
+
const words = text.trim().split(/\s+/).filter(Boolean);
|
|
22
|
+
if (!words.length)
|
|
23
|
+
return [""];
|
|
24
|
+
const lines = [];
|
|
25
|
+
let cur = "";
|
|
26
|
+
for (const word of words) {
|
|
27
|
+
if (cur && [...cur].length + 1 + [...word].length > w) {
|
|
28
|
+
lines.push(cur);
|
|
29
|
+
cur = word;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
cur = cur ? `${cur} ${word}` : word;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
if (cur)
|
|
36
|
+
lines.push(cur);
|
|
37
|
+
return lines;
|
|
38
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import * as readline from "node:readline";
|
|
2
|
+
import { c } from "./colors.js";
|
|
3
|
+
import { termWidth } from "./ui.js";
|
|
4
|
+
export function pickFromList(opts) {
|
|
5
|
+
const { title, description = "", choices } = opts;
|
|
6
|
+
if (!process.stdin.isTTY || choices.length === 0) {
|
|
7
|
+
return Promise.resolve(choices[opts.initial ?? 0]?.value ?? null);
|
|
8
|
+
}
|
|
9
|
+
return new Promise((resolve) => {
|
|
10
|
+
const stdin = process.stdin;
|
|
11
|
+
const stdout = process.stdout;
|
|
12
|
+
stdin.removeAllListeners("keypress");
|
|
13
|
+
readline.emitKeypressEvents(stdin);
|
|
14
|
+
const prevRaw = stdin.isRaw ?? false;
|
|
15
|
+
if (stdin.isTTY)
|
|
16
|
+
stdin.setRawMode(true);
|
|
17
|
+
stdin.resume();
|
|
18
|
+
let selected = Math.min(Math.max(0, opts.initial ?? 0), choices.length - 1);
|
|
19
|
+
let prevUp = 0;
|
|
20
|
+
const labelW = Math.min(30, Math.max(...choices.map((ch) => ch.label.length)));
|
|
21
|
+
const numW = String(choices.length).length;
|
|
22
|
+
const render = () => {
|
|
23
|
+
if (prevUp > 0)
|
|
24
|
+
readline.moveCursor(stdout, 0, -prevUp);
|
|
25
|
+
readline.cursorTo(stdout, 0);
|
|
26
|
+
readline.clearScreenDown(stdout);
|
|
27
|
+
const width = Math.min(termWidth() - 4, 92);
|
|
28
|
+
const lines = [" " + c.brand("─".repeat(width)), " " + c.brand.bold(title)];
|
|
29
|
+
if (description) {
|
|
30
|
+
for (const l of wrap(description, width))
|
|
31
|
+
lines.push(" " + c.dim(l));
|
|
32
|
+
}
|
|
33
|
+
lines.push("");
|
|
34
|
+
choices.forEach((ch, i) => {
|
|
35
|
+
const on = i === selected;
|
|
36
|
+
const pointer = on ? c.brand("❯ ") : " ";
|
|
37
|
+
const num = c.dim(`${String(i + 1).padStart(numW)}.`);
|
|
38
|
+
const label = (on ? c.brand.bold : c.value)(ch.label.padEnd(labelW));
|
|
39
|
+
const desc = ch.description ? " " + c.dim(ch.description) : "";
|
|
40
|
+
const mark = ch.current ? c.brand(" ✓") : "";
|
|
41
|
+
lines.push(" " + pointer + num + " " + label + desc + mark);
|
|
42
|
+
});
|
|
43
|
+
lines.push("");
|
|
44
|
+
lines.push(" " +
|
|
45
|
+
c.dim("↑↓ navigate · ") +
|
|
46
|
+
c.key("Enter") +
|
|
47
|
+
c.dim(" confirm · ") +
|
|
48
|
+
c.key("Esc") +
|
|
49
|
+
c.dim(" cancel"));
|
|
50
|
+
stdout.write(lines.join("\n"));
|
|
51
|
+
prevUp = lines.length - 1; // cursor rests on the last line; rewind from there next time
|
|
52
|
+
};
|
|
53
|
+
const finish = (val) => {
|
|
54
|
+
if (prevUp > 0)
|
|
55
|
+
readline.moveCursor(stdout, 0, -prevUp);
|
|
56
|
+
readline.cursorTo(stdout, 0);
|
|
57
|
+
readline.clearScreenDown(stdout);
|
|
58
|
+
stdin.removeListener("keypress", onKey);
|
|
59
|
+
stdin.setRawMode(prevRaw);
|
|
60
|
+
resolve(val);
|
|
61
|
+
};
|
|
62
|
+
const onKey = (str, key) => {
|
|
63
|
+
try {
|
|
64
|
+
if (!key)
|
|
65
|
+
return;
|
|
66
|
+
if (key.name === "up" || (key.ctrl && key.name === "p")) {
|
|
67
|
+
selected = (selected - 1 + choices.length) % choices.length;
|
|
68
|
+
return render();
|
|
69
|
+
}
|
|
70
|
+
if (key.name === "down" || (key.ctrl && key.name === "n")) {
|
|
71
|
+
selected = (selected + 1) % choices.length;
|
|
72
|
+
return render();
|
|
73
|
+
}
|
|
74
|
+
if (key.name === "return" || key.name === "enter")
|
|
75
|
+
return finish(choices[selected].value);
|
|
76
|
+
if (key.name === "escape" || (key.ctrl && (key.name === "c" || key.name === "d"))) {
|
|
77
|
+
return finish(null);
|
|
78
|
+
}
|
|
79
|
+
// Number keys jump to an option.
|
|
80
|
+
if (str && /^[1-9]$/.test(str)) {
|
|
81
|
+
const idx = Number(str) - 1;
|
|
82
|
+
if (idx < choices.length) {
|
|
83
|
+
selected = idx;
|
|
84
|
+
render();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
catch (err) {
|
|
89
|
+
stdout.write(`\n${c.err("Select error:")} ${err.message}\n`);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
stdin.on("keypress", onKey);
|
|
93
|
+
render();
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/** Minimal word wrap for the description line. */
|
|
97
|
+
function wrap(text, width) {
|
|
98
|
+
const w = Math.max(20, width);
|
|
99
|
+
const words = text.trim().split(/\s+/).filter(Boolean);
|
|
100
|
+
const lines = [];
|
|
101
|
+
let cur = "";
|
|
102
|
+
for (const word of words) {
|
|
103
|
+
if (cur && [...cur].length + 1 + [...word].length > w) {
|
|
104
|
+
lines.push(cur);
|
|
105
|
+
cur = word;
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
cur = cur ? `${cur} ${word}` : word;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (cur)
|
|
112
|
+
lines.push(cur);
|
|
113
|
+
return lines.length ? lines : [""];
|
|
114
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import ora from "ora";
|
|
2
|
+
/**
|
|
3
|
+
* A subtle braille "Thinking…" spinner (⠋⠙⠹…) shown while awaiting a response.
|
|
4
|
+
* `label` is pre-styled by the caller and may span multiple lines (e.g. a tip
|
|
5
|
+
* beneath the phrase) — ora clears all of them on stop so the streamed answer
|
|
6
|
+
* takes their place cleanly. `setText` lets the caller cycle the phrase while
|
|
7
|
+
* the spinner runs.
|
|
8
|
+
*/
|
|
9
|
+
export function thinking(label = "Thinking…") {
|
|
10
|
+
const spinner = ora({
|
|
11
|
+
text: label,
|
|
12
|
+
spinner: "dots",
|
|
13
|
+
color: "green",
|
|
14
|
+
// Leave stdin alone — the shell manages the terminal.
|
|
15
|
+
discardStdin: false
|
|
16
|
+
}).start();
|
|
17
|
+
return {
|
|
18
|
+
stop: () => spinner.stop(),
|
|
19
|
+
setText: (text) => {
|
|
20
|
+
spinner.text = text;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { c } from "./colors.js";
|
|
2
|
+
import { MARGIN, contentWidth } from "./composer-layout.js";
|
|
3
|
+
function barLines(footer) {
|
|
4
|
+
const w = contentWidth();
|
|
5
|
+
const rule = MARGIN + c.rule("─".repeat(w));
|
|
6
|
+
const prompt = MARGIN + c.brand("❯") + " " + " ".repeat(Math.max(0, w - 2));
|
|
7
|
+
return footer ? [rule, prompt, rule, footer] : [rule, prompt, rule];
|
|
8
|
+
}
|
|
9
|
+
// Reset the scroll region + restore the cursor if the process dies mid-stream,
|
|
10
|
+
// so a crash never leaves the terminal in a broken scrolling state.
|
|
11
|
+
let safetyInstalled = false;
|
|
12
|
+
function installSafety() {
|
|
13
|
+
if (safetyInstalled)
|
|
14
|
+
return;
|
|
15
|
+
safetyInstalled = true;
|
|
16
|
+
process.once("exit", () => {
|
|
17
|
+
try {
|
|
18
|
+
process.stdout.write("\x1b[r\x1b[?25h");
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
/* stream already closed */
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
export function startStickyStream(footer) {
|
|
26
|
+
const stdout = process.stdout;
|
|
27
|
+
if (!stdout.isTTY || !stdout.rows) {
|
|
28
|
+
// Non-TTY / unknown size: fall back to plain appends.
|
|
29
|
+
return {
|
|
30
|
+
scroll: () => stdout.write("\n"),
|
|
31
|
+
setLine: (t) => stdout.write("\r\x1b[2K" + t),
|
|
32
|
+
stop: () => stdout.write("\n")
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
installSafety();
|
|
36
|
+
const rows = stdout.rows;
|
|
37
|
+
const bar = barLines(footer);
|
|
38
|
+
const H = bar.length;
|
|
39
|
+
const bottom = Math.max(1, rows - H); // last content row; the bar occupies bottom+1..rows
|
|
40
|
+
const drawBar = () => {
|
|
41
|
+
for (let i = 0; i < H; i++) {
|
|
42
|
+
stdout.write(`\x1b[${bottom + 1 + i};1H\x1b[2K${bar[i]}`);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
stdout.write("\x1b[?25l"); // hide the caret (the ▋ is the cursor)
|
|
46
|
+
stdout.write("\x1b[999B"); // to the bottom row
|
|
47
|
+
stdout.write("\n".repeat(H)); // scroll up H rows to reserve the bar area
|
|
48
|
+
stdout.write(`\x1b[1;${bottom}r`); // scroll region = content rows 1..bottom
|
|
49
|
+
drawBar();
|
|
50
|
+
stdout.write(`\x1b[${bottom};1H`); // park at the bottom content row
|
|
51
|
+
return {
|
|
52
|
+
// LF at the scroll-region's bottom margin scrolls the region up by one; the
|
|
53
|
+
// bar (below the region) never moves.
|
|
54
|
+
scroll: () => stdout.write(`\x1b[${bottom};1H\n`),
|
|
55
|
+
setLine: (text) => stdout.write(`\x1b[${bottom};1H\x1b[2K${text}`),
|
|
56
|
+
stop: () => {
|
|
57
|
+
stdout.write("\x1b[r"); // reset the scroll region to the whole screen
|
|
58
|
+
// Clear the bar rows and park the cursor where it started, so the reader
|
|
59
|
+
// redraws its interactive bar in place (seamless hand-off).
|
|
60
|
+
stdout.write(`\x1b[${bottom + 1};1H\x1b[0J`);
|
|
61
|
+
stdout.write("\x1b[?25h");
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
}
|
package/dist/ui/theme.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
/**
|
|
3
|
+
* Theme manager — the single source of the CLI's accent color. Everything that
|
|
4
|
+
* renders in the accent (prompt, selection, assistant marker, thinking spinner,
|
|
5
|
+
* welcome accents, borders) pulls the current hex from here, so changing the
|
|
6
|
+
* accent at runtime (via /color) updates the whole UI without a restart and
|
|
7
|
+
* without recreating any Chalk instances.
|
|
8
|
+
*
|
|
9
|
+
* Future-ready: this is the seam a fuller theme (background, font, links) would
|
|
10
|
+
* plug into — add fields here, not scattered Chalk calls across the app.
|
|
11
|
+
*/
|
|
12
|
+
/** Named accent colors and their hex. `default` is Carrier OS green. */
|
|
13
|
+
export const THEME_COLORS = {
|
|
14
|
+
green: "#9ef56b",
|
|
15
|
+
cyan: "#22d3ee",
|
|
16
|
+
blue: "#60a5fa",
|
|
17
|
+
purple: "#a78bfa",
|
|
18
|
+
pink: "#f472b6",
|
|
19
|
+
yellow: "#facc15",
|
|
20
|
+
orange: "#fb923c",
|
|
21
|
+
red: "#f87171",
|
|
22
|
+
default: "#9ef56b"
|
|
23
|
+
};
|
|
24
|
+
/** Selector order, matching Claude's /color layout. */
|
|
25
|
+
export const THEME_ORDER = [
|
|
26
|
+
"red",
|
|
27
|
+
"blue",
|
|
28
|
+
"green",
|
|
29
|
+
"yellow",
|
|
30
|
+
"purple",
|
|
31
|
+
"orange",
|
|
32
|
+
"pink",
|
|
33
|
+
"cyan",
|
|
34
|
+
"default"
|
|
35
|
+
];
|
|
36
|
+
const DEFAULT_ACCENT = "green";
|
|
37
|
+
let current = DEFAULT_ACCENT;
|
|
38
|
+
export function isThemeColor(name) {
|
|
39
|
+
return Object.prototype.hasOwnProperty.call(THEME_COLORS, name);
|
|
40
|
+
}
|
|
41
|
+
/** The currently-selected accent name. */
|
|
42
|
+
export function accentName() {
|
|
43
|
+
return current;
|
|
44
|
+
}
|
|
45
|
+
/** Hex for a color name (defaults to the current accent). */
|
|
46
|
+
export function accentHex(name = current) {
|
|
47
|
+
return THEME_COLORS[name] ?? THEME_COLORS.green;
|
|
48
|
+
}
|
|
49
|
+
/** Switch the live accent. Takes effect immediately across the UI. */
|
|
50
|
+
export function setAccent(name) {
|
|
51
|
+
if (isThemeColor(name))
|
|
52
|
+
current = name;
|
|
53
|
+
}
|
|
54
|
+
/** Restore the persisted accent on startup (call once with config.theme.accent). */
|
|
55
|
+
export function loadAccent(saved) {
|
|
56
|
+
if (saved && isThemeColor(saved))
|
|
57
|
+
current = saved;
|
|
58
|
+
}
|
|
59
|
+
/** A Chalk instance in the current accent — created fresh so it always reflects
|
|
60
|
+
* the live accent. Prefer the `c.brand` getter in colors.ts for app code. */
|
|
61
|
+
export function accent() {
|
|
62
|
+
return chalk.hex(accentHex());
|
|
63
|
+
}
|