xterm: DECSCUSR cursor shapes; block cursor shows the character
CSI Ps SP q is stored as Terminal.cursorShape / cursorShapeBlinks (Ps 0 returns to the view's configured cursorType; RIS clears it) and reported by DECRQSS " q". The painter draws the requested shape. A focused block cursor now redraws the character under it in the background colour instead of hiding it, spans both columns of a wide character, and the underline and bar cursors are drawn in the cursor's cell (they were drawn at the top of the terminal). Blinking is stored but not animated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+45
-13
@@ -86,42 +86,74 @@ class TerminalPainter {
|
||||
}
|
||||
|
||||
/// Paints the cursor based on the current cursor type.
|
||||
///
|
||||
/// [cell] is the cell under the cursor: a focused block cursor draws its
|
||||
/// character again in the background colour, so the character stays
|
||||
/// readable, and a cursor over a wide character spans both columns.
|
||||
void paintCursor(
|
||||
Canvas canvas,
|
||||
Offset offset, {
|
||||
required TerminalCursorType cursorType,
|
||||
bool hasFocus = true,
|
||||
CellData? cell,
|
||||
}) {
|
||||
final paint = Paint()
|
||||
..color = _theme.cursor
|
||||
..strokeWidth = 1;
|
||||
final wide = cell != null && cell.content >> CellContent.widthShift == 2;
|
||||
final size = wide ? Size(_cellSize.width * 2, _cellSize.height) : _cellSize;
|
||||
final thickness = cursorThickness;
|
||||
final paint = Paint()..color = _theme.cursor;
|
||||
|
||||
if (!hasFocus) {
|
||||
paint.style = PaintingStyle.stroke;
|
||||
canvas.drawRect(offset & _cellSize, paint);
|
||||
paint
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = 1;
|
||||
canvas.drawRect((offset & size).deflate(0.5), paint);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (cursorType) {
|
||||
case TerminalCursorType.block:
|
||||
paint.style = PaintingStyle.fill;
|
||||
canvas.drawRect(offset & _cellSize, paint);
|
||||
canvas.drawRect(offset & size, paint);
|
||||
if (cell != null) {
|
||||
paintCellForeground(canvas, offset, _underCursor(cell));
|
||||
}
|
||||
return;
|
||||
case TerminalCursorType.underline:
|
||||
return canvas.drawLine(
|
||||
Offset(offset.dx, _cellSize.height - 1),
|
||||
Offset(offset.dx + _cellSize.width, _cellSize.height - 1),
|
||||
canvas.drawRect(
|
||||
Rect.fromLTWH(
|
||||
offset.dx,
|
||||
offset.dy + size.height - thickness,
|
||||
size.width,
|
||||
thickness,
|
||||
),
|
||||
paint,
|
||||
);
|
||||
return;
|
||||
case TerminalCursorType.verticalBar:
|
||||
return canvas.drawLine(
|
||||
Offset(offset.dx, 0),
|
||||
Offset(offset.dx, _cellSize.height),
|
||||
canvas.drawRect(
|
||||
Rect.fromLTWH(offset.dx, offset.dy, thickness, size.height),
|
||||
paint,
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/// The width of an underline or bar cursor: a tenth of the line height,
|
||||
/// at least one pixel.
|
||||
double get cursorThickness =>
|
||||
(_cellSize.height / 10).roundToDouble().clamp(1.0, double.infinity);
|
||||
|
||||
/// [cell] as drawn on top of a block cursor: in the background colour,
|
||||
/// without inverse.
|
||||
CellData _underCursor(CellData cell) {
|
||||
final background = _theme.background.toARGB32() & CellColor.valueMask;
|
||||
return CellData(
|
||||
foreground: CellColor.rgb | background,
|
||||
background: 0,
|
||||
flags: cell.flags & ~CellFlags.inverse,
|
||||
content: cell.content,
|
||||
);
|
||||
}
|
||||
|
||||
@pragma('vm:prefer-inline')
|
||||
void paintHighlight(Canvas canvas, Offset offset, int length, Color color) {
|
||||
final endOffset =
|
||||
|
||||
Reference in New Issue
Block a user