@moejay/wrightty 0.1.0 → 0.1.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/dist/cli.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ /** wrightty CLI for Node.js — control terminals from the command line. */
3
+ export {};
package/dist/cli.js ADDED
@@ -0,0 +1,144 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ /** wrightty CLI for Node.js — control terminals from the command line. */
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ const terminal_1 = require("./terminal");
6
+ const args = process.argv.slice(2);
7
+ const command = args[0];
8
+ function usage() {
9
+ console.log(`wrightty-js — Playwright for terminals (Node.js)
10
+
11
+ Usage:
12
+ wrightty-js run <command> [--timeout <s>] Run a command and print output
13
+ wrightty-js read Read the terminal screen
14
+ wrightty-js send-text <text> Send raw text
15
+ wrightty-js send-keys <key> [<key>...] Send keystrokes
16
+ wrightty-js screenshot [--format svg|text] Take a screenshot
17
+ wrightty-js wait-for <pattern> [--timeout] Wait for text on screen
18
+ wrightty-js info Show server info
19
+ wrightty-js size Get terminal dimensions
20
+ wrightty-js discover Find running servers
21
+
22
+ Options:
23
+ --url <url> Server URL (default: auto-discover)
24
+ --session <id> Session ID (default: first available)
25
+ --help Show this help`);
26
+ }
27
+ function getOpt(name) {
28
+ const idx = args.indexOf(name);
29
+ return idx >= 0 && idx + 1 < args.length ? args[idx + 1] : undefined;
30
+ }
31
+ function hasFlag(name) {
32
+ return args.includes(name);
33
+ }
34
+ async function getTerminal() {
35
+ const url = getOpt("--url");
36
+ const sessionId = getOpt("--session");
37
+ return terminal_1.Terminal.connect({ url, sessionId });
38
+ }
39
+ async function main() {
40
+ if (!command || hasFlag("--help") || hasFlag("-h")) {
41
+ usage();
42
+ process.exit(0);
43
+ }
44
+ try {
45
+ switch (command) {
46
+ case "discover": {
47
+ const servers = await terminal_1.Terminal.discover();
48
+ if (servers.length === 0) {
49
+ console.log("No wrightty servers found.");
50
+ }
51
+ else {
52
+ for (const s of servers) {
53
+ console.log(` ${s.url} ${s.implementation} v${s.version}`);
54
+ }
55
+ }
56
+ break;
57
+ }
58
+ case "run": {
59
+ const cmd = args[1];
60
+ if (!cmd) {
61
+ console.error("Usage: wrightty-js run <command>");
62
+ process.exit(1);
63
+ }
64
+ const timeout = parseInt(getOpt("--timeout") ?? "30", 10) * 1000;
65
+ const term = await getTerminal();
66
+ const output = await term.run(cmd, timeout);
67
+ console.log(output);
68
+ term.close();
69
+ break;
70
+ }
71
+ case "read": {
72
+ const term = await getTerminal();
73
+ console.log(await term.readScreen());
74
+ term.close();
75
+ break;
76
+ }
77
+ case "send-text": {
78
+ const text = args[1];
79
+ if (!text) {
80
+ console.error("Usage: wrightty-js send-text <text>");
81
+ process.exit(1);
82
+ }
83
+ const term = await getTerminal();
84
+ await term.sendText(text.replace(/\\n/g, "\n"));
85
+ term.close();
86
+ break;
87
+ }
88
+ case "send-keys": {
89
+ const keys = args.slice(1).filter(k => !k.startsWith("--"));
90
+ if (keys.length === 0) {
91
+ console.error("Usage: wrightty-js send-keys <key> [...]");
92
+ process.exit(1);
93
+ }
94
+ const term = await getTerminal();
95
+ await term.sendKeys(...keys);
96
+ term.close();
97
+ break;
98
+ }
99
+ case "screenshot": {
100
+ const format = (getOpt("--format") ?? "text");
101
+ const term = await getTerminal();
102
+ const result = await term.screenshot(format);
103
+ console.log(result.data);
104
+ term.close();
105
+ break;
106
+ }
107
+ case "wait-for": {
108
+ const pattern = args[1];
109
+ if (!pattern) {
110
+ console.error("Usage: wrightty-js wait-for <pattern>");
111
+ process.exit(1);
112
+ }
113
+ const timeout = parseInt(getOpt("--timeout") ?? "30", 10) * 1000;
114
+ const term = await getTerminal();
115
+ const screen = await term.waitFor(pattern, timeout);
116
+ console.log(screen);
117
+ term.close();
118
+ break;
119
+ }
120
+ case "info": {
121
+ const term = await getTerminal();
122
+ console.log(JSON.stringify(await term.getInfo(), null, 2));
123
+ term.close();
124
+ break;
125
+ }
126
+ case "size": {
127
+ const term = await getTerminal();
128
+ const [cols, rows] = await term.getSize();
129
+ console.log(`${cols}x${rows}`);
130
+ term.close();
131
+ break;
132
+ }
133
+ default:
134
+ console.error(`Unknown command: ${command}`);
135
+ usage();
136
+ process.exit(1);
137
+ }
138
+ }
139
+ catch (err) {
140
+ console.error(`Error: ${err.message}`);
141
+ process.exit(1);
142
+ }
143
+ }
144
+ main();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moejay/wrightty",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Node.js SDK for Wrightty terminal automation protocol",
5
5
  "author": "Moe Jay",
6
6
  "homepage": "https://github.com/moejay/wrightty",
@@ -14,6 +14,9 @@
14
14
  },
15
15
  "main": "dist/index.js",
16
16
  "types": "dist/index.d.ts",
17
+ "bin": {
18
+ "wrightty-js": "dist/cli.js"
19
+ },
17
20
  "files": [
18
21
  "dist"
19
22
  ],