terminalCursor property

Cursor? get terminalCursor

Returns a Cursor for rendering a real cursor in a TUI program. This requires that useVirtualCursor is set to false.

Implementation

Cursor? get terminalCursor {
  if (useVirtualCursor || !_focused) return null;

  final promptWidth = stringWidth(prompt);

  if (multiline) {
    final (cursorRow, cursorCol) = _cursorRowCol();
    // Compute display x: count cell widths of chars before cursor on this line.
    final lines = _getWrappedLines();
    final line = lines[cursorRow.clamp(0, lines.length - 1)];
    var xOffset = promptWidth;
    for (
      var i = line.start;
      i < line.start + cursorCol && i < line.end;
      i++
    ) {
      if (_value[i] != '\n') {
        xOffset += runeWidth(uni.firstCodePoint(_value[i]));
      }
    }
    final yOffset = cursorRow - _scrollRow;

    return Cursor(
      position: Position(xOffset, yOffset),
      color: styles.cursor.color,
      shape: styles.cursor.shape,
      blink: styles.cursor.blink,
    );
  }

  var xOffset = _pos - _offset + promptWidth;
  if (width > 0) {
    xOffset = math.min(xOffset, width + promptWidth);
  }

  return Cursor(
    position: Position(xOffset, 0),
    color: styles.cursor.color,
    shape: styles.cursor.shape,
    blink: styles.cursor.blink,
  );
}