(data: string | Buffer, header: string)
| 468 | } |
| 469 | |
| 470 | public writeWithHeader(data: string | Buffer, header: string) { |
| 471 | if (!this.terminal) { // Writes after a terminal is closed |
| 472 | return; |
| 473 | } |
| 474 | if (!header || !data) { |
| 475 | this.write(data); |
| 476 | return; |
| 477 | } |
| 478 | let str: string; |
| 479 | if ((typeof data !== 'string') && !(data instanceof String)) { |
| 480 | str = data.toString('utf8'); |
| 481 | } else { |
| 482 | str = data as string; |
| 483 | } |
| 484 | if (this.cursorPos === 1) { |
| 485 | this.write(header); |
| 486 | } |
| 487 | let endsWithNl = false; |
| 488 | while (str.endsWith('\n')) { |
| 489 | str = str.substr(0, str.length - 1); |
| 490 | endsWithNl = true; |
| 491 | } |
| 492 | str = str.replace(/\n/g, '\n' + header); |
| 493 | this.write(endsWithNl ? str + '\n' : str); |
| 494 | } |
| 495 | |
| 496 | public write(data: string | Buffer) { |
| 497 | if (!this.terminal) { // Writes after a terminal is closed |
no test coverage detected