up method

String up(
  1. String buffer
)

Scroll 'up' -- Replace the user-input buffer with the contents of the previous line. ScrollbackBuffer tracks which lines are the 'current' and 'previous' lines. The up() method stores the current line buffer so that the contents will not be lost in the event the user starts typing/editing the line and then wants to review a previous line.

Implementation

String up(String buffer) {
  // Handle the case of the user tapping 'up' before there is a
  // scrollback buffer to scroll through.
  if (lineIndex == null) {
    return buffer;
  } else {
    // Only store the current line buffer once while scrolling up
    currentLineBuffer ??= buffer;
    lineIndex = lineIndex! - 1;
    lineIndex = lineIndex! < 0 ? 0 : lineIndex;
    return lineList[lineIndex!];
  }
}