MCPcopy Index your code
hub / github.com/nodejs/node / [kRefreshLine]

Method [kRefreshLine]

lib/internal/readline/interface.js:493–542  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

491 }
492
493 [kRefreshLine]() {
494 // line length
495 const line = this[kPrompt] + this.line;
496 const dispPos = this[kGetDisplayPos](line);
497 const lineCols = dispPos.cols;
498 const lineRows = dispPos.rows;
499
500 // cursor position
501 const cursorPos = this.getCursorPos();
502
503 // First move to the bottom of the current line, based on cursor pos
504 const prevRows = this.prevRows || 0;
505 if (prevRows > 0) {
506 moveCursor(this.output, 0, -prevRows);
507 }
508
509 // Cursor to left edge.
510 cursorTo(this.output, 0);
511 // erase data
512 clearScreenDown(this.output);
513
514 if (this[kIsMultiline]) {
515 const lines = StringPrototypeSplit(this.line, '\n');
516 // Write first line with normal prompt
517 this[kWriteToOutput](this[kPrompt] + lines[0]);
518
519 // For continuation lines, add the "|" prefix
520 for (let i = 1; i < lines.length; i++) {
521 this[kWriteToOutput](`\n${kMultilinePrompt.description}` + lines[i]);
522 }
523 } else {
524 // Write the prompt and the current buffer content.
525 this[kWriteToOutput](line);
526 }
527
528 // Force terminal to allocate a new line
529 if (lineCols === 0) {
530 this[kWriteToOutput](' ');
531 }
532
533 // Move cursor to original position.
534 cursorTo(this.output, cursorPos.cols);
535
536 const diff = lineRows - cursorPos.rows;
537 if (diff > 0) {
538 moveCursor(this.output, 0, -diff);
539 }
540
541 this.prevRows = cursorPos.rows;
542 }
543
544 /**
545 * Closes the `readline.Interface` instance.

Callers

nothing calls this directly

Calls 4

getCursorPosMethod · 0.95
moveCursorFunction · 0.85
cursorToFunction · 0.85
clearScreenDownFunction · 0.85

Tested by

no test coverage detected