height property

  1. @override
int get height
override

Returns the height of the current console window in characters.

Implementation

@override
int get height {
  if (_height == null) {
    // try using ioctl() to give us the screen size
    final height = _terminal.get_window_height();
    if (height != -1) {
      return _height = height;
    } else {
      // otherwise, fall back to the approach of setting the cursor to beyond
      // the edge of the screen and then reading back its actual position
      final originalCursor = cursorPosition.get();
      stdout.write(control_sequence_identifier +
          '999C' +
          control_sequence_identifier +
          '999B');
      final newCursor = cursorPosition.get();
      cursorPosition.update(originalCursor);
      if (newCursor != null) {
        return _height = newCursor.row;
      } else {
        // we've run out of options; terminal is unsupported
        throw Exception(
          "Couldn't retrieve window height",
        );
      }
    }
  } else {
    return _height!;
  }
}