forked from owid/owid-grapher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProgressStream.ts
36 lines (28 loc) · 939 Bytes
/
ProgressStream.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { WriteStream } from "tty"
// Wrap stderr before passing it to ProgressBar so we can save all writes
// and replay them at the end of the bake. Without this the progress bar class
// works fine, but there is no way to show the summary once the job is complete.
export class ProgressStream implements Partial<WriteStream> {
private wrappedStream: WriteStream
constructor(wrap: WriteStream) {
this.wrappedStream = wrap
}
isTTY = true
private allWrites: string[] = []
replay() {
console.log(this.allWrites.join(""))
}
write(buffer: string) {
this.allWrites.push(buffer)
return this.wrappedStream.write(buffer)
}
cursorTo(index: number) {
return this.wrappedStream.cursorTo(index)
}
clearLine(direction: 1) {
return this.wrappedStream.clearLine(direction)
}
get columns() {
return this.wrappedStream.columns
}
}