render method

void render(
  1. List<String> lines
)

Draws lines, replacing any previously rendered region in place.

Each entry should fit within a single terminal row so the in-place updates stay aligned; fitting the visible text to the terminal width is the responsibility of the caller (so that ANSI color codes are preserved).

Implementation

void render(final List<String> lines) {
  final buffer = StringBuffer();

  if (_renderedLineCount > 0) {
    buffer.write('\r');
    if (_renderedLineCount > 1) {
      buffer.write('$_esc[${_renderedLineCount - 1}A');
    }
    // Clear from the start of the region to the end of the screen.
    buffer.write('$_esc[0J');
  }

  for (var i = 0; i < lines.length; i++) {
    buffer.write(lines[i]);
    if (i < lines.length - 1) buffer.write('\n');
  }

  _terminal.write(buffer.toString());
  _renderedLineCount = lines.length;
}