| 1 | import type { PtyAdapter, PtyExitEvent, PtyProcess, PtySpawnInput } from './types.ts' |
| 2 | |
| 3 | class NodePtyProcess implements PtyProcess { |
| 4 | private readonly process: import('node-pty').IPty |
| 5 | |
| 6 | constructor(process: import('node-pty').IPty) { |
| 7 | this.process = process |
| 8 | } |
| 9 | |
| 10 | get pid() { |
| 11 | return this.process.pid |
| 12 | } |
| 13 | |
| 14 | write(data: string) { |
| 15 | this.process.write(data) |
| 16 | } |
| 17 | |
| 18 | resize(cols: number, rows: number) { |
| 19 | this.process.resize(cols, rows) |
| 20 | } |
| 21 | |
| 22 | kill(signal?: string | undefined) { |
| 23 | this.process.kill(signal) |
| 24 | } |
| 25 | |
| 26 | onData(callback: (data: string) => void) { |
| 27 | const disposable = this.process.onData(callback) |
| 28 | return () => { |
| 29 | disposable.dispose() |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | onExit(callback: (event: PtyExitEvent) => void) { |
| 34 | const disposable = this.process.onExit((event) => { |
| 35 | callback({ exitCode: event.exitCode, signal: event.signal ?? null }) |
| 36 | }) |
| 37 | |
| 38 | return () => { |
| 39 | disposable.dispose() |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | export const nodePtyAdapter: PtyAdapter = { |
| 45 | name: 'node-pty', |
nothing calls this directly
no outgoing calls
no test coverage detected