testingterm 0.0.6 → 0.0.7

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/AGENT-DOCS.md CHANGED
@@ -36,7 +36,7 @@ Every terminal also listens on a unix socket and is listed by `testingterm ls`,
36
36
  ```ts
37
37
  launch(command?: string | string[] | LaunchOptions, options?: LaunchOptions): Terminal
38
38
 
39
- terminal.screen() / text() / scrollback() / styles() / info()
39
+ terminal.screen() / text() / scrollback() / styles() / info() / clipboard()
40
40
  terminal.type(text, { delay }) / press(keys, { count }) / paste(text)
41
41
  terminal.click(point, { button, count, modifiers }) / dblclick / move / down / up / drag(from, to) / wheel(lines, at?)
42
42
  terminal.getByText(text | RegExp, { exact }) -> Locator: first() last() nth(i) all() count() box() waitFor() click() hover()
@@ -47,12 +47,13 @@ terminal.pixels({ region: { x, y, w, h }, cursor }) -> { x, y, width, height, rg
47
47
  terminal.startRecording({ path, fps }) / stopRecording()
48
48
  terminal.startProfile({ path }) / stopProfile()
49
49
  terminal.resize(cols, rows) / signal(name) / focus(bool) / scroll(lines)
50
+ terminal.setClipboard(text) (OSC 52 reads need capabilities: { clipboardRead: true })
50
51
  terminal.setTheme("Dracula" | { base, background, foreground, cursor, cursorText, palette })
51
52
  themes (every bundled Ghostty theme name)
52
53
  terminal.verify(statement, { agent, model, effort, interact, timeout, artifacts, soft }) experimental
53
54
  terminal.close() -> { video?, profile? }
54
55
 
55
- expect(terminal).toHaveText / toHaveScreen / toHaveTitle / toHaveCursorAt / toHaveExited({ code }) (.not works)
56
+ expect(terminal).toHaveText / toHaveScreen / toHaveTitle / toHaveClipboard / toHaveCursorAt / toHaveExited({ code }) (.not works)
56
57
  expect(locator).toBeVisible / toHaveCount
57
58
  expect(value).toBe / toEqual / toBeTruthy / toContain / toMatch / toBeGreaterThan / toBeLessThan
58
59
 
@@ -9,6 +9,7 @@ var FULL = {
9
9
  kittyKeyboard: true,
10
10
  kittyGraphics: true,
11
11
  clipboard: true,
12
+ clipboardRead: false,
12
13
  hyperlinks: true,
13
14
  title: true,
14
15
  graphemes: true
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  resolveCapabilities,
3
3
  syncTheme
4
- } from "./chunk-INTJPVJZ.js";
4
+ } from "./chunk-BBJJJ76S.js";
5
5
  import {
6
6
  EngineError,
7
7
  newId,
@@ -331,6 +331,16 @@ var Terminal = class _Terminal {
331
331
  return (await this.screen()).text;
332
332
  }
333
333
  // fixme: placeholder copy
334
+ /** What the program last copied with OSC 52 (or what {@link setClipboard} put there), or null if nothing was copied. */
335
+ async clipboard() {
336
+ return (await this.connection.request("clipboard")).text;
337
+ }
338
+ // fixme: placeholder copy
339
+ /** Put text on the terminal's in-memory clipboard, for programs that read it with an OSC 52 query (needs `capabilities: { clipboardRead: true }`). */
340
+ async setClipboard(text) {
341
+ await this.act("clipboard", { text }, `set clipboard to ${text.length} chars`);
342
+ }
343
+ // fixme: placeholder copy
334
344
  /** Every line the program printed, including lines scrolled off the top. */
335
345
  async scrollback() {
336
346
  return (await this.connection.request("scrollback")).text;
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  resolveCapabilities,
3
3
  syncTheme
4
- } from "./chunk-INTJPVJZ.js";
4
+ } from "./chunk-BBJJJ76S.js";
5
5
  import {
6
6
  DESCRIBE_HEADER,
7
7
  connectSocket,
@@ -74,6 +74,7 @@ var FEATURES = {
74
74
  "kitty-keyboard": "kittyKeyboard",
75
75
  "kitty-graphics": "kittyGraphics",
76
76
  clipboard: "clipboard",
77
+ "clipboard-read": "clipboardRead",
77
78
  hyperlinks: "hyperlinks",
78
79
  title: "title",
79
80
  graphemes: "graphemes"
@@ -243,6 +244,16 @@ async function screenCommand(args) {
243
244
  ${screen.text}`);
244
245
  return 0;
245
246
  }
