Files
pipelines/app/test/third_party_xterm/paint_fixture.dart
T
alan bbb2d112ed 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>
2026-11-25 23:30:10 +00:00

99 lines
2.9 KiB
Dart

import 'dart:typed_data';
import 'dart:ui' as ui;
import 'package:flutter/painting.dart';
import 'package:xterm/src/ui/painter.dart';
import 'package:xterm/xterm.dart';
const cursorColor = Color(0xFFFF0000);
const backgroundColor = Color(0xFF0000FF);
const foregroundColor = Color(0xFF00FF00);
/// A theme whose cursor, background and foreground are pure red, blue and
/// green, so painted pixels say which of them they are.
const fixtureTheme = TerminalTheme(
cursor: cursorColor,
selection: Color(0x80FFFFFF),
foreground: foregroundColor,
background: backgroundColor,
black: Color(0xFF000000),
red: Color(0xFF800000),
green: Color(0xFF008000),
yellow: Color(0xFF808000),
blue: Color(0xFF000080),
magenta: Color(0xFF800080),
cyan: Color(0xFF008080),
white: Color(0xFFC0C0C0),
brightBlack: Color(0xFF808080),
brightRed: Color(0xFFFF8080),
brightGreen: Color(0xFF80FF80),
brightYellow: Color(0xFFFFFF80),
brightBlue: Color(0xFF8080FF),
brightMagenta: Color(0xFFFF80FF),
brightCyan: Color(0xFF80FFFF),
brightWhite: Color(0xFFFFFFFF),
searchHitBackground: Color(0xFFFFFF00),
searchHitBackgroundCurrent: Color(0xFFFF8000),
searchHitForeground: Color(0xFF000000),
);
TerminalPainter fixturePainter() => TerminalPainter(
theme: fixtureTheme,
textStyle: const TerminalStyle(fontSize: 20, height: 1),
textScaler: TextScaler.noScaling,
);
/// The pixels [paint] draws on a transparent canvas of [width] x [height].
class Pixels {
Pixels._(this.width, this.height, this._rgba);
final int width;
final int height;
final ByteData _rgba;
static Future<Pixels> paint(
int width,
int height,
void Function(Canvas canvas) paint,
) async {
final recorder = ui.PictureRecorder();
paint(Canvas(recorder));
final image = await recorder.endRecording().toImage(width, height);
final data = await image.toByteData(format: ui.ImageByteFormat.rawRgba);
image.dispose();
return Pixels._(width, height, data!);
}
/// The colour at ([x], [y]), opaque or transparent.
Color at(int x, int y) {
final i = (y * width + x) * 4;
return Color.fromARGB(
_rgba.getUint8(i + 3),
_rgba.getUint8(i),
_rgba.getUint8(i + 1),
_rgba.getUint8(i + 2),
);
}
/// How many pixels in [rect] are exactly [color].
int count(Color color, [Rect? rect]) {
final area =
rect ?? Rect.fromLTWH(0, 0, width.toDouble(), height.toDouble());
var n = 0;
for (var y = area.top.floor(); y < area.bottom.ceil(); y++) {
for (var x = area.left.floor(); x < area.right.ceil(); x++) {
if (at(x, y) == color) n++;
}
}
return n;
}
}
/// A cell holding [char] with [flags] and default colours.
CellData cellOf(String char, {int flags = 0, int width = 1}) => CellData(
foreground: 0,
background: 0,
flags: flags,
content: char.codeUnitAt(0) | (width << CellContent.widthShift),
);