@ian-pascoe/pi-termctrl 0.0.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.
@@ -0,0 +1,51 @@
1
+ import type { Key } from "@kitlangton/terminal-control";
2
+ import type { TerminalViewport } from "./pi-termctrl-settings.js";
3
+
4
+ /** How a Terminal's process ended, as termctrl reports it. */
5
+ export interface TerminalExit {
6
+ readonly code: number | null;
7
+ readonly signal: string | null;
8
+ }
9
+
10
+ /** One polled view of a Terminal: the visible screen plus process state. */
11
+ export interface TerminalSnapshot {
12
+ readonly screen: string;
13
+ readonly state: "running" | "exited";
14
+ readonly exit: TerminalExit | null;
15
+ /** Milliseconds since the Terminal last produced output, when termctrl knows. */
16
+ readonly idleForMs: number | null;
17
+ }
18
+
19
+ /** Launch request for one Terminal. `command` is the full argv, already wrapped in a shell. */
20
+ export interface TerminalLaunchRequest {
21
+ readonly id: string;
22
+ readonly command: readonly [string, ...string[]];
23
+ readonly cwd: string;
24
+ readonly viewport: TerminalViewport;
25
+ }
26
+
27
+ /** A running or exited Terminal inside one driver. Every call is a short driver request. */
28
+ export interface TerminalHandle {
29
+ snapshot(): Promise<TerminalSnapshot>;
30
+ /** Line-oriented output history of the current screen buffer, including the visible screen. */
31
+ logs(): Promise<string>;
32
+ type(text: string): Promise<void>;
33
+ press(keys: readonly Key[]): Promise<void>;
34
+ /** Ask termctrl to stop the Terminal and forget it. */
35
+ stop(): Promise<void>;
36
+ /** Whether the Terminal's process is known to still run. False when its pid is unknown. */
37
+ isAlive(): boolean;
38
+ /** Send SIGKILL to the Terminal's process group when termctrl does not stop it. */
39
+ kill(): void;
40
+ }
41
+
42
+ /** One termctrl driver process hosting many Terminals. */
43
+ export interface TerminalDriver {
44
+ launch(request: TerminalLaunchRequest): Promise<TerminalHandle>;
45
+ close(): Promise<void>;
46
+ }
47
+
48
+ /** Recognises the SDK errors that mean the driver child process is gone. */
49
+ export function isDriverGone(error: Error): boolean {
50
+ return /termctrl driver (?:exited|is closed)/u.test(error.message);
51
+ }