@kud/cli-shot 0.1.1 → 0.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.
- package/README.md +20 -15
- package/dist/{chunk-ZWMKVITE.js → chunk-NTFITNMX.js} +17 -3
- package/dist/cli.js +9 -4
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -39,28 +39,33 @@ brew install charmbracelet/tap/freeze # the renderer
|
|
|
39
39
|
cli-shot --out assets/screenshots -- pcloud
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
-
Everything after `--` is the command being driven
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
Everything after `--` is the command being driven, so its own flags stay clear
|
|
43
|
+
of cli-shot's.
|
|
44
|
+
|
|
45
|
+
Two exceptions: cli-shot appends `--mock` and `--screen` to that command itself.
|
|
46
|
+
Passing either one yourself leaves two in argv — the app reads the first while
|
|
47
|
+
the filename comes from the second, which is how you get a `files.png` holding
|
|
48
|
+
the Sync screen. cli-shot refuses rather than guessing, and points you at
|
|
49
|
+
`--only` or `--no-mock`.
|
|
45
50
|
|
|
46
51
|
```sh
|
|
47
|
-
cli-shot --out shots --
|
|
52
|
+
cli-shot --out shots --only sync -- pcloud # one screen
|
|
48
53
|
cli-shot --out shots --list -- pcloud # what screens exist
|
|
49
54
|
cli-shot --out shots --keys $'jjj\r' -- pcloud # drive deeper first
|
|
50
55
|
cli-shot --out shots --no-mock -- pcloud # real data (careful)
|
|
51
56
|
```
|
|
52
57
|
|
|
53
|
-
| flag
|
|
54
|
-
|
|
|
55
|
-
| `-o, --out <dir>`
|
|
56
|
-
|
|
|
57
|
-
| `--list`
|
|
58
|
-
| `--cols` / `--rows`
|
|
59
|
-
| `--settle <ms>`
|
|
60
|
-
| `--jobs <n>`
|
|
61
|
-
| `--keys <sequence>`
|
|
62
|
-
| `--font <family>`
|
|
63
|
-
| `--no-mock`
|
|
58
|
+
| flag | |
|
|
59
|
+
| ------------------- | ------------------------------------------------- |
|
|
60
|
+
| `-o, --out <dir>` | directory to write PNGs into |
|
|
61
|
+
| `--only <screen>` | shoot one screen instead of every screen |
|
|
62
|
+
| `--list` | print the screens the command offers, and stop |
|
|
63
|
+
| `--cols` / `--rows` | terminal size (default 110×32) |
|
|
64
|
+
| `--settle <ms>` | how long the screen must hold still (default 350) |
|
|
65
|
+
| `--jobs <n>` | screens shot at once; defaults to the core count |
|
|
66
|
+
| `--keys <sequence>` | keystrokes sent once the screen has drawn |
|
|
67
|
+
| `--font <family>` | font to render with; defaults to a Nerd Font |
|
|
68
|
+
| `--no-mock` | drive real data instead of fixtures |
|
|
64
69
|
|
|
65
70
|
## The contract
|
|
66
71
|
|
|
@@ -10,6 +10,7 @@ import { execFileSync } from 'child_process';
|
|
|
10
10
|
// src/index.ts
|
|
11
11
|
var { Terminal } = headless;
|
|
12
12
|
var TICK_MS = 60;
|
|
13
|
+
var HELPER_FAILURE = /execvp\(\d\) failed|posix_spawnp failed/;
|
|
13
14
|
var explainSpawnFailure = (error, command) => {
|
|
14
15
|
const message = error instanceof Error ? error.message : String(error);
|
|
15
16
|
const helper = helperPath();
|
|
@@ -62,6 +63,7 @@ var capture = (command, args = [], {
|
|
|
62
63
|
return;
|
|
63
64
|
}
|
|
64
65
|
let raw = 0;
|
|
66
|
+
let rawText = "";
|
|
65
67
|
let sentKeys = false;
|
|
66
68
|
let finished = false;
|
|
67
69
|
let previous = "";
|
|
@@ -106,16 +108,17 @@ var capture = (command, args = [], {
|
|
|
106
108
|
const hard = setTimeout(finish, timeout);
|
|
107
109
|
pty.onData((data) => {
|
|
108
110
|
raw += data.length;
|
|
111
|
+
if (rawText.length < 2048) rawText += data;
|
|
109
112
|
term.write(data);
|
|
110
113
|
});
|
|
111
114
|
pty.onExit(({ exitCode }) => {
|
|
112
|
-
if (exitCode !== 0 && raw === 0) {
|
|
115
|
+
if (exitCode !== 0 && (raw === 0 || HELPER_FAILURE.test(rawText))) {
|
|
113
116
|
finished = true;
|
|
114
117
|
clearInterval(poll);
|
|
115
118
|
clearTimeout(hard);
|
|
116
119
|
reject(
|
|
117
120
|
explainSpawnFailure(
|
|
118
|
-
new Error(`exited ${exitCode} without drawing
|
|
121
|
+
new Error(`the command exited ${exitCode} without drawing a screen`),
|
|
119
122
|
command
|
|
120
123
|
)
|
|
121
124
|
);
|
|
@@ -158,8 +161,18 @@ var toImage = (ansi, output, { font = DEFAULT_FONT, freezeArgs = [] } = {}) => {
|
|
|
158
161
|
};
|
|
159
162
|
|
|
160
163
|
// src/index.ts
|
|
164
|
+
var MANAGED_FLAGS = ["--screen", "--mock"];
|
|
165
|
+
var assertNoManagedFlags = (args) => {
|
|
166
|
+
const clash = MANAGED_FLAGS.find((flag) => args.includes(flag));
|
|
167
|
+
if (!clash) return;
|
|
168
|
+
throw new Error(
|
|
169
|
+
`${clash} is set by cli-shot, so passing it to the driven command leaves two in argv.
|
|
170
|
+
` + (clash === "--screen" ? ` Use cli-shot's --only <screen> instead, before the --.` : ` Mock data is on by default; use cli-shot's --no-mock to turn it off.`)
|
|
171
|
+
);
|
|
172
|
+
};
|
|
161
173
|
var screenArgs = (args, screen, mock) => [...args, ...mock ? ["--mock"] : [], "--screen", screen];
|
|
162
174
|
var shootScreen = async (screen, { command, args = [], out, mock = true, ...rest }) => {
|
|
175
|
+
assertNoManagedFlags(args);
|
|
163
176
|
const ansi = await capture(command, screenArgs(args, screen, mock), rest);
|
|
164
177
|
return toImage(ansi, join(out, `${screen}.png`), rest);
|
|
165
178
|
};
|
|
@@ -178,6 +191,7 @@ var pool = async (items, limit, run) => {
|
|
|
178
191
|
return results;
|
|
179
192
|
};
|
|
180
193
|
var shootAll = async (options) => {
|
|
194
|
+
assertNoManagedFlags(options.args ?? []);
|
|
181
195
|
const screens = listScreens(options.command, options.args ?? []);
|
|
182
196
|
return pool(
|
|
183
197
|
screens,
|
|
@@ -186,4 +200,4 @@ var shootAll = async (options) => {
|
|
|
186
200
|
);
|
|
187
201
|
};
|
|
188
202
|
|
|
189
|
-
export { DEFAULT_FONT, capture, listScreens, shootAll, shootScreen, toImage };
|
|
203
|
+
export { DEFAULT_FONT, MANAGED_FLAGS, capture, listScreens, shootAll, shootScreen, toImage };
|
package/dist/cli.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { DEFAULT_FONT, listScreens, shootScreen, shootAll } from './chunk-
|
|
2
|
+
import { DEFAULT_FONT, listScreens, shootScreen, shootAll } from './chunk-NTFITNMX.js';
|
|
3
3
|
import { Command } from 'commander';
|
|
4
4
|
|
|
5
5
|
var separator = process.argv.indexOf("--");
|
|
@@ -8,7 +8,7 @@ var own = separator === -1 ? process.argv : process.argv.slice(0, separator);
|
|
|
8
8
|
var program = new Command();
|
|
9
9
|
program.name("cli-shot").description(
|
|
10
10
|
"Screenshot an interactive CLI, one image per screen.\n\nThe command to drive follows `--`:\n cli-shot --out assets/screenshots -- pcloud"
|
|
11
|
-
).requiredOption("-o, --out <dir>", "directory to write PNGs into").option("
|
|
11
|
+
).requiredOption("-o, --out <dir>", "directory to write PNGs into").option("--only <screen>", "shoot one screen instead of every screen").option("--list", "print the screens the command offers, and stop").option("--cols <n>", "terminal columns", "110").option("--rows <n>", "terminal rows", "32").option("--settle <ms>", "how long the screen must hold still", "350").option("--keys <sequence>", "keystrokes to send once the screen has drawn").option(
|
|
12
12
|
"--font <family>",
|
|
13
13
|
"font to render with; needs Nerd Font coverage for TUI icons",
|
|
14
14
|
DEFAULT_FONT
|
|
@@ -37,5 +37,10 @@ if (options.list) {
|
|
|
37
37
|
console.log(listScreens(command, args).join("\n"));
|
|
38
38
|
process.exit(0);
|
|
39
39
|
}
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
try {
|
|
41
|
+
const written = options.only ? [await shootScreen(options.only, shoot)] : await shootAll(shoot);
|
|
42
|
+
for (const path of written) console.log(path);
|
|
43
|
+
} catch (error) {
|
|
44
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
45
|
+
process.exit(1);
|
|
46
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -38,7 +38,8 @@ type ShootOptions = CaptureOptions & RenderOptions & {
|
|
|
38
38
|
/** How many screens to shoot at once. Defaults to the core count. */
|
|
39
39
|
concurrency?: number;
|
|
40
40
|
};
|
|
41
|
+
declare const MANAGED_FLAGS: readonly ["--screen", "--mock"];
|
|
41
42
|
declare const shootScreen: (screen: string, { command, args, out, mock, ...rest }: ShootOptions) => Promise<string>;
|
|
42
43
|
declare const shootAll: (options: ShootOptions) => Promise<string[]>;
|
|
43
44
|
|
|
44
|
-
export { type CaptureOptions, DEFAULT_FONT, type RenderOptions, type ShootOptions, capture, listScreens, shootAll, shootScreen, toImage };
|
|
45
|
+
export { type CaptureOptions, DEFAULT_FONT, MANAGED_FLAGS, type RenderOptions, type ShootOptions, capture, listScreens, shootAll, shootScreen, toImage };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { DEFAULT_FONT, capture, listScreens, shootAll, shootScreen, toImage } from './chunk-
|
|
1
|
+
export { DEFAULT_FONT, MANAGED_FLAGS, capture, listScreens, shootAll, shootScreen, toImage } from './chunk-NTFITNMX.js';
|