@elumixor/devkit 0.11.1 → 0.12.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 +10 -1
- package/package.json +1 -1
- package/src/bin/devkit.ts +6 -0
- package/src/dev/board.tsx +274 -27
- package/src/dev/clipboard.ts +17 -0
- package/src/update.ts +32 -0
package/README.md
CHANGED
|
@@ -19,6 +19,9 @@ So does a positional, for a shell that completes them: `devkit build mac iwatch`
|
|
|
19
19
|
bun add -d @elumixor/devkit
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
+
`devkit update` moves the global `devkit` and, run inside a project, its dependency to the newest
|
|
23
|
+
published version (`--dry` prints what would change).
|
|
24
|
+
|
|
22
25
|
## Configure
|
|
23
26
|
|
|
24
27
|
Add a `devkit` block to your root `package.json`. Three phases, each a map of platform name to one
|
|
@@ -79,9 +82,15 @@ at the top, the merged log below.
|
|
|
79
82
|
── all ─────────────────────────────────────────────────────────────────────────────
|
|
80
83
|
web:frontend │ VITE v8.3.0 ready in 1055 ms
|
|
81
84
|
web:backend │ [nitro] ✔ Nitro Server built in 521ms
|
|
82
|
-
1-2 focus a all o open r restart c clear
|
|
85
|
+
1-2 focus a all o open r restart c clear jk ud gg G scroll v select y copy q quit
|
|
83
86
|
```
|
|
84
87
|
|
|
88
|
+
The log scrolls like `less`: `j`/`k` or arrows by a line, `u`/`d` by half a screen, PgUp/PgDn by a
|
|
89
|
+
screen, `gg` to the top and `G` back to following. `v` (or `V`) starts a line selection at the bottom
|
|
90
|
+
row; move it with the same keys and `y` copies it to the clipboard, `y` alone copies what is on screen.
|
|
91
|
+
Dragging with the mouse selects too, scrolling on its own while the pointer is above or below the log,
|
|
92
|
+
and copies on release; the wheel scrolls. Hold Option (macOS) or Shift for the terminal's own selection.
|
|
93
|
+
|
|
85
94
|
A crashed process stays on the board until you restart it with `r`; the rest keep running. Anywhere
|
|
86
95
|
else (an agent's shell, CI, a pipe, or `--plain`) it prints prefixed lines instead: the URLs first,
|
|
87
96
|
then a `devkit` line for every ready, crash and exit, and one `all ready:` line listing every URL.
|
package/package.json
CHANGED
package/src/bin/devkit.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { runRelease } from "../release.ts";
|
|
|
11
11
|
import { runTarget } from "../run-target.ts";
|
|
12
12
|
import { pullSecrets, pushSecrets } from "../secrets.ts";
|
|
13
13
|
import { runSetup } from "../setup.ts";
|
|
14
|
+
import { runUpdate } from "../update.ts";
|
|
14
15
|
import { runVersion } from "../version.ts";
|
|
15
16
|
|
|
16
17
|
const { values, positionals } = parseArgs({
|
|
@@ -43,6 +44,7 @@ const usage = `usage: devkit dev [platforms...] run the dev processes
|
|
|
43
44
|
devkit version write the source version into every file that declares one
|
|
44
45
|
devkit release <prefix> tag this commit <prefix>-v<timestamp> and push it
|
|
45
46
|
devkit secrets push|pull [root] sync age-encrypted secrets
|
|
47
|
+
devkit update [--dry] update the global devkit and this project's dependency to the latest
|
|
46
48
|
|
|
47
49
|
Platforms are whatever "devkit.dev", "devkit.build" and "devkit.deploy" name in package.json —
|
|
48
50
|
typically web, mac, iphone, iwatch. Naming one also runs the platforms it declares in "needs".
|
|
@@ -115,6 +117,10 @@ try {
|
|
|
115
117
|
await runRelease(rest[0] ?? "");
|
|
116
118
|
break;
|
|
117
119
|
}
|
|
120
|
+
case "update": {
|
|
121
|
+
await runUpdate(values.dry);
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
118
124
|
case "secrets": {
|
|
119
125
|
const [action, dir] = rest;
|
|
120
126
|
chdirTo(dir);
|
package/src/dev/board.tsx
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/** @jsxImportSource react */
|
|
2
2
|
import { relative } from "node:path";
|
|
3
|
-
import { Box, render, Text, useApp, useInput, useStdout } from "ink";
|
|
4
|
-
import { useEffect, useMemo, useState, useSyncExternalStore } from "react";
|
|
3
|
+
import { Box, type Key, render, Text, useApp, useInput, useStdout } from "ink";
|
|
4
|
+
import { useEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
|
|
5
5
|
import wrapAnsi from "wrap-ansi";
|
|
6
|
+
import { stripColor } from "../ansi.ts";
|
|
7
|
+
import { copyToClipboard } from "./clipboard.ts";
|
|
6
8
|
import type { Service, ServiceState } from "./service.ts";
|
|
7
9
|
import { DEVKIT, type LogEntry, type Supervisor } from "./supervisor.ts";
|
|
8
10
|
|
|
@@ -15,6 +17,17 @@ const CHROME_ROWS = 3;
|
|
|
15
17
|
/** Ink falls back to clearing the whole screen once a frame fills it, which flickers. */
|
|
16
18
|
const SPARE_ROWS = 1;
|
|
17
19
|
const MIN_LOG_WIDTH = 20;
|
|
20
|
+
const FLASH_MS = 2000;
|
|
21
|
+
const AUTOSCROLL_MS = 50;
|
|
22
|
+
const WHEEL_LINES = 3;
|
|
23
|
+
/** SGR mouse button codes: motion adds 32, the wheel is 64 and 65. */
|
|
24
|
+
const LEFT = 0;
|
|
25
|
+
const LEFT_DRAG = 32;
|
|
26
|
+
const WHEEL_UP = 64;
|
|
27
|
+
const WHEEL_DOWN = 65;
|
|
28
|
+
/** Button presses, drags and releases, reported as SGR coordinates. */
|
|
29
|
+
const MOUSE_ON = "\x1b[?1002h\x1b[?1006h";
|
|
30
|
+
const MOUSE_OFF = "\x1b[?1002l\x1b[?1006l";
|
|
18
31
|
|
|
19
32
|
const MARK: Record<ServiceState, { glyph: string; color: string }> = {
|
|
20
33
|
starting: { glyph: "", color: "yellow" },
|
|
@@ -40,19 +53,47 @@ export async function runBoard(supervisor: Supervisor, title: string) {
|
|
|
40
53
|
|
|
41
54
|
function Board({ supervisor, title }: { readonly supervisor: Supervisor; readonly title: string }) {
|
|
42
55
|
const { exit } = useApp();
|
|
56
|
+
const { stdout } = useStdout();
|
|
43
57
|
const { cols, rows } = useTerminalSize();
|
|
44
58
|
useThrottledVersion(supervisor);
|
|
59
|
+
useMouseReporting(stdout);
|
|
45
60
|
const frame = useFrame(supervisor.services.some((s) => s.state === "starting" || s.state === "stopping"));
|
|
46
61
|
|
|
47
62
|
const [focus, setFocus] = useState<number | null>(null);
|
|
48
63
|
/** `seq` the view ends before while scrolled back; `null` follows the newest line. */
|
|
49
64
|
const [end, setEnd] = useState<number | null>(null);
|
|
50
65
|
const [quitting, setQuitting] = useState(false);
|
|
66
|
+
/** `seq` the selection started at; `null` outside visual mode. */
|
|
67
|
+
const [anchor, setAnchor] = useState<number | null>(null);
|
|
68
|
+
const [cursor, setCursor] = useState(0);
|
|
69
|
+
const [dragging, setDragging] = useState(false);
|
|
70
|
+
const [flash, setFlash] = useState<string | null>(null);
|
|
71
|
+
/** The first `g` of `gg`. */
|
|
72
|
+
const pendingG = useRef(false);
|
|
73
|
+
/** Whether the view followed new lines before visual mode paused it. */
|
|
74
|
+
const resumeFollow = useRef(false);
|
|
75
|
+
/** Rows per tick the view scrolls while a drag is held above or below the log. */
|
|
76
|
+
const autoscroll = useRef(0);
|
|
77
|
+
const step = useRef(() => {});
|
|
78
|
+
|
|
79
|
+
useEffect(() => {
|
|
80
|
+
if (!flash) return;
|
|
81
|
+
const timer = setTimeout(() => setFlash(null), FLASH_MS);
|
|
82
|
+
return () => clearTimeout(timer);
|
|
83
|
+
}, [flash]);
|
|
84
|
+
|
|
85
|
+
useEffect(() => {
|
|
86
|
+
if (!dragging) return;
|
|
87
|
+
const timer = setInterval(() => step.current(), AUTOSCROLL_MS);
|
|
88
|
+
return () => clearInterval(timer);
|
|
89
|
+
}, [dragging]);
|
|
51
90
|
|
|
52
91
|
const services = supervisor.services;
|
|
53
92
|
const logRows = Math.max(1, rows - CHROME_ROWS - SPARE_ROWS - services.length);
|
|
93
|
+
const logTop = services.length + 3;
|
|
54
94
|
const labelWidth = Math.max("devkit".length, ...services.map((s) => s.spec.label.length));
|
|
55
95
|
const textWidth = Math.max(MIN_LOG_WIDTH, cols - labelWidth - 3);
|
|
96
|
+
const halfPage = Math.max(1, Math.floor(logRows / 2));
|
|
56
97
|
|
|
57
98
|
const shown = supervisor.entries.filter(
|
|
58
99
|
(entry) => focus == null || entry.source === focus || entry.source === DEVKIT,
|
|
@@ -65,24 +106,123 @@ function Board({ supervisor, title }: { readonly supervisor: Supervisor; readonl
|
|
|
65
106
|
const lines = tail(shown, endIndex, logRows, textWidth, who);
|
|
66
107
|
const newer = shown.length - endIndex;
|
|
67
108
|
|
|
109
|
+
const visual = anchor != null;
|
|
110
|
+
const low = Math.min(anchor ?? 0, cursor);
|
|
111
|
+
const high = Math.max(anchor ?? 0, cursor);
|
|
112
|
+
const markOf = (seq: number) =>
|
|
113
|
+
!visual || seq < low || seq > high ? undefined : seq === cursor ? "cursor" : "selected";
|
|
114
|
+
|
|
68
115
|
const scroll = (by: number) => {
|
|
69
116
|
const next = Math.min(shown.length, Math.max(firstFullScreen(shown, logRows, textWidth), endIndex + by));
|
|
70
117
|
setEnd(next >= shown.length ? null : (shown[next]?.seq ?? null));
|
|
71
118
|
};
|
|
72
119
|
|
|
120
|
+
/** Ends the view before `index`, staying put at the bottom instead of following. */
|
|
121
|
+
const showUntil = (index: number) =>
|
|
122
|
+
setEnd(index >= shown.length ? (shown.at(-1)?.seq ?? -1) + 1 : (shown[index]?.seq ?? null));
|
|
123
|
+
|
|
124
|
+
const moveCursor = (index: number) => {
|
|
125
|
+
const to = Math.min(shown.length - 1, Math.max(0, index));
|
|
126
|
+
const entry = shown[to];
|
|
127
|
+
if (!entry) return;
|
|
128
|
+
setCursor(entry.seq);
|
|
129
|
+
if (to >= endIndex) showUntil(to + 1);
|
|
130
|
+
else if (to < firstVisible(shown, endIndex, logRows, textWidth)) showUntil(endFor(shown, to, logRows, textWidth));
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
const startVisual = (seq: number) => {
|
|
134
|
+
if (!visual) resumeFollow.current = end == null;
|
|
135
|
+
showUntil(endIndex);
|
|
136
|
+
setAnchor(seq);
|
|
137
|
+
setCursor(seq);
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const stopVisual = () => {
|
|
141
|
+
setAnchor(null);
|
|
142
|
+
setDragging(false);
|
|
143
|
+
autoscroll.current = 0;
|
|
144
|
+
if (resumeFollow.current) setEnd(null);
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const yank = (entries: readonly LogEntry[]) => {
|
|
148
|
+
if (entries.length === 0) return;
|
|
149
|
+
copyToClipboard(entries.map((entry) => stripColor(entry.text)).join("\n"), stdout);
|
|
150
|
+
setFlash(`copied ${entries.length} line${entries.length === 1 ? "" : "s"}`);
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
const yankSelection = () => {
|
|
154
|
+
yank(shown.filter((entry) => entry.seq >= low && entry.seq <= high));
|
|
155
|
+
stopVisual();
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
const cursorIndex = Math.min(shown.length - 1, countBefore(shown, cursor));
|
|
159
|
+
step.current = () => {
|
|
160
|
+
if (autoscroll.current) moveCursor(cursorIndex + autoscroll.current);
|
|
161
|
+
};
|
|
162
|
+
|
|
73
163
|
const quit = () => {
|
|
74
164
|
if (quitting) return;
|
|
75
165
|
setQuitting(true);
|
|
76
166
|
void supervisor.stop().then(() => exit());
|
|
77
167
|
};
|
|
78
168
|
|
|
79
|
-
|
|
169
|
+
const onMouse = ({ button, row, release }: MouseEvent) => {
|
|
170
|
+
const at = row - logTop;
|
|
171
|
+
if (button === WHEEL_UP || button === WHEEL_DOWN) {
|
|
172
|
+
const by = button === WHEEL_UP ? -WHEEL_LINES : WHEEL_LINES;
|
|
173
|
+
return visual ? moveCursor(cursorIndex + by) : scroll(by);
|
|
174
|
+
}
|
|
175
|
+
if (release) {
|
|
176
|
+
if (!dragging) return;
|
|
177
|
+
return anchor === cursor ? stopVisual() : yankSelection();
|
|
178
|
+
}
|
|
179
|
+
if (button === LEFT) {
|
|
180
|
+
const line = lines[at];
|
|
181
|
+
if (!line) return;
|
|
182
|
+
startVisual(line.seq);
|
|
183
|
+
return setDragging(true);
|
|
184
|
+
}
|
|
185
|
+
if (button === LEFT_DRAG && dragging) {
|
|
186
|
+
autoscroll.current = at < 0 ? at : at >= logRows ? at - logRows + 1 : 0;
|
|
187
|
+
const line = lines[Math.min(lines.length - 1, Math.max(0, at))];
|
|
188
|
+
if (!autoscroll.current && line) setCursor(line.seq);
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
/** `times` repeats a movement, for a key held down faster than the board redraws. */
|
|
193
|
+
const onKey = (input: string, key: Key, times = 1) => {
|
|
194
|
+
const gg = input === "g" && pendingG.current;
|
|
195
|
+
pendingG.current = input === "g" && !gg;
|
|
80
196
|
if (input === "q" || (key.ctrl && input === "c")) return quit();
|
|
197
|
+
|
|
81
198
|
// Before Escape: Ink flags `escape` on every escape sequence, arrows and paging included.
|
|
82
|
-
if (
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
199
|
+
if (visual) {
|
|
200
|
+
if (input === "y" || key.return) return yankSelection();
|
|
201
|
+
if (key.upArrow || input === "k") return moveCursor(cursorIndex - times);
|
|
202
|
+
if (key.downArrow || input === "j") return moveCursor(cursorIndex + times);
|
|
203
|
+
if (input === "u") return moveCursor(cursorIndex - halfPage * times);
|
|
204
|
+
if (input === "d") return moveCursor(cursorIndex + halfPage * times);
|
|
205
|
+
if (key.pageUp || (key.ctrl && input === "b")) return moveCursor(cursorIndex - (logRows - 1) * times);
|
|
206
|
+
if (key.pageDown || (key.ctrl && input === "f")) return moveCursor(cursorIndex + (logRows - 1) * times);
|
|
207
|
+
if (gg || key.home) return moveCursor(0);
|
|
208
|
+
if (input === "G" || key.end) return moveCursor(shown.length - 1);
|
|
209
|
+
if (key.escape || input === "v" || input === "V") stopVisual();
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// Before Escape: Ink flags `escape` on every escape sequence, arrows and paging included.
|
|
214
|
+
if (key.upArrow || input === "k") return scroll(-times);
|
|
215
|
+
if (key.downArrow || input === "j") return scroll(times);
|
|
216
|
+
if (input === "u") return scroll(-halfPage * times);
|
|
217
|
+
if (input === "d") return scroll(halfPage * times);
|
|
218
|
+
if (key.pageUp || (key.ctrl && input === "b")) return scroll(-(logRows - 1) * times);
|
|
219
|
+
if (key.pageDown || (key.ctrl && input === "f")) return scroll((logRows - 1) * times);
|
|
220
|
+
if (gg || key.home) return scroll(-shown.length);
|
|
221
|
+
if (input === "v" || input === "V") {
|
|
222
|
+
const last = shown[endIndex - 1];
|
|
223
|
+
return last && startVisual(last.seq);
|
|
224
|
+
}
|
|
225
|
+
if (input === "y") return yank(shown.slice(firstVisible(shown, endIndex, logRows, textWidth), endIndex));
|
|
86
226
|
const digit = Number(input);
|
|
87
227
|
if (Number.isInteger(digit) && digit >= 1 && digit <= services.length) {
|
|
88
228
|
setFocus(focus === digit - 1 ? null : digit - 1);
|
|
@@ -99,6 +239,17 @@ function Board({ supervisor, title }: { readonly supervisor: Supervisor; readonl
|
|
|
99
239
|
return setEnd(null);
|
|
100
240
|
}
|
|
101
241
|
if (key.end || input === "G" || input === "f") setEnd(null);
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
useInput((input, key) => {
|
|
245
|
+
const mouse = parseMouse(input);
|
|
246
|
+
if (mouse) return onMouse(mouse);
|
|
247
|
+
// Keys typed faster than the board redraws arrive together: `gg`, or `jjj` from a held key.
|
|
248
|
+
if (input.length < 2 || !/^\w+$/.test(input)) return onKey(input, key);
|
|
249
|
+
for (const [run, char = ""] of input.matchAll(/(\w)\1*/g)) {
|
|
250
|
+
if (char === "g") for (const _ of run) onKey(char, key);
|
|
251
|
+
else onKey(char, key, run.length);
|
|
252
|
+
}
|
|
102
253
|
});
|
|
103
254
|
|
|
104
255
|
return (
|
|
@@ -125,15 +276,34 @@ function Board({ supervisor, title }: { readonly supervisor: Supervisor; readonl
|
|
|
125
276
|
{`── ${focus == null ? "all" : services[focus]?.spec.label} `.padEnd(cols, "─")}
|
|
126
277
|
</Text>
|
|
127
278
|
<Box flexDirection="column" height={logRows} overflow="hidden">
|
|
128
|
-
{lines.map((line) =>
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
<
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
279
|
+
{lines.map((line) => {
|
|
280
|
+
const mark = markOf(line.seq);
|
|
281
|
+
return (
|
|
282
|
+
<Box key={line.key}>
|
|
283
|
+
<Text color={line.color}>{(line.first ? line.label : "").padEnd(labelWidth)}</Text>
|
|
284
|
+
{mark ? (
|
|
285
|
+
<Text color="yellow">{mark === "cursor" && line.first ? " ▶ " : " ┃ "}</Text>
|
|
286
|
+
) : (
|
|
287
|
+
<Text dimColor> │ </Text>
|
|
288
|
+
)}
|
|
289
|
+
{/* Inverse on the plain text: a child's own colour resets would cut the highlight short. */}
|
|
290
|
+
{mark ? (
|
|
291
|
+
<Text inverse wrap="truncate-end">
|
|
292
|
+
{stripColor(line.text) || " "}
|
|
293
|
+
</Text>
|
|
294
|
+
) : (
|
|
295
|
+
<Text wrap="truncate-end">{line.text}</Text>
|
|
296
|
+
)}
|
|
297
|
+
</Box>
|
|
298
|
+
);
|
|
299
|
+
})}
|
|
135
300
|
</Box>
|
|
136
|
-
<Footer
|
|
301
|
+
<Footer
|
|
302
|
+
count={services.length}
|
|
303
|
+
newer={end == null ? 0 : newer}
|
|
304
|
+
selected={visual ? shown.filter((entry) => entry.seq >= low && entry.seq <= high).length : null}
|
|
305
|
+
flash={flash}
|
|
306
|
+
/>
|
|
137
307
|
</Box>
|
|
138
308
|
);
|
|
139
309
|
}
|
|
@@ -196,20 +366,42 @@ function StateText({ service }: { readonly service: Service }) {
|
|
|
196
366
|
}
|
|
197
367
|
}
|
|
198
368
|
|
|
199
|
-
function Footer({
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
369
|
+
function Footer({
|
|
370
|
+
count,
|
|
371
|
+
newer,
|
|
372
|
+
selected,
|
|
373
|
+
flash,
|
|
374
|
+
}: {
|
|
375
|
+
readonly count: number;
|
|
376
|
+
readonly newer: number;
|
|
377
|
+
/** Lines in the visual selection; `null` outside visual mode. */
|
|
378
|
+
readonly selected: number | null;
|
|
379
|
+
readonly flash: string | null;
|
|
380
|
+
}) {
|
|
381
|
+
const keys =
|
|
382
|
+
selected == null
|
|
383
|
+
? [
|
|
384
|
+
[count > 1 ? `1-${count}` : "1", "focus"],
|
|
385
|
+
["a", "all"],
|
|
386
|
+
["o", "open"],
|
|
387
|
+
["r", "restart"],
|
|
388
|
+
["c", "clear"],
|
|
389
|
+
["jk ud gg G", "scroll"],
|
|
390
|
+
["v", "select"],
|
|
391
|
+
["y", "copy"],
|
|
392
|
+
["q", "quit"],
|
|
393
|
+
]
|
|
394
|
+
: [
|
|
395
|
+
["jk ud gg G", "move"],
|
|
396
|
+
["y", "copy"],
|
|
397
|
+
["esc", "cancel"],
|
|
398
|
+
];
|
|
209
399
|
return (
|
|
210
400
|
<Text wrap="truncate-end">
|
|
211
401
|
{" "}
|
|
212
|
-
{
|
|
402
|
+
{flash && <Text color="green">{flash} </Text>}
|
|
403
|
+
{selected != null && <Text color="yellow">VISUAL · {selected} selected </Text>}
|
|
404
|
+
{selected == null && newer > 0 && <Text color="yellow">paused · {newer} newer · f to follow </Text>}
|
|
213
405
|
{keys.map(([key, label]) => (
|
|
214
406
|
<Text key={label}>
|
|
215
407
|
<Text bold>{key}</Text>
|
|
@@ -222,6 +414,7 @@ function Footer({ count, newer }: { readonly count: number; readonly newer: numb
|
|
|
222
414
|
|
|
223
415
|
interface LogLine {
|
|
224
416
|
readonly key: string;
|
|
417
|
+
readonly seq: number;
|
|
225
418
|
readonly label: string;
|
|
226
419
|
readonly color: string;
|
|
227
420
|
readonly text: string;
|
|
@@ -242,7 +435,13 @@ function tail(
|
|
|
242
435
|
const entry = entries[i] as LogEntry;
|
|
243
436
|
const rows = wrapAnsi(entry.text, width, { hard: true, trim: false }).split("\n");
|
|
244
437
|
for (let row = rows.length - 1; row >= 0 && out.length < count; row--)
|
|
245
|
-
out.push({
|
|
438
|
+
out.push({
|
|
439
|
+
key: `${entry.seq}:${row}`,
|
|
440
|
+
seq: entry.seq,
|
|
441
|
+
text: rows[row] ?? "",
|
|
442
|
+
first: row === 0,
|
|
443
|
+
...who(entry.source),
|
|
444
|
+
});
|
|
246
445
|
}
|
|
247
446
|
return out.reverse();
|
|
248
447
|
}
|
|
@@ -260,6 +459,23 @@ function firstFullScreen(entries: readonly LogEntry[], rows: number, width: numb
|
|
|
260
459
|
return entries.length;
|
|
261
460
|
}
|
|
262
461
|
|
|
462
|
+
/** The first entry `entries[0, endIndex)` shows whole, so a cursor there needs no scrolling. */
|
|
463
|
+
function firstVisible(entries: readonly LogEntry[], endIndex: number, rows: number, width: number) {
|
|
464
|
+
let filled = 0;
|
|
465
|
+
let i = endIndex;
|
|
466
|
+
while (i > 0 && filled < rows) filled += heightOf(entries[--i] as LogEntry, width);
|
|
467
|
+
return Math.min(Math.max(0, endIndex - 1), filled > rows ? i + 1 : i);
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/** Where a view must end to show `entries[start]` on its top row. */
|
|
471
|
+
function endFor(entries: readonly LogEntry[], start: number, rows: number, width: number) {
|
|
472
|
+
let filled = 0;
|
|
473
|
+
let i = start;
|
|
474
|
+
while (i < entries.length && filled + heightOf(entries[i] as LogEntry, width) <= rows)
|
|
475
|
+
filled += heightOf(entries[i++] as LogEntry, width);
|
|
476
|
+
return Math.max(i, start + 1);
|
|
477
|
+
}
|
|
478
|
+
|
|
263
479
|
/** How many entries come before `seq` — entries are in `seq` order. */
|
|
264
480
|
function countBefore(entries: readonly LogEntry[], seq: number) {
|
|
265
481
|
let low = 0;
|
|
@@ -279,6 +495,37 @@ function openTarget(services: readonly Service[], focus: number | null) {
|
|
|
279
495
|
return marked >= 0 ? marked : services.findIndex((service) => service.url);
|
|
280
496
|
}
|
|
281
497
|
|
|
498
|
+
interface MouseEvent {
|
|
499
|
+
readonly button: number;
|
|
500
|
+
/** 1-based screen row. */
|
|
501
|
+
readonly row: number;
|
|
502
|
+
readonly release: boolean;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/** Ink hands an SGR mouse report to `useInput` whole, minus its escape. */
|
|
506
|
+
function parseMouse(input: string): MouseEvent | undefined {
|
|
507
|
+
const match = /^\[<(\d+);\d+;(\d+)([Mm])$/.exec(input);
|
|
508
|
+
if (!match) return undefined;
|
|
509
|
+
return { button: Number(match[1]), row: Number(match[2]), release: match[3] === "m" };
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
/**
|
|
513
|
+
* Takes the mouse from the terminal so a drag can select and scroll the log. The terminal's own
|
|
514
|
+
* selection stays one modifier away (Option on macOS, Shift elsewhere).
|
|
515
|
+
*/
|
|
516
|
+
function useMouseReporting(stdout: NodeJS.WriteStream) {
|
|
517
|
+
useEffect(() => {
|
|
518
|
+
if (!stdout.isTTY) return;
|
|
519
|
+
const off = () => stdout.write(MOUSE_OFF);
|
|
520
|
+
stdout.write(MOUSE_ON);
|
|
521
|
+
process.once("exit", off);
|
|
522
|
+
return () => {
|
|
523
|
+
process.off("exit", off);
|
|
524
|
+
off();
|
|
525
|
+
};
|
|
526
|
+
}, [stdout]);
|
|
527
|
+
}
|
|
528
|
+
|
|
282
529
|
function useThrottledVersion(supervisor: Supervisor) {
|
|
283
530
|
const subscribe = useMemo(
|
|
284
531
|
() => (notify: () => void) => {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
|
|
3
|
+
/** Native copy commands, tried in order; OSC 52 covers the rest, ssh sessions included. */
|
|
4
|
+
const COMMANDS: readonly (readonly [string, ...string[]])[] =
|
|
5
|
+
process.platform === "darwin"
|
|
6
|
+
? [["pbcopy"]]
|
|
7
|
+
: process.platform === "win32"
|
|
8
|
+
? [["clip"]]
|
|
9
|
+
: [["wl-copy"], ["xclip", "-selection", "clipboard"], ["xsel", "--clipboard", "--input"]];
|
|
10
|
+
|
|
11
|
+
export function copyToClipboard(text: string, stdout: NodeJS.WriteStream) {
|
|
12
|
+
for (const [command, ...args] of COMMANDS) {
|
|
13
|
+
const result = spawnSync(command, args, { input: text, stdio: ["pipe", "ignore", "ignore"] });
|
|
14
|
+
if (!result.error && result.status === 0) return;
|
|
15
|
+
}
|
|
16
|
+
stdout.write(`\x1b]52;c;${Buffer.from(text).toString("base64")}\x07`);
|
|
17
|
+
}
|
package/src/update.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { $ } from "bun";
|
|
4
|
+
import pkg from "../package.json" with { type: "json" };
|
|
5
|
+
|
|
6
|
+
const NAME = "@elumixor/devkit";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Bring devkit to the newest published version: the global `devkit` on PATH always, and the
|
|
10
|
+
* project's own dependency when the current directory declares one. A pinned version stays pinned.
|
|
11
|
+
*/
|
|
12
|
+
export async function runUpdate(dry = false) {
|
|
13
|
+
const response = await fetch(`https://registry.npmjs.org/${NAME}/latest`);
|
|
14
|
+
if (!response.ok) throw new Error(`npm registry answered ${response.status} for ${NAME}`);
|
|
15
|
+
const latest = ((await response.json()) as { version: string }).version;
|
|
16
|
+
|
|
17
|
+
console.log(`global: ${pkg.version} -> ${latest}`);
|
|
18
|
+
if (!dry) await $`bun add -g ${NAME}@${latest}`.quiet();
|
|
19
|
+
|
|
20
|
+
const manifestPath = resolve("package.json");
|
|
21
|
+
if (!existsSync(manifestPath)) return;
|
|
22
|
+
const manifest = await Bun.file(manifestPath).json();
|
|
23
|
+
const dev = manifest.devDependencies?.[NAME] as string | undefined;
|
|
24
|
+
const spec = dev ?? (manifest.dependencies?.[NAME] as string | undefined);
|
|
25
|
+
if (!spec) return;
|
|
26
|
+
|
|
27
|
+
const pinned = /^\d/.test(spec);
|
|
28
|
+
console.log(`${manifest.name ?? "project"}: ${spec} -> ${pinned ? "" : "^"}${latest}`);
|
|
29
|
+
if (dry) return;
|
|
30
|
+
const flags = [...(dev ? ["-d"] : []), ...(pinned ? ["--exact"] : [])];
|
|
31
|
+
await $`bun add ${flags} ${NAME}@${latest}`.quiet();
|
|
32
|
+
}
|