aboutsummaryrefslogtreecommitdiff
path: root/editors/code/src/commands/line_buffer.ts
blob: fb5b9f7f2b2a6bb3541ea820ab3dd1125a141c9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
export class LineBuffer {
    private outBuffer: string = '';

    public processOutput(chunk: string, cb: (line: string) => void) {
        this.outBuffer += chunk;
        let eolIndex = this.outBuffer.indexOf('\n');
        while (eolIndex >= 0) {
            // line includes the EOL
            const line = this.outBuffer.slice(0, eolIndex + 1);
            cb(line);
            this.outBuffer = this.outBuffer.slice(eolIndex + 1);

            eolIndex = this.outBuffer.indexOf('\n');
        }
    }
}