| ... | ... | @@ -2,10 +2,23 @@ |
| 2 | 2 | |
| 3 | 3 | import * as Effect from "effect/Effect"; |
| 4 | 4 | import * as Layer from "effect/Layer"; |
| 5 | import * as Schema from "effect/Schema"; |
| 5 | 6 | import { HostProcessPlatform } from "@t3tools/shared/hostProcess"; |
| 6 | 7 | |
| 7 | 8 | import * as PtyAdapter from "./PtyAdapter.ts"; |
| 8 | 9 | |
| 10 | export class BunPtyOperationUnavailableError extends Schema.TaggedErrorClass<BunPtyOperationUnavailableError>()( |
| 11 | "BunPtyOperationUnavailableError", |
| 12 | { |
| 13 | operation: Schema.Literals(["write", "resize"]), |
| 14 | pid: Schema.Number, |
| 15 | }, |
| 16 | ) { |
| 17 | override get message(): string { |
| 18 | return `Bun PTY ${this.operation} is unavailable for process ${this.pid}.`; |
| 19 | } |
| 20 | } |
| 21 | |
| 9 | 22 | class BunPtyProcess implements PtyAdapter.PtyProcess { |
| 10 | 23 | private readonly dataListeners = new Set<(data: string) => void>(); |
| 11 | 24 | private readonly exitListeners = new Set<(event: PtyAdapter.PtyExitEvent) => void>(); |
| ... | ... | @@ -33,14 +46,14 @@ class BunPtyProcess implements PtyAdapter.PtyProcess { |
| 33 | 46 | |
| 34 | 47 | write(data: string): void { |
| 35 | 48 | if (!this.process.terminal) { |
| 36 | | throw new Error("Bun PTY terminal handle is unavailable"); |
| 49 | throw new BunPtyOperationUnavailableError({ operation: "write", pid: this.pid }); |
| 37 | 50 | } |
| 38 | 51 | this.process.terminal.write(data); |
| 39 | 52 | } |
| 40 | 53 | |
| 41 | 54 | resize(cols: number, rows: number): void { |
| 42 | 55 | if (!this.process.terminal?.resize) { |
| 43 | | throw new Error("Bun PTY resize is unavailable"); |
| 56 | throw new BunPtyOperationUnavailableError({ operation: "resize", pid: this.pid }); |
| 44 | 57 | } |
| 45 | 58 | this.process.terminal.resize(cols, rows); |
| 46 | 59 | } |