@kud/cli-shot 0.1.2 → 0.2.1

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 CHANGED
@@ -39,28 +39,38 @@ 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. That separation matters: it
43
- lets the driven CLI have its own `--mock` or `--screen` without colliding with
44
- cli-shot's flags.
42
+ Everything after `--` is the command being driven, so its own flags stay clear
43
+ of cli-shot's.
44
+
45
+ cli-shot adds `--mock` and `--screen` to that command, but only where you
46
+ haven't. Anything you pass wins:
47
+
48
+ ```sh
49
+ cli-shot --out shots -- pcloud --screen sync # shoots Sync, writes sync.png
50
+ cli-shot --out shots --only sync -- pcloud # the same thing, said from here
51
+ ```
52
+
53
+ Naming a screen yourself is already an answer to "which one", so cli-shot skips
54
+ the discovery loop and takes the filename from your value.
45
55
 
46
56
  ```sh
47
- cli-shot --out shots --screen sync -- pcloud # one screen
57
+ cli-shot --out shots --only sync -- pcloud # one screen
48
58
  cli-shot --out shots --list -- pcloud # what screens exist
49
59
  cli-shot --out shots --keys $'jjj\r' -- pcloud # drive deeper first
50
60
  cli-shot --out shots --no-mock -- pcloud # real data (careful)
51
61
  ```
52
62
 
53
- | flag | |
54
- | --------------------- | ----------------------------------------------------- |
55
- | `-o, --out <dir>` | directory to write PNGs into |
56
- | `-s, --screen <name>` | shoot one screen instead of every screen |
57
- | `--list` | print the screens the command offers, and stop |
58
- | `--cols` / `--rows` | terminal size (default 110×32) |
59
- | `--settle <ms>` | how long the screen must hold still (default 350) |
60
- | `--jobs <n>` | screens shot at once; defaults to the core count |
61
- | `--keys <sequence>` | keystrokes sent once the screen has drawn |
62
- | `--font <family>` | font to render with; defaults to a Nerd Font |
63
- | `--no-mock` | drive real data instead of fixtures |
63
+ | flag | |
64
+ | ------------------- | ------------------------------------------------- |
65
+ | `-o, --out <dir>` | directory to write PNGs into |
66
+ | `--only <screen>` | shoot one screen instead of every screen |
67
+ | `--list` | print the screens the command offers, and stop |
68
+ | `--cols` / `--rows` | terminal size (default 110×32) |
69
+ | `--settle <ms>` | how long the screen must hold still (default 350) |
70
+ | `--jobs <n>` | screens shot at once; defaults to the core count |
71
+ | `--keys <sequence>` | keystrokes sent once the screen has drawn |
72
+ | `--font <family>` | font to render with; defaults to a Nerd Font |
73
+ | `--no-mock` | drive real data instead of fixtures |
64
74
 
65
75
  ## The contract
66
76
 
@@ -161,7 +161,15 @@ var toImage = (ansi, output, { font = DEFAULT_FONT, freezeArgs = [] } = {}) => {
161
161
  };
162
162
 
163
163
  // src/index.ts
164
- var screenArgs = (args, screen, mock) => [...args, ...mock ? ["--mock"] : [], "--screen", screen];
164
+ var drivenScreen = (args) => {
165
+ const at = args.indexOf("--screen");
166
+ return at === -1 ? void 0 : args[at + 1];
167
+ };
168
+ var screenArgs = (args, screen, mock) => [
169
+ ...args,
170
+ ...mock && !args.includes("--mock") ? ["--mock"] : [],
171
+ ...drivenScreen(args) === void 0 ? ["--screen", screen] : []
172
+ ];
165
173
  var shootScreen = async (screen, { command, args = [], out, mock = true, ...rest }) => {
166
174
  const ansi = await capture(command, screenArgs(args, screen, mock), rest);
167
175
  return toImage(ansi, join(out, `${screen}.png`), rest);
@@ -181,6 +189,8 @@ var pool = async (items, limit, run) => {
181
189
  return results;
182
190
  };
183
191
  var shootAll = async (options) => {
192
+ const pinned = drivenScreen(options.args ?? []);
193
+ if (pinned) return [await shootScreen(pinned, options)];
184
194
  const screens = listScreens(options.command, options.args ?? []);
185
195
  return pool(
186
196
  screens,
@@ -189,4 +199,4 @@ var shootAll = async (options) => {
189
199
  );
190
200
  };
191
201
 
192
- export { DEFAULT_FONT, capture, listScreens, shootAll, shootScreen, toImage };
202
+ export { DEFAULT_FONT, capture, drivenScreen, 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-RT6Y4NTY.js';
2
+ import { DEFAULT_FONT, listScreens, shootScreen, shootAll } from './chunk-TKCXCDP2.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("-s, --screen <name>", "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(
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
- var written = options.screen ? [await shootScreen(options.screen, shoot)] : await shootAll(shoot);
41
- for (const path of written) console.log(path);
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 drivenScreen: (args: readonly string[]) => string | undefined;
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, type RenderOptions, type ShootOptions, capture, drivenScreen, listScreens, shootAll, shootScreen, toImage };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export { DEFAULT_FONT, capture, listScreens, shootAll, shootScreen, toImage } from './chunk-RT6Y4NTY.js';
1
+ export { DEFAULT_FONT, capture, drivenScreen, listScreens, shootAll, shootScreen, toImage } from './chunk-TKCXCDP2.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kud/cli-shot",
3
- "version": "0.1.2",
3
+ "version": "0.2.1",
4
4
  "type": "module",
5
5
  "description": "Automatic screenshots of interactive CLIs — pty capture, terminal emulation, PNG out",
6
6
  "license": "MIT",