247
+ async function clipboardCommand(args) {
248
+ const json = args.flag("--json");
249
+ const values = args.positional();
250
+ const set = values.length > 0;
251
+ const reply = await call(args, "clipboard", set ? { text: unescape(values.join(" ")) } : {});
252
+ const text = reply.text;
253
+ if (json) print(JSON.stringify(text));
254
+ else if (!set && text !== null) print(text.replace(/[\x00-\x08\x0b-\x1f\x7f-\x9f]/g, (c) => `\\x${c.charCodeAt(0).toString(16).padStart(2, "0")}`));
255
+ return text === null ? 1 : 0;
256
+ }
246
257
  async function scrollbackCommand(args) {
247
258
  args.positional();
248
259
  print(String((await call(args, "scrollback")).text ?? ""));
@@ -513,6 +524,7 @@ var COMMANDS = {
513
524
  ls: lsCommand,
514
525
  screen: screenCommand,
515
526
  scrollback: scrollbackCommand,
527
+ clipboard: clipboardCommand,
516
528
  find: findCommand,
517
529
  type: typeCommand,
518
530
  press: pressCommand,
@@ -58,7 +58,8 @@ Options:
58
58
  bracketed-paste, focus-events, synchronized-output,
59
59
  alternate-screen, kitty-keyboard, kitty-graphics,
60
60
  clipboard, hyperlinks, title, graphemes
61
- --enable <features> Turn features back on after a preset
61
+ --enable <features> Turn features back on after a preset, or turn on
62
+ clipboard-read (answer OSC 52 read queries)
62
63
  --colors <n> truecolor, 256, 16, 8 or none
63
64
  --term <name> The TERM the program sees
64
65
  --json Print the terminal's details as JSON
@@ -97,6 +98,17 @@ Options:
97
98
  usage: "testingterm scrollback [--id <id>]",
98
99
  body: ""
99
100
  },
101
+ clipboard: {
102
+ summary: "Print what the program copied with OSC 52, or set the clipboard",
103
+ usage: "testingterm clipboard [--id <id>] [text] [--json]",
104
+ body: `
105
+ Without text, prints the terminal's in-memory clipboard: the last OSC 52 copy,
106
+ with control characters shown as \\xNN (--json prints the exact value).
107
+ Exits 1 when nothing was copied. With text, puts it on the clipboard for
108
+ programs that read it with an OSC 52 query (start them with
109
+ --enable clipboard-read). The system clipboard is never touched.
110
+ `
111
+ },
100
112
  find: {
101
113
  summary: "Show where text is on screen, in cells and screenshot pixels",
102
114
  usage: "testingterm find [--id <id>] <text> [--regex]",
@@ -2,8 +2,8 @@ import {
2
2
  defaultWorkers,
3
3
  evalFile,
4
4
  runFiles
5
- } from "./chunk-Q7U4D2YJ.js";
6
- import "./chunk-INTJPVJZ.js";
5
+ } from "./chunk-KMQVWEOE.js";
6
+ import "./chunk-BBJJJ76S.js";
7
7
  import "./chunk-FQASQ43D.js";
8
8
  import {
9
9
  settings
package/dist/cli/main.js CHANGED
@@ -6,7 +6,7 @@ module.enableCompileCache?.();
6
6
  var argv = process.argv.slice(2);
7
7
  var command = argv[0];
8
8
  async function main() {
9
- const { commandHelp, rootHelp } = await import("../chunks/help-LRGKDAA6.js");
9
+ const { commandHelp, rootHelp } = await import("../chunks/help-LF55GGKK.js");
10
10
  if (!command || command === "help" || command === "--help" || command === "-h") {
11
11
  const topic = command === "help" ? argv[1] : void 0;
12
12
  process.stdout.write(topic && commandHelp(topic) || rootHelp());
@@ -36,7 +36,7 @@ async function main() {
36
36
  const args = new Args(rest);
37
37
  switch (command) {
38
38
  case "run":
39
- return await (await import("../chunks/run-X6BLV7F7.js")).runCommand(args);
39
+ return await (await import("../chunks/run-U7674YL4.js")).runCommand(args);
40
40
  case "setup":
41
41
  return await (await import("../chunks/setup-WIZULKES.js")).setupCommand(args);
42
42
  case "upgrade":
@@ -44,7 +44,7 @@ async function main() {
44
44
  case "verify":
45
45
  return await (await import("../chunks/verify-7WDJYYPZ.js")).verifyCommand(args);
46
46
  default: {
47
- const commands = await import("../chunks/commands-QVHQORTJ.js");
47
+ const commands = await import("../chunks/commands-BCFC4GFT.js");
48
48
  const handler = commands.COMMANDS[command];
49
49
  if (!handler) {
50
50
  process.stderr.write(`testingterm: unknown command ${command}
package/dist/expect.d.ts CHANGED
@@ -19,6 +19,10 @@ export interface TerminalAssertions {
19
19
  toHaveTitle(title: TextQuery, options?: {
20
20
  timeout?: number;
21
21
  }): Promise<void>;
22
+ /** Waits until the program has copied exactly `text` with OSC 52, or something matching the regex. */
23
+ toHaveClipboard(text: TextQuery, options?: {
24
+ timeout?: number;
25
+ }): Promise<void>;
22
26
  /** Waits until the cursor is at the cell. */
23
27
  toHaveCursorAt(cell: {
24
28
  col: number;
package/dist/index.js CHANGED
@@ -4,10 +4,10 @@ import {
4
4
  Terminal,
5
5
  normalizeLaunch,
6
6
  test
7
- } from "./chunks/chunk-Q7U4D2YJ.js";
7
+ } from "./chunks/chunk-KMQVWEOE.js";
8
8
  import {
9
9
  CAPABILITY_PRESETS
10
- } from "./chunks/chunk-INTJPVJZ.js";
10
+ } from "./chunks/chunk-BBJJJ76S.js";
11
11
  import {
12
12
  EngineError
13
13
  } from "./chunks/chunk-FQASQ43D.js";
@@ -44,7 +44,9 @@ screen:
44
44
  ${excerpt(screen)}`, screen);
45
45
  }
46
46
  function matches(text, query) {
47
- return query instanceof RegExp ? query.test(text) : text.includes(query);
47
+ if (!(query instanceof RegExp)) return text.includes(query);
48
+ query.lastIndex = 0;
49
+ return query.test(text);
48
50
  }
49
51
  async function poll(check, timeout) {
50
52
  const deadline = Date.now() + timeout;
@@ -98,6 +100,16 @@ ${expected}`, await terminal.text());
98
100
  }, timeout);
99
101
  if (!ok) fail(`expected the title ${negated ? "not " : ""}to match ${show(title)}, but it is ${JSON.stringify(last)}`);
100
102
  },
103
+ async toHaveClipboard(text, options) {
104
+ const timeout = timeoutOf(options);
105
+ let last = null;
106
+ const ok = await poll(async () => {
107
+ last = await terminal.clipboard();
108
+ const hit = last !== null && (text instanceof RegExp ? matches(last, text) : last === text);
109
+ return hit !== negated;
110
+ }, timeout);
111
+ if (!ok) fail(`expected the clipboard ${negated ? "not " : ""}to be ${show(text)}, but it is ${last === null ? "empty (nothing copied)" : JSON.stringify(last)}`);
112
+ },
101
113
  async toHaveCursorAt(cell, options) {
102
114
  const timeout = timeoutOf(options);
103
115
  let last = null;
@@ -34,6 +34,10 @@ export declare class Terminal {
34
34
  screen(): Promise<Screen>;
35
35
  /** The visible screen as plain text. */
36
36
  text(): Promise<string>;
37
+ /** What the program last copied with OSC 52 (or what {@link setClipboard} put there), or null if nothing was copied. */
38
+ clipboard(): Promise<string | null>;
39
+ /** Put text on the terminal's in-memory clipboard, for programs that read it with an OSC 52 query (needs `capabilities: { clipboardRead: true }`). */
40
+ setClipboard(text: string): Promise<void>;
37
41
  /** Every line the program printed, including lines scrolled off the top. */
38
42
  scrollback(): Promise<string>;
39
43
  /** The screen as rows of styled spans with colors and attributes, for checking how text looks. */
package/dist/types.d.ts CHANGED
@@ -46,8 +46,10 @@ export interface Capabilities {
46
46
  alternateScreen?: boolean;
47
47
  kittyKeyboard?: boolean;
48
48
  kittyGraphics?: boolean;
49
- /** OSC 52 clipboard writes. */
49
+ /** OSC 52 clipboard writes. They go to the terminal's own in-memory clipboard, never the system one. */
50
50
  clipboard?: boolean;
51
+ /** Answer OSC 52 read queries with the in-memory clipboard. Default: false, like terminals that refuse reads (queries get no reply). */
52
+ clipboardRead?: boolean;
51
53
  /** OSC 8 links. */
52
54
  hyperlinks?: boolean;
53
55
  /** Setting the window title. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "testingterm",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "Test terminal apps: drive a real terminal, read its state, and capture screenshots, videos and profiles",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -35,9 +35,9 @@
35
35
  "zod": "^4.6.7"
36
36
  },
37
37
  "optionalDependencies": {
38
- "@zenbu-labs/testingterm-darwin-arm64": "0.0.6",
39
- "@zenbu-labs/testingterm-darwin-x64": "0.0.6",
40
- "@zenbu-labs/testingterm-linux-x64": "0.0.6",
41
- "@zenbu-labs/testingterm-linux-arm64": "0.0.6"
38
+ "@zenbu-labs/testingterm-darwin-arm64": "0.0.7",
39
+ "@zenbu-labs/testingterm-darwin-x64": "0.0.7",
40
+ "@zenbu-labs/testingterm-linux-x64": "0.0.7",
41
+ "@zenbu-labs/testingterm-linux-arm64": "0.0.7"
42
42
  }
43
43
  }
@@ -67,6 +67,7 @@ at a time, reading the screen after each step, like a person would.
67
67
  testingterm new --name app -- npm run dev # prints the terminal id
68
68
  testingterm wait --text "ready"
69
69
  testingterm screen # text, cursor, title, modes
70
+ testingterm clipboard # what the program copied (OSC 52)
70
71
  testingterm press Down Down Enter
71
72
  testingterm type "hello\n"
72
73
  testingterm click --text "Save" # waits for the text, clicks its center