MCPcopy Create free account
hub / github.com/Marus/cortex-debug / writeWithHeader

Method writeWithHeader

src/frontend/pty.ts:470–494  ·  view source on GitHub ↗
(data: string | Buffer, header: string)

Source from the content-addressed store, hash-verified

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

Callers 1

writeNonBinaryMethod · 0.80

Calls 2

writeMethod · 0.95
toStringMethod · 0.80

Tested by

no test coverage detected