(session: ProcessSession, input: StartCommandInput)
| 340 | } |
| 341 | |
| 342 | private async startPty(session: ProcessSession, input: StartCommandInput): Promise<void> { |
| 343 | let nodePty: typeof import("node-pty"); |
| 344 | try { |
| 345 | nodePty = await import("node-pty"); |
| 346 | } catch { |
| 347 | throw new Error("PTY support requires the optional node-pty dependency."); |
| 348 | } |
| 349 | |
| 350 | const shell = resolveShellCommand(input.command); |
| 351 | let pty: import("node-pty").IPty; |
| 352 | try { |
| 353 | pty = nodePty.spawn(shell.executable, shell.args, { |
| 354 | cwd: input.cwd, |
| 355 | env: processEnvironment(), |
| 356 | name: "xterm-256color", |
| 357 | cols: session.columns, |
| 358 | rows: session.rows, |
| 359 | }); |
| 360 | } catch (error) { |
| 361 | throw error; |
| 362 | } |
| 363 | |
| 364 | session.process = { |
| 365 | write: (data) => pty.write(data), |
| 366 | kill: (signal) => pty.kill(signal), |
| 367 | resize: (columns, rows) => pty.resize(columns, rows), |
| 368 | }; |
| 369 | pty.onData((data) => this.append(session, data)); |
| 370 | pty.onExit(({ exitCode, signal }) => { |
| 371 | this.finish(session, exitCode, signal === 0 ? undefined : String(signal)); |
| 372 | }); |
| 373 | } |
| 374 | |
| 375 | private finish(session: ProcessSession, exitCode?: number, signal?: string): void { |
| 376 | if (!session.running) return; |
no test coverage detected