| 7 | const exec = promisify(execFile) |
| 8 | |
| 9 | function command(command: string, args: string[] = [], input?: string) { |
| 10 | return new Promise<Buffer>((resolve, reject) => { |
| 11 | const child = spawn(command, args, { stdio: [input === undefined ? "ignore" : "pipe", "pipe", "ignore"] }) |
| 12 | const output: Buffer[] = [] |
| 13 | child.on("error", reject) |
| 14 | child.stdout?.on("data", (chunk: Buffer) => output.push(chunk)) |
| 15 | child.on("close", (code) => { |
| 16 | if (code === 0) return resolve(Buffer.concat(output)) |
| 17 | reject(new Error(`${command} exited with code ${code}`)) |
| 18 | }) |
| 19 | if (input !== undefined) child.stdin?.end(input) |
| 20 | }) |
| 21 | } |
| 22 | |
| 23 | function writeOsc52(text: string) { |
| 24 | if (!process.stdout.isTTY) return |