(options: { stdin: ReadableOrWritable; stdout: ReadableOrWritable; stderr: ReadableOrWritable; preserveAnsi?: boolean })
| 15 | private preserveAnsi?: boolean |
| 16 | |
| 17 | constructor(options: { stdin: ReadableOrWritable; stdout: ReadableOrWritable; stderr: ReadableOrWritable; preserveAnsi?: boolean }) { |
| 18 | this.stdin = options.stdin |
| 19 | this.stdin = options.stdin |
| 20 | this.preserveAnsi = options.preserveAnsi |
| 21 | |
| 22 | for (const source of (['stdout', 'stderr'] as const)) { |
| 23 | const stream = options[source] |
| 24 | |
| 25 | if ((stream as Readable).readable) { |
| 26 | stream.on('data', (data) => { |
| 27 | this.capture(source, data) |
| 28 | }) |
| 29 | } |
| 30 | else if (isWritable(stream)) { |
| 31 | const original = stream.write.bind(stream) |
| 32 | |
| 33 | // @ts-expect-error -- Is there a better way to detect when a Writable is being written into? |
| 34 | stream.write = (data, encoding, callback) => { |
| 35 | this.capture(source, data) |
| 36 | return original(data, encoding, callback) |
| 37 | } |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | private capture(source: Source, data: any) { |
| 43 | const msg = this.preserveAnsi ? data.toString() : stripVTControlCharacters(data.toString()) |
nothing calls this directly
no test coverage detected