MCPcopy Create free account
hub / github.com/IgorWarzocha/howcode / NodePtyProcess

Class NodePtyProcess

desktop/terminal/node-pty.ts:3–42  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1import type { PtyAdapter, PtyExitEvent, PtyProcess, PtySpawnInput } from './types.ts'
2
3class 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
44export const nodePtyAdapter: PtyAdapter = {
45 name: 'node-pty',

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected