| ... | @@ -2,10 +2,23 @@ | ... | @@ -2,10 +2,23 @@ |
| 2 | | 2 | |
| 3 | import * as Effect from "effect/Effect"; | 3 | import * as Effect from "effect/Effect"; |
| 4 | import * as Layer from "effect/Layer"; | 4 | import * as Layer from "effect/Layer"; |
| | 5 | import * as Schema from "effect/Schema"; |
| 5 | import { HostProcessPlatform } from "@t3tools/shared/hostProcess"; | 6 | import { HostProcessPlatform } from "@t3tools/shared/hostProcess"; |
| 6 | | 7 | |
| 7 | import * as PtyAdapter from "./PtyAdapter.ts"; | 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 | class BunPtyProcess implements PtyAdapter.PtyProcess { | 22 | class BunPtyProcess implements PtyAdapter.PtyProcess { |
| 10 | private readonly dataListeners = new Set<(data: string) => void>(); | 23 | private readonly dataListeners = new Set<(data: string) => void>(); |
| 11 | private readonly exitListeners = new Set<(event: PtyAdapter.PtyExitEvent) => void>(); | 24 | private readonly exitListeners = new Set<(event: PtyAdapter.PtyExitEvent) => void>(); |
| ... | @@ -33,14 +46,14 @@ class BunPtyProcess implements PtyAdapter.PtyProcess { | ... | @@ -33,14 +46,14 @@ class BunPtyProcess implements PtyAdapter.PtyProcess { |
| 33 | | 46 | |
| 34 | write(data: string): void { | 47 | write(data: string): void { |
| 35 | if (!this.process.terminal) { | 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 | this.process.terminal.write(data); | 51 | this.process.terminal.write(data); |
| 39 | } | 52 | } |
| 40 | | 53 | |
| 41 | resize(cols: number, rows: number): void { | 54 | resize(cols: number, rows: number): void { |
| 42 | if (!this.process.terminal?.resize) { | 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 | this.process.terminal.resize(cols, rows); | 58 | this.process.terminal.resize(cols, rows); |
| 46 | } | 59 | } |