-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinteractive.ts
More file actions
46 lines (34 loc) · 1.15 KB
/
Copy pathinteractive.ts
File metadata and controls
46 lines (34 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { TerminalManager } from "@termwright/core";
async function main() {
const manager = TerminalManager;
// Spawn a terminal session
const session = manager.spawn({
cols: 80,
rows: 24,
});
console.log(`Session created: ${session.id}`);
// Write directly to the terminal
session.write("echo 'Starting interactive demo'\n");
await new Promise((resolve) => setTimeout(resolve, 500));
// Read the output
let output = session.readOutput();
console.log("Output after echo:", output);
// Start a Python REPL
session.write("python3\n");
await session.waitForPattern(/>>>/, { timeout: 5000 });
console.log("Python REPL started");
// Execute some Python code
session.write("import sys\n");
await new Promise((resolve) => setTimeout(resolve, 200));
session.write("print(sys.version)\n");
await new Promise((resolve) => setTimeout(resolve, 500));
output = session.readOutput();
console.log("Python version:", output);
// Exit Python
session.write("exit()\n");
await new Promise((resolve) => setTimeout(resolve, 500));
// Clean up
session.destroy();
console.log("Session destroyed");
}
main().catch(console.error);