arc402-cli 0.7.4 → 0.7.5
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/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/tui/App.d.ts +9 -1
- package/dist/tui/App.d.ts.map +1 -1
- package/dist/tui/App.js +19 -7
- package/dist/tui/App.js.map +1 -1
- package/dist/tui/Header.d.ts +2 -1
- package/dist/tui/Header.d.ts.map +1 -1
- package/dist/tui/Header.js +3 -3
- package/dist/tui/Header.js.map +1 -1
- package/dist/tui/Viewport.d.ts +4 -5
- package/dist/tui/Viewport.d.ts.map +1 -1
- package/dist/tui/Viewport.js +7 -17
- package/dist/tui/Viewport.js.map +1 -1
- package/dist/tui/useCommand.d.ts +7 -2
- package/dist/tui/useCommand.d.ts.map +1 -1
- package/dist/tui/useCommand.js +152 -70
- package/dist/tui/useCommand.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +2 -2
- package/src/tui/App.tsx +43 -17
- package/src/tui/Header.tsx +9 -2
- package/src/tui/Viewport.tsx +18 -22
- package/src/tui/useCommand.ts +181 -84
package/dist/index.js
CHANGED
|
@@ -86,8 +86,8 @@ if (printMode) {
|
|
|
86
86
|
process.exit(1);
|
|
87
87
|
});
|
|
88
88
|
}
|
|
89
|
-
else if (process.stdout.isTTY && !hasSubcommand && process.argv.length <= 2) {
|
|
90
|
-
// TTY with no subcommand — launch Ink TUI
|
|
89
|
+
else if (process.stdout.isTTY && !hasSubcommand && process.argv.length <= 2 && !process.env.ARC402_NO_TUI) {
|
|
90
|
+
// TTY with no subcommand — launch Ink TUI (unless spawned by TUI as a child process)
|
|
91
91
|
checkUpgrade();
|
|
92
92
|
void Promise.resolve().then(() => __importStar(require("./tui/index"))).then(({ launchTUI }) => launchTUI()).catch((e) => {
|
|
93
93
|
console.error("TUI failed to start:", e instanceof Error ? e.message : String(e));
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|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AAC,CAAC,CAAC;QAC1D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;AACL,CAAC;KAAM,IAAI,OAAO,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,EAAE,CAAC;IAC5G,qFAAqF;IACrF,YAAY,EAAE,CAAC;IACf,KAAK,kDAAO,aAAa,IAAE,IAAI,CAAC,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,SAAS,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAU,EAAE,EAAE;QACnF,OAAO,CAAC,KAAK,CAAC,sBAAsB,EAAE,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;QAClF,mBAAmB;QACnB,KAAK,IAAA,gBAAS,GAAE,CAAC;IACnB,CAAC,CAAC,CAAC;AACL,CAAC;KAAM,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;IACpC,qDAAqD;IACrD,YAAY,EAAE,CAAC;IACf,KAAK,IAAA,gBAAS,GAAE,CAAC;AACnB,CAAC;KAAM,CAAC;IACN,4DAA4D;IAC5D,YAAY,EAAE,CAAC;IACf,MAAM,OAAO,GAAG,IAAA,uBAAa,GAAE,CAAC;IAChC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAC9B,CAAC"}
|
package/dist/tui/App.d.ts
CHANGED
|
@@ -5,7 +5,15 @@ interface AppProps {
|
|
|
5
5
|
balance?: string;
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
|
-
* Root TUI component — fixed header/footer
|
|
8
|
+
* Root TUI component — box-drawn frame with fixed header/footer, scrollable viewport.
|
|
9
|
+
*
|
|
10
|
+
* ┌─────────────────────────────────────────────┐
|
|
11
|
+
* │ ASCII banner + status info │ ← FIXED header
|
|
12
|
+
* ├─────────────────────────────────────────────┤
|
|
13
|
+
* │ scrollable output │ ← VIEWPORT
|
|
14
|
+
* ├─────────────────────────────────────────────┤
|
|
15
|
+
* │ ◈ arc402 > _ │ ← FIXED footer
|
|
16
|
+
* └─────────────────────────────────────────────┘
|
|
9
17
|
*/
|
|
10
18
|
export declare function App({ version, network, wallet, balance }: AppProps): import("react/jsx-runtime").JSX.Element;
|
|
11
19
|
export {};
|
package/dist/tui/App.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"App.d.ts","sourceRoot":"","sources":["../../src/tui/App.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"App.d.ts","sourceRoot":"","sources":["../../src/tui/App.tsx"],"names":[],"mappings":"AAaA,UAAU,QAAQ;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,GAAG,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,QAAQ,2CAgNlE"}
|
package/dist/tui/App.js
CHANGED
|
@@ -9,21 +9,30 @@ const react_1 = require("react");
|
|
|
9
9
|
const ink_1 = require("ink");
|
|
10
10
|
const Header_1 = require("./Header");
|
|
11
11
|
const Viewport_1 = require("./Viewport");
|
|
12
|
-
const Footer_1 = require("./Footer");
|
|
13
12
|
const InputLine_1 = require("./InputLine");
|
|
14
13
|
const useCommand_1 = require("./useCommand");
|
|
15
14
|
const useChat_1 = require("./useChat");
|
|
16
15
|
const useScroll_1 = require("./useScroll");
|
|
17
16
|
const program_1 = require("../program");
|
|
18
17
|
const chalk_1 = __importDefault(require("chalk"));
|
|
19
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
20
|
-
const pkg = require("../../package.json");
|
|
21
18
|
const BUILTIN_CMDS = ["help", "exit", "quit", "clear", "status"];
|
|
22
19
|
/**
|
|
23
|
-
* Root TUI component — fixed header/footer
|
|
20
|
+
* Root TUI component — box-drawn frame with fixed header/footer, scrollable viewport.
|
|
21
|
+
*
|
|
22
|
+
* ┌─────────────────────────────────────────────┐
|
|
23
|
+
* │ ASCII banner + status info │ ← FIXED header
|
|
24
|
+
* ├─────────────────────────────────────────────┤
|
|
25
|
+
* │ scrollable output │ ← VIEWPORT
|
|
26
|
+
* ├─────────────────────────────────────────────┤
|
|
27
|
+
* │ ◈ arc402 > _ │ ← FIXED footer
|
|
28
|
+
* └─────────────────────────────────────────────┘
|
|
24
29
|
*/
|
|
25
30
|
function App({ version, network, wallet, balance }) {
|
|
26
31
|
const { exit } = (0, ink_1.useApp)();
|
|
32
|
+
const { stdout } = (0, ink_1.useStdout)();
|
|
33
|
+
const cols = stdout?.columns ?? 60;
|
|
34
|
+
const W = Math.min(cols, 80); // inner width between │ chars
|
|
35
|
+
const inner = W - 2; // space between the two │ border chars
|
|
27
36
|
const [outputBuffer, setOutputBuffer] = (0, react_1.useState)([
|
|
28
37
|
chalk_1.default.dim(" Type 'help' to see available commands"),
|
|
29
38
|
"",
|
|
@@ -32,8 +41,8 @@ function App({ version, network, wallet, balance }) {
|
|
|
32
41
|
const { execute, isRunning } = (0, useCommand_1.useCommand)();
|
|
33
42
|
const { send, isSending } = (0, useChat_1.useChat)();
|
|
34
43
|
// Approximate viewport height for scroll management
|
|
35
|
-
const HEADER_ROWS =
|
|
36
|
-
const FOOTER_ROWS =
|
|
44
|
+
const HEADER_ROWS = 17;
|
|
45
|
+
const FOOTER_ROWS = 3;
|
|
37
46
|
const rows = process.stdout.rows ?? 24;
|
|
38
47
|
const viewportHeight = Math.max(1, rows - HEADER_ROWS - FOOTER_ROWS);
|
|
39
48
|
const { scrollOffset, isAutoScroll, scrollUp, scrollDown, snapToBottom } = (0, useScroll_1.useScroll)(viewportHeight);
|
|
@@ -149,6 +158,9 @@ function App({ version, network, wallet, balance }) {
|
|
|
149
158
|
setIsProcessing(false);
|
|
150
159
|
}, [appendLine, execute, send, snapToBottom, topCmds, network, wallet, balance, exit]);
|
|
151
160
|
const isDisabled = isProcessing || isRunning || isSending;
|
|
152
|
-
|
|
161
|
+
const topBorder = "┌" + "─".repeat(inner) + "┐";
|
|
162
|
+
const midBorder = "├" + "─".repeat(inner) + "┤";
|
|
163
|
+
const botBorder = "└" + "─".repeat(inner) + "┘";
|
|
164
|
+
return ((0, jsx_runtime_1.jsxs)(ink_1.Box, { flexDirection: "column", height: "100%", children: [(0, jsx_runtime_1.jsx)(ink_1.Text, { dimColor: true, children: topBorder }), (0, jsx_runtime_1.jsx)(Header_1.Header, { version: version, network: network, wallet: wallet, balance: balance, innerWidth: inner }), (0, jsx_runtime_1.jsx)(ink_1.Text, { dimColor: true, children: midBorder }), (0, jsx_runtime_1.jsx)(Viewport_1.Viewport, { lines: outputBuffer, scrollOffset: scrollOffset, isAutoScroll: isAutoScroll, innerWidth: inner }), (0, jsx_runtime_1.jsx)(ink_1.Text, { dimColor: true, children: midBorder }), (0, jsx_runtime_1.jsxs)(ink_1.Box, { children: [(0, jsx_runtime_1.jsx)(ink_1.Text, { dimColor: true, children: "\u2502" }), (0, jsx_runtime_1.jsx)(ink_1.Box, { flexGrow: 1, children: (0, jsx_runtime_1.jsx)(InputLine_1.InputLine, { onSubmit: handleCommand, isDisabled: isDisabled }) }), (0, jsx_runtime_1.jsx)(ink_1.Text, { dimColor: true, children: "\u2502" })] }), (0, jsx_runtime_1.jsx)(ink_1.Text, { dimColor: true, children: botBorder })] }));
|
|
153
165
|
}
|
|
154
166
|
//# sourceMappingURL=App.js.map
|
package/dist/tui/App.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"App.js","sourceRoot":"","sources":["../../src/tui/App.tsx"],"names":[],"mapp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,IAAC,QAAQ,kBAAE,SAAS,GAAQ,IAC7B,CACP,CAAC;AACJ,CAAC"}
|
package/dist/tui/Header.d.ts
CHANGED
|
@@ -4,10 +4,11 @@ interface HeaderProps {
|
|
|
4
4
|
network?: string;
|
|
5
5
|
wallet?: string;
|
|
6
6
|
balance?: string;
|
|
7
|
+
innerWidth?: number;
|
|
7
8
|
}
|
|
8
9
|
/**
|
|
9
10
|
* Fixed header showing the ASCII art banner + status info.
|
|
10
|
-
*
|
|
11
|
+
* Each line is framed with │ … │ box-drawing borders.
|
|
11
12
|
*/
|
|
12
13
|
export declare const Header: React.NamedExoticComponent<HeaderProps>;
|
|
13
14
|
export {};
|
package/dist/tui/Header.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Header.d.ts","sourceRoot":"","sources":["../../src/tui/Header.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,UAAU,WAAW;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"Header.d.ts","sourceRoot":"","sources":["../../src/tui/Header.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,UAAU,WAAW;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;GAGG;AACH,eAAO,MAAM,MAAM,yCAoBjB,CAAC"}
|
package/dist/tui/Header.js
CHANGED
|
@@ -10,10 +10,10 @@ const ink_1 = require("ink");
|
|
|
10
10
|
const banner_1 = require("../ui/banner");
|
|
11
11
|
/**
|
|
12
12
|
* Fixed header showing the ASCII art banner + status info.
|
|
13
|
-
*
|
|
13
|
+
* Each line is framed with │ … │ box-drawing borders.
|
|
14
14
|
*/
|
|
15
|
-
exports.Header = react_1.default.memo(function Header({ network, wallet, balance, }) {
|
|
15
|
+
exports.Header = react_1.default.memo(function Header({ network, wallet, balance, innerWidth = 58, }) {
|
|
16
16
|
const bannerLines = (0, banner_1.getBannerLines)({ network, wallet, balance });
|
|
17
|
-
return ((0, jsx_runtime_1.jsx)(ink_1.Box, { flexDirection: "column", children: bannerLines.map((line, i) => ((0, jsx_runtime_1.jsx)(ink_1.Text, { children: line }, i))) }));
|
|
17
|
+
return ((0, jsx_runtime_1.jsx)(ink_1.Box, { flexDirection: "column", children: bannerLines.map((line, i) => ((0, jsx_runtime_1.jsxs)(ink_1.Box, { children: [(0, jsx_runtime_1.jsx)(ink_1.Text, { dimColor: true, children: "\u2502" }), (0, jsx_runtime_1.jsx)(ink_1.Text, { children: " " + line }), (0, jsx_runtime_1.jsx)(ink_1.Box, { flexGrow: 1 }), (0, jsx_runtime_1.jsx)(ink_1.Text, { dimColor: true, children: "\u2502" })] }, i))) }));
|
|
18
18
|
});
|
|
19
19
|
//# sourceMappingURL=Header.js.map
|
package/dist/tui/Header.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Header.js","sourceRoot":"","sources":["../../src/tui/Header.tsx"],"names":[],"mappings":";;;;;;;AAAA,kDAA0B;AAC1B,6BAAgC;AAChC,yCAA8C;
|
|
1
|
+
{"version":3,"file":"Header.js","sourceRoot":"","sources":["../../src/tui/Header.tsx"],"names":[],"mappings":";;;;;;;AAAA,kDAA0B;AAC1B,6BAAgC;AAChC,yCAA8C;AAU9C;;;GAGG;AACU,QAAA,MAAM,GAAG,eAAK,CAAC,IAAI,CAAC,SAAS,MAAM,CAAC,EAC/C,OAAO,EACP,MAAM,EACN,OAAO,EACP,UAAU,GAAG,EAAE,GACH;IACZ,MAAM,WAAW,GAAG,IAAA,uBAAc,EAAC,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;IAEjE,OAAO,CACL,uBAAC,SAAG,IAAC,aAAa,EAAC,QAAQ,YACxB,WAAW,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,CAC5B,wBAAC,SAAG,eACF,uBAAC,UAAI,IAAC,QAAQ,6BAAS,EACvB,uBAAC,UAAI,cAAE,GAAG,GAAG,IAAI,GAAQ,EACzB,uBAAC,SAAG,IAAC,QAAQ,EAAE,CAAC,GAAI,EACpB,uBAAC,UAAI,IAAC,QAAQ,6BAAS,KAJf,CAAC,CAKL,CACP,CAAC,GACE,CACP,CAAC;AACJ,CAAC,CAAC,CAAC"}
|
package/dist/tui/Viewport.d.ts
CHANGED
|
@@ -2,13 +2,12 @@ interface ViewportProps {
|
|
|
2
2
|
lines: string[];
|
|
3
3
|
scrollOffset: number;
|
|
4
4
|
isAutoScroll: boolean;
|
|
5
|
+
innerWidth?: number;
|
|
5
6
|
}
|
|
6
7
|
/**
|
|
7
|
-
* Scrollable output area
|
|
8
|
-
*
|
|
9
|
-
* scrollOffset=0 means pinned to bottom (auto-scroll).
|
|
10
|
-
* Positive scrollOffset means scrolled up by that many lines.
|
|
8
|
+
* Scrollable output area framed with │ … │ box-drawing borders.
|
|
9
|
+
* Fills remaining terminal space between header and footer separators.
|
|
11
10
|
*/
|
|
12
|
-
export declare function Viewport({ lines, scrollOffset, isAutoScroll }: ViewportProps): import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export declare function Viewport({ lines, scrollOffset, isAutoScroll, innerWidth }: ViewportProps): import("react/jsx-runtime").JSX.Element;
|
|
13
12
|
export {};
|
|
14
13
|
//# sourceMappingURL=Viewport.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Viewport.d.ts","sourceRoot":"","sources":["../../src/tui/Viewport.tsx"],"names":[],"mappings":"AAGA,UAAU,aAAa;IACrB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"Viewport.d.ts","sourceRoot":"","sources":["../../src/tui/Viewport.tsx"],"names":[],"mappings":"AAGA,UAAU,aAAa;IACrB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,OAAO,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,UAAe,EAAE,EAAE,aAAa,2CAmD7F"}
|
package/dist/tui/Viewport.js
CHANGED
|
@@ -4,34 +4,24 @@ exports.Viewport = Viewport;
|
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
const ink_1 = require("ink");
|
|
6
6
|
/**
|
|
7
|
-
* Scrollable output area
|
|
8
|
-
*
|
|
9
|
-
* scrollOffset=0 means pinned to bottom (auto-scroll).
|
|
10
|
-
* Positive scrollOffset means scrolled up by that many lines.
|
|
7
|
+
* Scrollable output area framed with │ … │ box-drawing borders.
|
|
8
|
+
* Fills remaining terminal space between header and footer separators.
|
|
11
9
|
*/
|
|
12
|
-
function Viewport({ lines, scrollOffset, isAutoScroll }) {
|
|
10
|
+
function Viewport({ lines, scrollOffset, isAutoScroll, innerWidth = 58 }) {
|
|
13
11
|
const { stdout } = (0, ink_1.useStdout)();
|
|
14
12
|
const termRows = stdout?.rows ?? 24;
|
|
15
|
-
//
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
// We'll use a reasonable estimate here; the parent App can pass exact height
|
|
19
|
-
const HEADER_ROWS = 15; // approximate
|
|
20
|
-
const FOOTER_ROWS = 1;
|
|
21
|
-
const viewportHeight = Math.max(1, termRows - HEADER_ROWS - FOOTER_ROWS);
|
|
13
|
+
// Header (~14 rows) + top/mid/mid/bot borders (4) + footer input (1) = ~19 fixed rows
|
|
14
|
+
const FIXED_ROWS = 19;
|
|
15
|
+
const viewportHeight = Math.max(1, termRows - FIXED_ROWS);
|
|
22
16
|
// Compute the window slice
|
|
23
|
-
// scrollOffset=0 → show last viewportHeight lines
|
|
24
|
-
// scrollOffset=N → show lines ending viewportHeight+N from end
|
|
25
17
|
const totalLines = lines.length;
|
|
26
18
|
let endIdx;
|
|
27
19
|
let startIdx;
|
|
28
20
|
if (scrollOffset === 0) {
|
|
29
|
-
// Auto-scroll: pinned to bottom
|
|
30
21
|
endIdx = totalLines;
|
|
31
22
|
startIdx = Math.max(0, endIdx - viewportHeight);
|
|
32
23
|
}
|
|
33
24
|
else {
|
|
34
|
-
// Scrolled up: scrollOffset lines from bottom
|
|
35
25
|
endIdx = Math.max(0, totalLines - scrollOffset);
|
|
36
26
|
startIdx = Math.max(0, endIdx - viewportHeight);
|
|
37
27
|
}
|
|
@@ -43,6 +33,6 @@ function Viewport({ lines, scrollOffset, isAutoScroll }) {
|
|
|
43
33
|
...visibleLines,
|
|
44
34
|
];
|
|
45
35
|
const canScrollDown = scrollOffset > 0;
|
|
46
|
-
return ((0, jsx_runtime_1.jsxs)(ink_1.Box, { flexDirection: "column", flexGrow: 1, children: [(0, jsx_runtime_1.
|
|
36
|
+
return ((0, jsx_runtime_1.jsxs)(ink_1.Box, { flexDirection: "column", flexGrow: 1, children: [paddedLines.map((line, i) => ((0, jsx_runtime_1.jsxs)(ink_1.Box, { children: [(0, jsx_runtime_1.jsx)(ink_1.Text, { dimColor: true, children: "\u2502" }), (0, jsx_runtime_1.jsx)(ink_1.Text, { children: " " + line }), (0, jsx_runtime_1.jsx)(ink_1.Box, { flexGrow: 1 }), (0, jsx_runtime_1.jsx)(ink_1.Text, { dimColor: true, children: "\u2502" })] }, i))), canScrollDown && !isAutoScroll && ((0, jsx_runtime_1.jsxs)(ink_1.Box, { justifyContent: "flex-end", children: [(0, jsx_runtime_1.jsx)(ink_1.Text, { dimColor: true, children: "\u2502 \u2193 more" }), (0, jsx_runtime_1.jsx)(ink_1.Box, { flexGrow: 1 }), (0, jsx_runtime_1.jsx)(ink_1.Text, { dimColor: true, children: "\u2502" })] }))] }));
|
|
47
37
|
}
|
|
48
38
|
//# sourceMappingURL=Viewport.js.map
|
package/dist/tui/Viewport.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Viewport.js","sourceRoot":"","sources":["../../src/tui/Viewport.tsx"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"Viewport.js","sourceRoot":"","sources":["../../src/tui/Viewport.tsx"],"names":[],"mappings":";;AAcA,4BAmDC;;AAhED,6BAA2C;AAS3C;;;GAGG;AACH,SAAgB,QAAQ,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,UAAU,GAAG,EAAE,EAAiB;IAC5F,MAAM,EAAE,MAAM,EAAE,GAAG,IAAA,eAAS,GAAE,CAAC;IAC/B,MAAM,QAAQ,GAAG,MAAM,EAAE,IAAI,IAAI,EAAE,CAAC;IAEpC,sFAAsF;IACtF,MAAM,UAAU,GAAG,EAAE,CAAC;IACtB,MAAM,cAAc,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,GAAG,UAAU,CAAC,CAAC;IAE1D,2BAA2B;IAC3B,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM,CAAC;IAChC,IAAI,MAAc,CAAC;IACnB,IAAI,QAAgB,CAAC;IAErB,IAAI,YAAY,KAAK,CAAC,EAAE,CAAC;QACvB,MAAM,GAAG,UAAU,CAAC;QACpB,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,GAAG,cAAc,CAAC,CAAC;IAClD,CAAC;SAAM,CAAC;QACN,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,UAAU,GAAG,YAAY,CAAC,CAAC;QAChD,QAAQ,GAAG,IAAI,CAAC,GAAG,CA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+
*
|
|
8
|
+
* NON-INTERACTIVE commands: captures stdout/stderr by monkey-patching
|
|
9
|
+
* process.stdout.write and routes output to the viewport.
|
|
10
|
+
*
|
|
11
|
+
* INTERACTIVE commands (WalletConnect, prompts): spawns a child process
|
|
12
|
+
* running `arc402 <command>` with inherited stdin so that QR codes render
|
|
13
|
+
* and prompts accept input. Output is captured line-by-line into the viewport.
|
|
9
14
|
*/
|
|
10
15
|
export declare function useCommand(): UseCommandResult;
|
|
11
16
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCommand.d.ts","sourceRoot":"","sources":["../../src/tui/useCommand.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useCommand.d.ts","sourceRoot":"","sources":["../../src/tui/useCommand.ts"],"names":[],"mappings":"AAyCA,UAAU,gBAAgB;IACxB,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1E,SAAS,EAAE,OAAO,CAAC;CACpB;AAED;;;;;;;;;GASG;AACH,wBAAgB,UAAU,IAAI,gBAAgB,CAmB7C"}
|
package/dist/tui/useCommand.js
CHANGED
|
@@ -6,91 +6,173 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.useCommand = useCommand;
|
|
7
7
|
const react_1 = require("react");
|
|
8
8
|
const program_1 = require("../program");
|
|
9
|
+
const child_process_1 = require("child_process");
|
|
9
10
|
const chalk_1 = __importDefault(require("chalk"));
|
|
10
11
|
const colors_1 = require("../ui/colors");
|
|
12
|
+
/**
|
|
13
|
+
* Commands that use interactive prompts or WalletConnect QR flows.
|
|
14
|
+
* These MUST run in a child process so they can own stdin/stdout directly,
|
|
15
|
+
* because Ink holds stdin in raw mode for its own input handling.
|
|
16
|
+
*/
|
|
17
|
+
const INTERACTIVE_COMMANDS = new Set([
|
|
18
|
+
"wallet deploy",
|
|
19
|
+
"wallet set-guardian",
|
|
20
|
+
"wallet unfreeze",
|
|
21
|
+
"wallet authorize-machine-key",
|
|
22
|
+
"wallet revoke-machine-key",
|
|
23
|
+
"wallet set-passkey",
|
|
24
|
+
"wallet set-interceptor",
|
|
25
|
+
"wallet set-velocity-limit",
|
|
26
|
+
"wallet upgrade-registry",
|
|
27
|
+
"wallet execute-registry-upgrade",
|
|
28
|
+
"wallet cancel-registry-upgrade",
|
|
29
|
+
"wallet register-policy",
|
|
30
|
+
"wallet whitelist-contract",
|
|
31
|
+
"wallet governance setup",
|
|
32
|
+
"wallet policy set-limit",
|
|
33
|
+
"wallet policy set-daily-limit",
|
|
34
|
+
"wallet policy set",
|
|
35
|
+
"wallet import",
|
|
36
|
+
"config init",
|
|
37
|
+
]);
|
|
38
|
+
function isInteractiveCommand(input) {
|
|
39
|
+
const normalized = input.trim();
|
|
40
|
+
for (const cmd of INTERACTIVE_COMMANDS) {
|
|
41
|
+
if (normalized === cmd || normalized.startsWith(cmd + " "))
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
11
46
|
/**
|
|
12
47
|
* Dispatches parsed commands to the commander program.
|
|
13
|
-
*
|
|
14
|
-
*
|
|
48
|
+
*
|
|
49
|
+
* NON-INTERACTIVE commands: captures stdout/stderr by monkey-patching
|
|
50
|
+
* process.stdout.write and routes output to the viewport.
|
|
51
|
+
*
|
|
52
|
+
* INTERACTIVE commands (WalletConnect, prompts): spawns a child process
|
|
53
|
+
* running `arc402 <command>` with inherited stdin so that QR codes render
|
|
54
|
+
* and prompts accept input. Output is captured line-by-line into the viewport.
|
|
15
55
|
*/
|
|
16
56
|
function useCommand() {
|
|
17
57
|
const [isRunning, setIsRunning] = (0, react_1.useState)(false);
|
|
18
58
|
const execute = (0, react_1.useCallback)(async (input, onLine) => {
|
|
19
59
|
setIsRunning(true);
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const originalStderrWrite = process.stderr.write.bind(process.stderr);
|
|
23
|
-
let captureBuffer = "";
|
|
24
|
-
const flushBuffer = () => {
|
|
25
|
-
if (!captureBuffer)
|
|
26
|
-
return;
|
|
27
|
-
const lines = captureBuffer.split("\n");
|
|
28
|
-
captureBuffer = lines.pop() ?? "";
|
|
29
|
-
for (const line of lines) {
|
|
30
|
-
onLine(line);
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
const capturedWrite = (chunk, encodingOrCb, cb) => {
|
|
34
|
-
const str = typeof chunk === "string"
|
|
35
|
-
? chunk
|
|
36
|
-
: Buffer.from(chunk).toString("utf8");
|
|
37
|
-
captureBuffer += str;
|
|
38
|
-
flushBuffer();
|
|
39
|
-
// call callback if provided
|
|
40
|
-
const callback = typeof encodingOrCb === "function" ? encodingOrCb : cb;
|
|
41
|
-
if (callback)
|
|
42
|
-
callback();
|
|
43
|
-
return true;
|
|
44
|
-
};
|
|
45
|
-
// Monkey-patch (cast through unknown to bypass strict overload checking)
|
|
46
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
47
|
-
process.stdout.write = capturedWrite;
|
|
48
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
49
|
-
process.stderr.write = capturedWrite;
|
|
50
|
-
try {
|
|
51
|
-
const tokens = parseTokens(input);
|
|
52
|
-
const prog = (0, program_1.createProgram)();
|
|
53
|
-
prog.exitOverride();
|
|
54
|
-
prog.configureOutput({
|
|
55
|
-
writeOut: (str) => process.stdout.write(str),
|
|
56
|
-
writeErr: (str) => process.stderr.write(str),
|
|
57
|
-
});
|
|
58
|
-
await prog.parseAsync(["node", "arc402", ...tokens]);
|
|
60
|
+
if (isInteractiveCommand(input)) {
|
|
61
|
+
await executeInteractive(input, onLine);
|
|
59
62
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
63
|
+
else {
|
|
64
|
+
await executeInProcess(input, onLine);
|
|
65
|
+
}
|
|
66
|
+
setIsRunning(false);
|
|
67
|
+
}, []);
|
|
68
|
+
return { execute, isRunning };
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Run an interactive command as a child process with inherited stdin.
|
|
72
|
+
* Ink is temporarily suspended so the child can own the terminal.
|
|
73
|
+
*/
|
|
74
|
+
async function executeInteractive(input, onLine) {
|
|
75
|
+
const tokens = parseTokens(input);
|
|
76
|
+
onLine(chalk_1.default.dim(" ◈ Launching interactive session..."));
|
|
77
|
+
onLine("");
|
|
78
|
+
return new Promise((resolve) => {
|
|
79
|
+
// Spawn arc402 as a child process with full terminal access.
|
|
80
|
+
// Use stdio: 'inherit' so the child owns stdin/stdout/stderr directly.
|
|
81
|
+
// This means its output goes straight to the terminal (not captured in viewport)
|
|
82
|
+
// but that's correct — the child needs raw terminal access for QR codes, prompts, etc.
|
|
83
|
+
const child = (0, child_process_1.spawn)(process.execPath, [process.argv[1], ...tokens], {
|
|
84
|
+
stdio: "inherit",
|
|
85
|
+
env: { ...process.env, ARC402_NO_TUI: "1" }, // prevent child from launching its own TUI
|
|
86
|
+
cwd: process.cwd(),
|
|
87
|
+
});
|
|
88
|
+
child.on("close", (code) => {
|
|
89
|
+
onLine("");
|
|
90
|
+
if (code === 0) {
|
|
91
|
+
onLine(` ${colors_1.c.success} ${chalk_1.default.dim("Command completed")}`);
|
|
74
92
|
}
|
|
75
93
|
else {
|
|
76
|
-
onLine(` ${colors_1.c.failure} ${chalk_1.default.red(
|
|
94
|
+
onLine(` ${colors_1.c.failure} ${chalk_1.default.red(`Command exited with code ${code}`)}`);
|
|
77
95
|
}
|
|
96
|
+
resolve();
|
|
97
|
+
});
|
|
98
|
+
child.on("error", (err) => {
|
|
99
|
+
onLine(` ${colors_1.c.failure} ${chalk_1.default.red(`Failed to spawn: ${err.message}`)}`);
|
|
100
|
+
resolve();
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Run a non-interactive command in-process with captured output.
|
|
106
|
+
*/
|
|
107
|
+
async function executeInProcess(input, onLine) {
|
|
108
|
+
// Capture stdout/stderr
|
|
109
|
+
const originalStdoutWrite = process.stdout.write.bind(process.stdout);
|
|
110
|
+
const originalStderrWrite = process.stderr.write.bind(process.stderr);
|
|
111
|
+
let captureBuffer = "";
|
|
112
|
+
const flushBuffer = () => {
|
|
113
|
+
if (!captureBuffer)
|
|
114
|
+
return;
|
|
115
|
+
const lines = captureBuffer.split("\n");
|
|
116
|
+
captureBuffer = lines.pop() ?? "";
|
|
117
|
+
for (const line of lines) {
|
|
118
|
+
onLine(line);
|
|
78
119
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
120
|
+
};
|
|
121
|
+
const capturedWrite = (chunk, encodingOrCb, cb) => {
|
|
122
|
+
const str = typeof chunk === "string"
|
|
123
|
+
? chunk
|
|
124
|
+
: Buffer.from(chunk).toString("utf8");
|
|
125
|
+
captureBuffer += str;
|
|
126
|
+
flushBuffer();
|
|
127
|
+
const callback = typeof encodingOrCb === "function" ? encodingOrCb : cb;
|
|
128
|
+
if (callback)
|
|
129
|
+
callback();
|
|
130
|
+
return true;
|
|
131
|
+
};
|
|
132
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
133
|
+
process.stdout.write = capturedWrite;
|
|
134
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
135
|
+
process.stderr.write = capturedWrite;
|
|
136
|
+
try {
|
|
137
|
+
const tokens = parseTokens(input);
|
|
138
|
+
const prog = (0, program_1.createProgram)();
|
|
139
|
+
prog.exitOverride();
|
|
140
|
+
prog.configureOutput({
|
|
141
|
+
writeOut: (str) => process.stdout.write(str),
|
|
142
|
+
writeErr: (str) => process.stderr.write(str),
|
|
143
|
+
});
|
|
144
|
+
await prog.parseAsync(["node", "arc402", ...tokens]);
|
|
145
|
+
}
|
|
146
|
+
catch (err) {
|
|
147
|
+
const e = err;
|
|
148
|
+
if (e.code === "commander.helpDisplayed" ||
|
|
149
|
+
e.code === "commander.version" ||
|
|
150
|
+
e.code === "commander.executeSubCommandAsync") {
|
|
151
|
+
// already written or normal exit — no-op
|
|
91
152
|
}
|
|
92
|
-
|
|
93
|
-
|
|
153
|
+
else if (e.code === "commander.unknownCommand") {
|
|
154
|
+
const tokens = parseTokens(input);
|
|
155
|
+
onLine(` ${colors_1.c.failure} ${chalk_1.default.red(`Unknown command: ${chalk_1.default.white(tokens[0])}`)} `);
|
|
156
|
+
onLine(chalk_1.default.dim(" Type 'help' for available commands"));
|
|
157
|
+
}
|
|
158
|
+
else if (e.code?.startsWith("commander.")) {
|
|
159
|
+
onLine(` ${colors_1.c.failure} ${chalk_1.default.red(e.message ?? String(err))}`);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
onLine(` ${colors_1.c.failure} ${chalk_1.default.red(e.message ?? String(err))}`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
finally {
|
|
166
|
+
// Flush remaining buffer
|
|
167
|
+
if (captureBuffer.trim()) {
|
|
168
|
+
onLine(captureBuffer);
|
|
169
|
+
captureBuffer = "";
|
|
170
|
+
}
|
|
171
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
172
|
+
process.stdout.write = originalStdoutWrite;
|
|
173
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
174
|
+
process.stderr.write = originalStderrWrite;
|
|
175
|
+
}
|
|
94
176
|
}
|
|
95
177
|
// Shell-style tokenizer
|
|
96
178
|
function parseTokens(input) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCommand.js","sourceRoot":"","sources":["../../src/tui/useCommand.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"useCommand.js","sourceRoot":"","sources":["../../src/tui/useCommand.ts"],"names":[],"mappings":";;;;;AAwDA,gCAmBC;AA3ED,iCAA8C;AAC9C,wCAA2C;AAC3C,iDAAsC;AACtC,kDAA0B;AAC1B,yCAAiC;AAEjC;;;;GAIG;AACH,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAAC;IACnC,eAAe;IACf,qBAAqB;IACrB,iBAAiB;IACjB,8BAA8B;IAC9B,2BAA2B;IAC3B,oBAAoB;IACpB,wBAAwB;IACxB,2BAA2B;IAC3B,yBAAyB;IACzB,iCAAiC;IACjC,gCAAgC;IAChC,wBAAwB;IACxB,2BAA2B;IAC3B,yBAAyB;IACzB,yBAAyB;IACzB,+BAA+B;IAC/B,mBAAmB;IACnB,eAAe;IACf,aAAa;CACd,CAAC,CAAC;AAEH,SAAS,oBAAoB,CAAC,KAAa;IACzC,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAChC,KAAK,MAAM,GAAG,IAAI,oBAAoB,EAAE,CAAC;QACvC,IAAI,UAAU,KAAK,GAAG,IAAI,UAAU,CAAC,UAAU,CAAC,GAAG,GAAG,GAAG,CAAC;YAAE,OAAO,IAAI,CAAC;IAC1E,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAOD;;;;;;;;;GASG;AACH,SAAgB,UAAU;IACxB,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,IAAA,gBAAQ,EAAC,KAAK,CAAC,CAAC;IAElD,MAAM,OAAO,GAAG,IAAA,mBAAW,EACzB,KAAK,EAAE,KAAa,EAAE,MAA8B,EAAiB,EAAE;QACrE,YAAY,CAAC,IAAI,CAAC,CAAC;QAEnB,IAAI,oBAAoB,CAAC,KAAK,CAAC,EAAE,CAAC;YAChC,MAAM,kBAAkB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAC1C,CAAC;aAAM,CAAC;YACN,MAAM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QACvB,IAAI,MAAM,EAAE,CAAC;YACX,OAAO,IAAI,EAAE,CAAC;YACd,MAAM,GAAG,KAAK,CAAC;YACf,SAAS;QACX,CAAC;QACD,IAAI,OAAO,EAAE,CAAC;YACZ,IAAI,SAAS,KAAK,GAAG,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC;gBACrC,MAAM,GAAG,IAAI,CAAC;YAChB,CAAC;iBAAM,IAAI,EAAE,KAAK,SAAS,EAAE,CAAC;gBAC5B,OAAO,GAAG,KAAK,CAAC;YAClB,CAAC;iBAAM,CAAC;gBACN,OAAO,IAAI,EAAE,CAAC;YAChB,CAAC;QACH,CAAC;aAAM,IAAI,EAAE,KAAK,GAAG,IAAI,EAAE,KAAK,GAAG,EAAE,CAAC;YACpC,OAAO,GAAG,IAAI,CAAC;YACf,SAAS,GAAG,EAAE,CAAC;QACjB,CAAC;aAAM,IAAI,EAAE,KAAK,GAAG,EAAE,CAAC;YACtB,IAAI,OAAO,EAAE,CAAC;gBACZ,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;gBACrB,OAAO,GAAG,EAAE,CAAC;YACf,CAAC;QACH,CAAC;aAAM,CAAC;YACN,OAAO,IAAI,EAAE,CAAC;QAChB,CAAC;IACH,CAAC;IACD,IAAI,OAAO;QAAE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAClC,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -52,8 +52,8 @@ if (printMode) {
|
|
|
52
52
|
console.error(e instanceof Error ? e.message : String(e));
|
|
53
53
|
process.exit(1);
|
|
54
54
|
});
|
|
55
|
-
} else if (process.stdout.isTTY && !hasSubcommand && process.argv.length <= 2) {
|
|
56
|
-
// TTY with no subcommand — launch Ink TUI
|
|
55
|
+
} else if (process.stdout.isTTY && !hasSubcommand && process.argv.length <= 2 && !process.env.ARC402_NO_TUI) {
|
|
56
|
+
// TTY with no subcommand — launch Ink TUI (unless spawned by TUI as a child process)
|
|
57
57
|
checkUpgrade();
|
|
58
58
|
void import("./tui/index").then(({ launchTUI }) => launchTUI()).catch((e: unknown) => {
|
|
59
59
|
console.error("TUI failed to start:", e instanceof Error ? e.message : String(e));
|
package/src/tui/App.tsx
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import React, { useState, useCallback
|
|
2
|
-
import { Box, Text, useApp } from "ink";
|
|
1
|
+
import React, { useState, useCallback } from "react";
|
|
2
|
+
import { Box, Text, useApp, useStdout } from "ink";
|
|
3
3
|
import { Header } from "./Header";
|
|
4
4
|
import { Viewport } from "./Viewport";
|
|
5
|
-
import { Footer } from "./Footer";
|
|
6
5
|
import { InputLine } from "./InputLine";
|
|
7
6
|
import { useCommand } from "./useCommand";
|
|
8
7
|
import { useChat } from "./useChat";
|
|
@@ -10,9 +9,6 @@ import { useScroll } from "./useScroll";
|
|
|
10
9
|
import { createProgram } from "../program";
|
|
11
10
|
import chalk from "chalk";
|
|
12
11
|
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
14
|
-
const pkg = require("../../package.json") as { version: string };
|
|
15
|
-
|
|
16
12
|
const BUILTIN_CMDS = ["help", "exit", "quit", "clear", "status"];
|
|
17
13
|
|
|
18
14
|
interface AppProps {
|
|
@@ -23,10 +19,23 @@ interface AppProps {
|
|
|
23
19
|
}
|
|
24
20
|
|
|
25
21
|
/**
|
|
26
|
-
* Root TUI component — fixed header/footer
|
|
22
|
+
* Root TUI component — box-drawn frame with fixed header/footer, scrollable viewport.
|
|
23
|
+
*
|
|
24
|
+
* ┌─────────────────────────────────────────────┐
|
|
25
|
+
* │ ASCII banner + status info │ ← FIXED header
|
|
26
|
+
* ├─────────────────────────────────────────────┤
|
|
27
|
+
* │ scrollable output │ ← VIEWPORT
|
|
28
|
+
* ├─────────────────────────────────────────────┤
|
|
29
|
+
* │ ◈ arc402 > _ │ ← FIXED footer
|
|
30
|
+
* └─────────────────────────────────────────────┘
|
|
27
31
|
*/
|
|
28
32
|
export function App({ version, network, wallet, balance }: AppProps) {
|
|
29
33
|
const { exit } = useApp();
|
|
34
|
+
const { stdout } = useStdout();
|
|
35
|
+
const cols = stdout?.columns ?? 60;
|
|
36
|
+
const W = Math.min(cols, 80); // inner width between │ chars
|
|
37
|
+
const inner = W - 2; // space between the two │ border chars
|
|
38
|
+
|
|
30
39
|
const [outputBuffer, setOutputBuffer] = useState<string[]>([
|
|
31
40
|
chalk.dim(" Type 'help' to see available commands"),
|
|
32
41
|
"",
|
|
@@ -37,8 +46,8 @@ export function App({ version, network, wallet, balance }: AppProps) {
|
|
|
37
46
|
const { send, isSending } = useChat();
|
|
38
47
|
|
|
39
48
|
// Approximate viewport height for scroll management
|
|
40
|
-
const HEADER_ROWS =
|
|
41
|
-
const FOOTER_ROWS =
|
|
49
|
+
const HEADER_ROWS = 17;
|
|
50
|
+
const FOOTER_ROWS = 3;
|
|
42
51
|
const rows = process.stdout.rows ?? 24;
|
|
43
52
|
const viewportHeight = Math.max(1, rows - HEADER_ROWS - FOOTER_ROWS);
|
|
44
53
|
|
|
@@ -183,32 +192,49 @@ export function App({ version, network, wallet, balance }: AppProps) {
|
|
|
183
192
|
|
|
184
193
|
const isDisabled = isProcessing || isRunning || isSending;
|
|
185
194
|
|
|
195
|
+
const topBorder = "┌" + "─".repeat(inner) + "┐";
|
|
196
|
+
const midBorder = "├" + "─".repeat(inner) + "┤";
|
|
197
|
+
const botBorder = "└" + "─".repeat(inner) + "┘";
|
|
198
|
+
|
|
186
199
|
return (
|
|
187
200
|
<Box flexDirection="column" height="100%">
|
|
201
|
+
{/* Top border */}
|
|
202
|
+
<Text dimColor>{topBorder}</Text>
|
|
203
|
+
|
|
188
204
|
{/* HEADER — fixed, never scrolls */}
|
|
189
205
|
<Header
|
|
190
206
|
version={version}
|
|
191
207
|
network={network}
|
|
192
208
|
wallet={wallet}
|
|
193
209
|
balance={balance}
|
|
210
|
+
innerWidth={inner}
|
|
194
211
|
/>
|
|
195
212
|
|
|
196
|
-
{/*
|
|
197
|
-
<
|
|
198
|
-
<Text dimColor>{"─".repeat(60)}</Text>
|
|
199
|
-
</Box>
|
|
213
|
+
{/* Mid separator */}
|
|
214
|
+
<Text dimColor>{midBorder}</Text>
|
|
200
215
|
|
|
201
216
|
{/* VIEWPORT — fills remaining space */}
|
|
202
217
|
<Viewport
|
|
203
218
|
lines={outputBuffer}
|
|
204
219
|
scrollOffset={scrollOffset}
|
|
205
220
|
isAutoScroll={isAutoScroll}
|
|
221
|
+
innerWidth={inner}
|
|
206
222
|
/>
|
|
207
223
|
|
|
208
|
-
{/*
|
|
209
|
-
<
|
|
210
|
-
|
|
211
|
-
|
|
224
|
+
{/* Footer separator */}
|
|
225
|
+
<Text dimColor>{midBorder}</Text>
|
|
226
|
+
|
|
227
|
+
{/* FOOTER — input pinned */}
|
|
228
|
+
<Box>
|
|
229
|
+
<Text dimColor>│</Text>
|
|
230
|
+
<Box flexGrow={1}>
|
|
231
|
+
<InputLine onSubmit={handleCommand} isDisabled={isDisabled} />
|
|
232
|
+
</Box>
|
|
233
|
+
<Text dimColor>│</Text>
|
|
234
|
+
</Box>
|
|
235
|
+
|
|
236
|
+
{/* Bottom border */}
|
|
237
|
+
<Text dimColor>{botBorder}</Text>
|
|
212
238
|
</Box>
|
|
213
239
|
);
|
|
214
240
|
}
|
package/src/tui/Header.tsx
CHANGED
|
@@ -7,23 +7,30 @@ interface HeaderProps {
|
|
|
7
7
|
network?: string;
|
|
8
8
|
wallet?: string;
|
|
9
9
|
balance?: string;
|
|
10
|
+
innerWidth?: number;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* Fixed header showing the ASCII art banner + status info.
|
|
14
|
-
*
|
|
15
|
+
* Each line is framed with │ … │ box-drawing borders.
|
|
15
16
|
*/
|
|
16
17
|
export const Header = React.memo(function Header({
|
|
17
18
|
network,
|
|
18
19
|
wallet,
|
|
19
20
|
balance,
|
|
21
|
+
innerWidth = 58,
|
|
20
22
|
}: HeaderProps) {
|
|
21
23
|
const bannerLines = getBannerLines({ network, wallet, balance });
|
|
22
24
|
|
|
23
25
|
return (
|
|
24
26
|
<Box flexDirection="column">
|
|
25
27
|
{bannerLines.map((line, i) => (
|
|
26
|
-
<
|
|
28
|
+
<Box key={i}>
|
|
29
|
+
<Text dimColor>│</Text>
|
|
30
|
+
<Text>{" " + line}</Text>
|
|
31
|
+
<Box flexGrow={1} />
|
|
32
|
+
<Text dimColor>│</Text>
|
|
33
|
+
</Box>
|
|
27
34
|
))}
|
|
28
35
|
</Box>
|
|
29
36
|
);
|
package/src/tui/Viewport.tsx
CHANGED
|
@@ -5,39 +5,30 @@ interface ViewportProps {
|
|
|
5
5
|
lines: string[];
|
|
6
6
|
scrollOffset: number;
|
|
7
7
|
isAutoScroll: boolean;
|
|
8
|
+
innerWidth?: number;
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
|
-
* Scrollable output area
|
|
12
|
-
*
|
|
13
|
-
* scrollOffset=0 means pinned to bottom (auto-scroll).
|
|
14
|
-
* Positive scrollOffset means scrolled up by that many lines.
|
|
12
|
+
* Scrollable output area framed with │ … │ box-drawing borders.
|
|
13
|
+
* Fills remaining terminal space between header and footer separators.
|
|
15
14
|
*/
|
|
16
|
-
export function Viewport({ lines, scrollOffset, isAutoScroll }: ViewportProps) {
|
|
15
|
+
export function Viewport({ lines, scrollOffset, isAutoScroll, innerWidth = 58 }: ViewportProps) {
|
|
17
16
|
const { stdout } = useStdout();
|
|
18
17
|
const termRows = stdout?.rows ?? 24;
|
|
19
18
|
|
|
20
|
-
//
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
// We'll use a reasonable estimate here; the parent App can pass exact height
|
|
24
|
-
const HEADER_ROWS = 15; // approximate
|
|
25
|
-
const FOOTER_ROWS = 1;
|
|
26
|
-
const viewportHeight = Math.max(1, termRows - HEADER_ROWS - FOOTER_ROWS);
|
|
19
|
+
// Header (~14 rows) + top/mid/mid/bot borders (4) + footer input (1) = ~19 fixed rows
|
|
20
|
+
const FIXED_ROWS = 19;
|
|
21
|
+
const viewportHeight = Math.max(1, termRows - FIXED_ROWS);
|
|
27
22
|
|
|
28
23
|
// Compute the window slice
|
|
29
|
-
// scrollOffset=0 → show last viewportHeight lines
|
|
30
|
-
// scrollOffset=N → show lines ending viewportHeight+N from end
|
|
31
24
|
const totalLines = lines.length;
|
|
32
25
|
let endIdx: number;
|
|
33
26
|
let startIdx: number;
|
|
34
27
|
|
|
35
28
|
if (scrollOffset === 0) {
|
|
36
|
-
// Auto-scroll: pinned to bottom
|
|
37
29
|
endIdx = totalLines;
|
|
38
30
|
startIdx = Math.max(0, endIdx - viewportHeight);
|
|
39
31
|
} else {
|
|
40
|
-
// Scrolled up: scrollOffset lines from bottom
|
|
41
32
|
endIdx = Math.max(0, totalLines - scrollOffset);
|
|
42
33
|
startIdx = Math.max(0, endIdx - viewportHeight);
|
|
43
34
|
}
|
|
@@ -55,14 +46,19 @@ export function Viewport({ lines, scrollOffset, isAutoScroll }: ViewportProps) {
|
|
|
55
46
|
|
|
56
47
|
return (
|
|
57
48
|
<Box flexDirection="column" flexGrow={1}>
|
|
58
|
-
|
|
59
|
-
{
|
|
60
|
-
<Text
|
|
61
|
-
|
|
62
|
-
|
|
49
|
+
{paddedLines.map((line, i) => (
|
|
50
|
+
<Box key={i}>
|
|
51
|
+
<Text dimColor>│</Text>
|
|
52
|
+
<Text>{" " + line}</Text>
|
|
53
|
+
<Box flexGrow={1} />
|
|
54
|
+
<Text dimColor>│</Text>
|
|
55
|
+
</Box>
|
|
56
|
+
))}
|
|
63
57
|
{canScrollDown && !isAutoScroll && (
|
|
64
58
|
<Box justifyContent="flex-end">
|
|
65
|
-
<Text dimColor
|
|
59
|
+
<Text dimColor>│ ↓ more</Text>
|
|
60
|
+
<Box flexGrow={1} />
|
|
61
|
+
<Text dimColor>│</Text>
|
|
66
62
|
</Box>
|
|
67
63
|
)}
|
|
68
64
|
</Box>
|
package/src/tui/useCommand.ts
CHANGED
|
@@ -1,8 +1,44 @@
|
|
|
1
1
|
import { useState, useCallback } from "react";
|
|
2
2
|
import { createProgram } from "../program";
|
|
3
|
+
import { spawn } from "child_process";
|
|
3
4
|
import chalk from "chalk";
|
|
4
5
|
import { c } from "../ui/colors";
|
|
5
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Commands that use interactive prompts or WalletConnect QR flows.
|
|
9
|
+
* These MUST run in a child process so they can own stdin/stdout directly,
|
|
10
|
+
* because Ink holds stdin in raw mode for its own input handling.
|
|
11
|
+
*/
|
|
12
|
+
const INTERACTIVE_COMMANDS = new Set([
|
|
13
|
+
"wallet deploy",
|
|
14
|
+
"wallet set-guardian",
|
|
15
|
+
"wallet unfreeze",
|
|
16
|
+
"wallet authorize-machine-key",
|
|
17
|
+
"wallet revoke-machine-key",
|
|
18
|
+
"wallet set-passkey",
|
|
19
|
+
"wallet set-interceptor",
|
|
20
|
+
"wallet set-velocity-limit",
|
|
21
|
+
"wallet upgrade-registry",
|
|
22
|
+
"wallet execute-registry-upgrade",
|
|
23
|
+
"wallet cancel-registry-upgrade",
|
|
24
|
+
"wallet register-policy",
|
|
25
|
+
"wallet whitelist-contract",
|
|
26
|
+
"wallet governance setup",
|
|
27
|
+
"wallet policy set-limit",
|
|
28
|
+
"wallet policy set-daily-limit",
|
|
29
|
+
"wallet policy set",
|
|
30
|
+
"wallet import",
|
|
31
|
+
"config init",
|
|
32
|
+
]);
|
|
33
|
+
|
|
34
|
+
function isInteractiveCommand(input: string): boolean {
|
|
35
|
+
const normalized = input.trim();
|
|
36
|
+
for (const cmd of INTERACTIVE_COMMANDS) {
|
|
37
|
+
if (normalized === cmd || normalized.startsWith(cmd + " ")) return true;
|
|
38
|
+
}
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
|
|
6
42
|
interface UseCommandResult {
|
|
7
43
|
execute: (input: string, onLine: (line: string) => void) => Promise<void>;
|
|
8
44
|
isRunning: boolean;
|
|
@@ -10,8 +46,13 @@ interface UseCommandResult {
|
|
|
10
46
|
|
|
11
47
|
/**
|
|
12
48
|
* Dispatches parsed commands to the commander program.
|
|
13
|
-
*
|
|
14
|
-
*
|
|
49
|
+
*
|
|
50
|
+
* NON-INTERACTIVE commands: captures stdout/stderr by monkey-patching
|
|
51
|
+
* process.stdout.write and routes output to the viewport.
|
|
52
|
+
*
|
|
53
|
+
* INTERACTIVE commands (WalletConnect, prompts): spawns a child process
|
|
54
|
+
* running `arc402 <command>` with inherited stdin so that QR codes render
|
|
55
|
+
* and prompts accept input. Output is captured line-by-line into the viewport.
|
|
15
56
|
*/
|
|
16
57
|
export function useCommand(): UseCommandResult {
|
|
17
58
|
const [isRunning, setIsRunning] = useState(false);
|
|
@@ -20,89 +61,13 @@ export function useCommand(): UseCommandResult {
|
|
|
20
61
|
async (input: string, onLine: (line: string) => void): Promise<void> => {
|
|
21
62
|
setIsRunning(true);
|
|
22
63
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
let captureBuffer = "";
|
|
28
|
-
|
|
29
|
-
const flushBuffer = (): void => {
|
|
30
|
-
if (!captureBuffer) return;
|
|
31
|
-
const lines = captureBuffer.split("\n");
|
|
32
|
-
captureBuffer = lines.pop() ?? "";
|
|
33
|
-
for (const line of lines) {
|
|
34
|
-
onLine(line);
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const capturedWrite = (
|
|
39
|
-
chunk: string | Uint8Array,
|
|
40
|
-
encodingOrCb?: BufferEncoding | ((err?: Error | null) => void),
|
|
41
|
-
cb?: (err?: Error | null) => void
|
|
42
|
-
): boolean => {
|
|
43
|
-
const str =
|
|
44
|
-
typeof chunk === "string"
|
|
45
|
-
? chunk
|
|
46
|
-
: Buffer.from(chunk).toString("utf8");
|
|
47
|
-
captureBuffer += str;
|
|
48
|
-
flushBuffer();
|
|
49
|
-
// call callback if provided
|
|
50
|
-
const callback =
|
|
51
|
-
typeof encodingOrCb === "function" ? encodingOrCb : cb;
|
|
52
|
-
if (callback) callback();
|
|
53
|
-
return true;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
// Monkey-patch (cast through unknown to bypass strict overload checking)
|
|
57
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
58
|
-
(process.stdout as any).write = capturedWrite;
|
|
59
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
60
|
-
(process.stderr as any).write = capturedWrite;
|
|
61
|
-
|
|
62
|
-
try {
|
|
63
|
-
const tokens = parseTokens(input);
|
|
64
|
-
const prog = createProgram();
|
|
65
|
-
prog.exitOverride();
|
|
66
|
-
prog.configureOutput({
|
|
67
|
-
writeOut: (str) => process.stdout.write(str),
|
|
68
|
-
writeErr: (str) => process.stderr.write(str),
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
await prog.parseAsync(["node", "arc402", ...tokens]);
|
|
72
|
-
} catch (err) {
|
|
73
|
-
const e = err as { code?: string; message?: string };
|
|
74
|
-
if (
|
|
75
|
-
e.code === "commander.helpDisplayed" ||
|
|
76
|
-
e.code === "commander.version" ||
|
|
77
|
-
e.code === "commander.executeSubCommandAsync"
|
|
78
|
-
) {
|
|
79
|
-
// already written or normal exit — no-op
|
|
80
|
-
} else if (e.code === "commander.unknownCommand") {
|
|
81
|
-
const tokens = parseTokens(input);
|
|
82
|
-
onLine(
|
|
83
|
-
` ${c.failure} ${chalk.red(`Unknown command: ${chalk.white(tokens[0])}`)} `
|
|
84
|
-
);
|
|
85
|
-
onLine(chalk.dim(" Type 'help' for available commands"));
|
|
86
|
-
} else if (e.code?.startsWith("commander.")) {
|
|
87
|
-
onLine(` ${c.failure} ${chalk.red(e.message ?? String(err))}`);
|
|
88
|
-
} else {
|
|
89
|
-
onLine(` ${c.failure} ${chalk.red(e.message ?? String(err))}`);
|
|
90
|
-
}
|
|
91
|
-
} finally {
|
|
92
|
-
// Flush remaining buffer
|
|
93
|
-
if (captureBuffer.trim()) {
|
|
94
|
-
onLine(captureBuffer);
|
|
95
|
-
captureBuffer = "";
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// Restore original write functions
|
|
99
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
100
|
-
(process.stdout as any).write = originalStdoutWrite;
|
|
101
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
102
|
-
(process.stderr as any).write = originalStderrWrite;
|
|
103
|
-
|
|
104
|
-
setIsRunning(false);
|
|
64
|
+
if (isInteractiveCommand(input)) {
|
|
65
|
+
await executeInteractive(input, onLine);
|
|
66
|
+
} else {
|
|
67
|
+
await executeInProcess(input, onLine);
|
|
105
68
|
}
|
|
69
|
+
|
|
70
|
+
setIsRunning(false);
|
|
106
71
|
},
|
|
107
72
|
[]
|
|
108
73
|
);
|
|
@@ -110,6 +75,138 @@ export function useCommand(): UseCommandResult {
|
|
|
110
75
|
return { execute, isRunning };
|
|
111
76
|
}
|
|
112
77
|
|
|
78
|
+
/**
|
|
79
|
+
* Run an interactive command as a child process with inherited stdin.
|
|
80
|
+
* Ink is temporarily suspended so the child can own the terminal.
|
|
81
|
+
*/
|
|
82
|
+
async function executeInteractive(
|
|
83
|
+
input: string,
|
|
84
|
+
onLine: (line: string) => void
|
|
85
|
+
): Promise<void> {
|
|
86
|
+
const tokens = parseTokens(input);
|
|
87
|
+
|
|
88
|
+
onLine(chalk.dim(" ◈ Launching interactive session..."));
|
|
89
|
+
onLine("");
|
|
90
|
+
|
|
91
|
+
return new Promise<void>((resolve) => {
|
|
92
|
+
// Spawn arc402 as a child process with full terminal access.
|
|
93
|
+
// Use stdio: 'inherit' so the child owns stdin/stdout/stderr directly.
|
|
94
|
+
// This means its output goes straight to the terminal (not captured in viewport)
|
|
95
|
+
// but that's correct — the child needs raw terminal access for QR codes, prompts, etc.
|
|
96
|
+
const child = spawn(
|
|
97
|
+
process.execPath,
|
|
98
|
+
[process.argv[1], ...tokens],
|
|
99
|
+
{
|
|
100
|
+
stdio: "inherit",
|
|
101
|
+
env: { ...process.env, ARC402_NO_TUI: "1" }, // prevent child from launching its own TUI
|
|
102
|
+
cwd: process.cwd(),
|
|
103
|
+
}
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
child.on("close", (code) => {
|
|
107
|
+
onLine("");
|
|
108
|
+
if (code === 0) {
|
|
109
|
+
onLine(` ${c.success} ${chalk.dim("Command completed")}`);
|
|
110
|
+
} else {
|
|
111
|
+
onLine(` ${c.failure} ${chalk.red(`Command exited with code ${code}`)}`);
|
|
112
|
+
}
|
|
113
|
+
resolve();
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
child.on("error", (err) => {
|
|
117
|
+
onLine(` ${c.failure} ${chalk.red(`Failed to spawn: ${err.message}`)}`);
|
|
118
|
+
resolve();
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Run a non-interactive command in-process with captured output.
|
|
125
|
+
*/
|
|
126
|
+
async function executeInProcess(
|
|
127
|
+
input: string,
|
|
128
|
+
onLine: (line: string) => void
|
|
129
|
+
): Promise<void> {
|
|
130
|
+
// Capture stdout/stderr
|
|
131
|
+
const originalStdoutWrite = process.stdout.write.bind(process.stdout);
|
|
132
|
+
const originalStderrWrite = process.stderr.write.bind(process.stderr);
|
|
133
|
+
|
|
134
|
+
let captureBuffer = "";
|
|
135
|
+
|
|
136
|
+
const flushBuffer = (): void => {
|
|
137
|
+
if (!captureBuffer) return;
|
|
138
|
+
const lines = captureBuffer.split("\n");
|
|
139
|
+
captureBuffer = lines.pop() ?? "";
|
|
140
|
+
for (const line of lines) {
|
|
141
|
+
onLine(line);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
const capturedWrite = (
|
|
146
|
+
chunk: string | Uint8Array,
|
|
147
|
+
encodingOrCb?: BufferEncoding | ((err?: Error | null) => void),
|
|
148
|
+
cb?: (err?: Error | null) => void
|
|
149
|
+
): boolean => {
|
|
150
|
+
const str =
|
|
151
|
+
typeof chunk === "string"
|
|
152
|
+
? chunk
|
|
153
|
+
: Buffer.from(chunk).toString("utf8");
|
|
154
|
+
captureBuffer += str;
|
|
155
|
+
flushBuffer();
|
|
156
|
+
const callback =
|
|
157
|
+
typeof encodingOrCb === "function" ? encodingOrCb : cb;
|
|
158
|
+
if (callback) callback();
|
|
159
|
+
return true;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
163
|
+
(process.stdout as any).write = capturedWrite;
|
|
164
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
165
|
+
(process.stderr as any).write = capturedWrite;
|
|
166
|
+
|
|
167
|
+
try {
|
|
168
|
+
const tokens = parseTokens(input);
|
|
169
|
+
const prog = createProgram();
|
|
170
|
+
prog.exitOverride();
|
|
171
|
+
prog.configureOutput({
|
|
172
|
+
writeOut: (str) => process.stdout.write(str),
|
|
173
|
+
writeErr: (str) => process.stderr.write(str),
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
await prog.parseAsync(["node", "arc402", ...tokens]);
|
|
177
|
+
} catch (err) {
|
|
178
|
+
const e = err as { code?: string; message?: string };
|
|
179
|
+
if (
|
|
180
|
+
e.code === "commander.helpDisplayed" ||
|
|
181
|
+
e.code === "commander.version" ||
|
|
182
|
+
e.code === "commander.executeSubCommandAsync"
|
|
183
|
+
) {
|
|
184
|
+
// already written or normal exit — no-op
|
|
185
|
+
} else if (e.code === "commander.unknownCommand") {
|
|
186
|
+
const tokens = parseTokens(input);
|
|
187
|
+
onLine(
|
|
188
|
+
` ${c.failure} ${chalk.red(`Unknown command: ${chalk.white(tokens[0])}`)} `
|
|
189
|
+
);
|
|
190
|
+
onLine(chalk.dim(" Type 'help' for available commands"));
|
|
191
|
+
} else if (e.code?.startsWith("commander.")) {
|
|
192
|
+
onLine(` ${c.failure} ${chalk.red(e.message ?? String(err))}`);
|
|
193
|
+
} else {
|
|
194
|
+
onLine(` ${c.failure} ${chalk.red(e.message ?? String(err))}`);
|
|
195
|
+
}
|
|
196
|
+
} finally {
|
|
197
|
+
// Flush remaining buffer
|
|
198
|
+
if (captureBuffer.trim()) {
|
|
199
|
+
onLine(captureBuffer);
|
|
200
|
+
captureBuffer = "";
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
204
|
+
(process.stdout as any).write = originalStdoutWrite;
|
|
205
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
206
|
+
(process.stderr as any).write = originalStderrWrite;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
113
210
|
// Shell-style tokenizer
|
|
114
211
|
function parseTokens(input: string): string[] {
|
|
115
212
|
const tokens: string[] = [];
|