archymedes-cli 3.0.0 → 3.2.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.
@@ -1,155 +0,0 @@
1
- import {
2
- __require
3
- } from "./archymedes-x67v3n58.mjs";
4
-
5
- // packages/archymedes-cli/src/ui/pager-screen.tsx
6
- import { useInput, useState } from "@termuijs/jsx";
7
- import { Box, Text } from "@termuijs/widgets";
8
-
9
- // packages/archymedes-cli/src/ui/text-pager.ts
10
- var ANSI = /\x1b\[[0-9;?]*[A-Za-z]|\x1b\][^\x07]*\x07/g;
11
- function initialPagerState(text, height) {
12
- const lines = text.replace(ANSI, "").replace(/\r/g, "").split(`
13
- `);
14
- const rows = Math.max(1, height);
15
- return { lines, top: Math.max(0, lines.length - rows), height: rows, search: { query: "", typing: false } };
16
- }
17
- function keyToPagerAction(key, character, state) {
18
- const name = key.name ?? "";
19
- if (key.ctrl && name === "c")
20
- return { kind: "exit" };
21
- if (state.search.typing) {
22
- if (name === "escape")
23
- return { kind: "searchCancel" };
24
- if (name === "return" || name === "enter")
25
- return { kind: "searchCommit" };
26
- if (name === "backspace")
27
- return { kind: "searchBackspace" };
28
- if (character && character.length === 1 && character >= " ")
29
- return { kind: "searchType", character };
30
- return { kind: "none" };
31
- }
32
- if (name === "escape" || character === "q")
33
- return { kind: "exit" };
34
- if (name === "up" || character === "k")
35
- return { kind: "scroll", rows: -1 };
36
- if (name === "down" || character === "j" || name === "return" || name === "enter")
37
- return { kind: "scroll", rows: 1 };
38
- if (name === "pageup" || character === "b")
39
- return { kind: "scroll", rows: -(state.height - 1) };
40
- if (name === "pagedown" || name === "space" || character === " ")
41
- return { kind: "scroll", rows: state.height - 1 };
42
- if (name === "home" || character === "g")
43
- return { kind: "home" };
44
- if (name === "end" || character === "G")
45
- return { kind: "end" };
46
- if (character === "/")
47
- return { kind: "search" };
48
- if (character === "n")
49
- return { kind: "searchNext" };
50
- return { kind: "none" };
51
- }
52
- function clampTop(state, top) {
53
- return Math.max(0, Math.min(top, Math.max(0, state.lines.length - state.height)));
54
- }
55
- function findFrom(state, from) {
56
- const needle = state.search.query.toLowerCase();
57
- if (!needle)
58
- return -1;
59
- for (let offset = 0;offset < state.lines.length; offset += 1) {
60
- const row = (from + offset) % state.lines.length;
61
- if (state.lines[row].toLowerCase().includes(needle))
62
- return row;
63
- }
64
- return -1;
65
- }
66
- function applyPagerAction(state, action) {
67
- switch (action.kind) {
68
- case "exit":
69
- return { state, exit: true };
70
- case "scroll":
71
- return { state: { ...state, top: clampTop(state, state.top + action.rows), message: undefined } };
72
- case "home":
73
- return { state: { ...state, top: 0, message: undefined } };
74
- case "end":
75
- return { state: { ...state, top: clampTop(state, state.lines.length), message: undefined } };
76
- case "search":
77
- return { state: { ...state, search: { query: "", typing: true }, message: undefined } };
78
- case "searchType":
79
- return { state: { ...state, search: { ...state.search, query: state.search.query + action.character } } };
80
- case "searchBackspace":
81
- return { state: { ...state, search: { ...state.search, query: state.search.query.slice(0, -1) } } };
82
- case "searchCancel":
83
- return { state: { ...state, search: { query: "", typing: false } } };
84
- case "searchCommit":
85
- case "searchNext": {
86
- const settled = { ...state, search: { ...state.search, typing: false } };
87
- const row = findFrom(settled, action.kind === "searchCommit" ? state.top : state.top + 1);
88
- if (row < 0)
89
- return { state: { ...settled, message: state.search.query ? `no match for "${state.search.query}"` : undefined } };
90
- return { state: { ...settled, top: clampTop(settled, row), message: undefined } };
91
- }
92
- default:
93
- return { state };
94
- }
95
- }
96
- function composePagerFrame(state, columns, title = "transcript") {
97
- const clip = (text) => text.length <= columns ? text : text.slice(0, Math.max(0, columns - 1));
98
- const last = Math.min(state.lines.length, state.top + state.height);
99
- const position = `${state.lines.length === 0 ? 0 : state.top + 1}-${last} of ${state.lines.length}`;
100
- const body = state.lines.slice(state.top, state.top + state.height).map((text) => ({ text: clip(text) }));
101
- while (body.length < state.height)
102
- body.push({ text: "" });
103
- const bar = state.search.typing ? `/${state.search.query} Enter find · Esc cancel` : state.message ?? "↑↓ scroll · PgUp/PgDn page · g/G ends · / find · Esc back";
104
- return [
105
- { text: clip(`${title} ${position}`), bold: true },
106
- ...body,
107
- { text: clip(bar), dim: true }
108
- ];
109
- }
110
-
111
- // packages/archymedes-cli/src/ui/pager-screen.tsx
112
- import { jsxDEV } from "@termuijs/jsx/jsx-dev-runtime";
113
- var Panel = Box;
114
- var Line = Text;
115
- var CHROME_ROWS = 2;
116
- function PagerScreen({ columns, rows, text, title, onExit }) {
117
- const [state, setState] = useState(() => initialPagerState(text, rows - CHROME_ROWS));
118
- useInput((input, key) => {
119
- const action = keyToPagerAction({ name: key?.key, ctrl: key?.ctrl }, input, state);
120
- const step = applyPagerAction(state, action);
121
- if (step.exit) {
122
- onExit();
123
- return;
124
- }
125
- setState(step.state);
126
- });
127
- const frame = composePagerFrame(state, columns, title);
128
- return /* @__PURE__ */ jsxDEV(Panel, {
129
- flexDirection: "column",
130
- width: columns,
131
- height: rows,
132
- children: frame.map((row, index) => /* @__PURE__ */ jsxDEV(Line, {
133
- bold: row.bold,
134
- dimColor: row.dim,
135
- children: row.text
136
- }, `row-${index}`, false, undefined, this))
137
- }, undefined, false, undefined, this);
138
- }
139
- async function runPagerScreen(options) {
140
- const { renderApp } = await import("@termuijs/jsx");
141
- await new Promise((resolve) => {
142
- let settled = false;
143
- const finish = () => {
144
- if (settled)
145
- return;
146
- settled = true;
147
- resolve();
148
- };
149
- renderApp(PagerScreen, { ...options, onExit: finish, fullscreen: true }).catch(finish);
150
- });
151
- }
152
- export {
153
- runPagerScreen,
154
- PagerScreen
155
- };
@@ -1,70 +0,0 @@
1
- import {
2
- applyAction,
3
- composeFrame,
4
- keyToAction
5
- } from "./archymedes-e8vb7ty3.mjs";
6
- import"./archymedes-qsrxyhb3.mjs";
7
- import"./archymedes-2emwtckp.mjs";
8
- import {
9
- exitTopTermUIApp
10
- } from "./archymedes-y64yssbc.mjs";
11
- import {
12
- __require
13
- } from "./archymedes-x67v3n58.mjs";
14
-
15
- // packages/archymedes-cli/src/ui/workspace-screen.tsx
16
- import { useInput, useInterval, useState } from "@termuijs/jsx";
17
- import { Box, Text } from "@termuijs/widgets";
18
- import { jsxDEV } from "@termuijs/jsx/jsx-dev-runtime";
19
- var Panel = Box;
20
- var Line = Text;
21
- function Workspace({ read, onExit, refreshMs = 200 }) {
22
- const [snapshot, setSnapshot] = useState(() => read());
23
- useInterval(() => {
24
- setSnapshot((current) => ({ ...read(), selected: current.selected, scroll: current.scroll }));
25
- }, refreshMs);
26
- useInput((input, key) => {
27
- const action = keyToAction({ name: key?.key, ctrl: key?.ctrl, shift: key?.shift }, input);
28
- if (action.kind === "exit") {
29
- onExit();
30
- return;
31
- }
32
- setSnapshot((current) => applyAction(current, action));
33
- });
34
- const rows = composeFrame(snapshot);
35
- return /* @__PURE__ */ jsxDEV(Panel, {
36
- flexDirection: "column",
37
- width: snapshot.columns,
38
- height: snapshot.rows,
39
- children: rows.map((row, index) => /* @__PURE__ */ jsxDEV(Line, {
40
- bold: row.bold,
41
- dimColor: row.dim,
42
- inverse: row.inverse,
43
- color: row.color,
44
- children: row.text
45
- }, `row-${index}`, false, undefined, this))
46
- }, undefined, false, undefined, this);
47
- }
48
- async function runWorkspace(host) {
49
- const { renderApp } = await import("@termuijs/jsx");
50
- await new Promise((resolve) => {
51
- let settled = false;
52
- const finish = () => {
53
- if (settled)
54
- return;
55
- settled = true;
56
- exitTopTermUIApp();
57
- host.onExit?.();
58
- resolve();
59
- };
60
- renderApp(Workspace, {
61
- read: host.read,
62
- onExit: finish,
63
- fullscreen: true
64
- }).catch(finish);
65
- });
66
- }
67
- export {
68
- runWorkspace,
69
- Workspace
70
- };