The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
Paint Block Elements as cell-sized rectangles instead of font glyphs
glifocatab924986bacd
diff --git a/desktop/test/terminal_block_glyph_test.dart b/desktop/test/terminal_block_glyph_test.dartnew file mode 100644index 000000000..d85050381--- /dev/null+++ b/desktop/test/terminal_block_glyph_test.dart@@ -0,0 +1,276 @@+import 'dart:typed_data';+import 'dart:ui';++import 'package:flutter/painting.dart';+import 'package:flutter_test/flutter_test.dart';+import 'package:xterm/src/ui/block_glyphs.dart';+import 'package:xterm/src/ui/painter.dart';+import 'package:xterm/xterm.dart';++const _full = Rect.fromLTRB(0, 0, 1, 1);+const _ul = Rect.fromLTRB(0, 0, 0.5, 0.5);+const _ur = Rect.fromLTRB(0.5, 0, 1, 0.5);+const _ll = Rect.fromLTRB(0, 0.5, 0.5, 1);+const _lr = Rect.fromLTRB(0.5, 0.5, 1, 1);++void main() {+ TestWidgetsFlutterBinding.ensureInitialized();++ group('lookup table', () {+ test(+ 'every Block Elements code point has a glyph and nothing else does',+ () {+ for (var cp = 0x2580; cp <= 0x259F; cp++) {+ expect(BlockGlyph.lookup(cp), isNotNull, reason: _u(cp));+ }+ expect(BlockGlyph.lookup(0x257F), isNull); // last box-drawing char+ expect(BlockGlyph.lookup(0x25A0), isNull); // ■ geometric shapes+ expect(BlockGlyph.lookup('A'.codeUnitAt(0)), isNull);+ },+ );++ test('halves and the full block', () {+ expect(BlockGlyph.lookup(0x2588)!.rects, [_full]);+ expect(BlockGlyph.lookup(0x2580)!.rects, [+ const Rect.fromLTRB(0, 0, 1, 0.5),+ ]);+ expect(BlockGlyph.lookup(0x2584)!.rects, [+ const Rect.fromLTRB(0, 0.5, 1, 1),+ ]);+ expect(BlockGlyph.lookup(0x258C)!.rects, [+ const Rect.fromLTRB(0, 0, 0.5, 1),+ ]);+ expect(BlockGlyph.lookup(0x2590)!.rects, [+ const Rect.fromLTRB(0.5, 0, 1, 1),+ ]);+ });++ test('lower eighths U+2581–U+2587 grow from the bottom', () {+ for (var i = 1; i <= 7; i++) {+ final r = BlockGlyph.lookup(0x2580 + i)!.rects.single;+ expect(r, Rect.fromLTRB(0, 1 - i / 8, 1, 1), reason: _u(0x2580 + i));+ }+ });++ test('left eighths U+2589–U+258F shrink from seven eighths', () {+ for (var i = 7; i >= 1; i--) {+ final r = BlockGlyph.lookup(0x2590 - i)!.rects.single;+ expect(r, Rect.fromLTRB(0, 0, i / 8, 1), reason: _u(0x2590 - i));+ }+ });++ test('upper and right one-eighth strips', () {+ expect(BlockGlyph.lookup(0x2594)!.rects, [+ const Rect.fromLTRB(0, 0, 1, 0.125),+ ]);+ expect(BlockGlyph.lookup(0x2595)!.rects, [+ const Rect.fromLTRB(0.875, 0, 1, 1),+ ]);+ });++ test('all ten quadrant combinations, exactly', () {+ const expected = <int, List<Rect>>{+ 0x2596: [_ll], // ▖+ 0x2597: [_lr], // ▗+ 0x2598: [_ul], // ▘+ 0x2599: [_ul, _ll, _lr], // ▙+ 0x259A: [_ul, _lr], // ▚+ 0x259B: [_ul, _ur, _ll], // ▛+ 0x259C: [_ul, _ur, _lr], // ▜+ 0x259D: [_ur], // ▝+ 0x259E: [_ur, _ll], // ▞+ 0x259F: [_ur, _ll, _lr], // ▟+ };+ for (final entry in expected.entries) {+ expect(+ BlockGlyph.lookup(entry.key)!.rects,+ unorderedEquals(entry.value),+ reason: _u(entry.key),+ );+ }+ });++ test(+ 'shades are a full cell at reduced coverage, everything else is opaque',+ () {+ expect(BlockGlyph.lookup(0x2591)!.opacity, 0.25);+ expect(BlockGlyph.lookup(0x2592)!.opacity, 0.5);+ expect(BlockGlyph.lookup(0x2593)!.opacity, 0.75);+ for (final cp in [0x2591, 0x2592, 0x2593]) {+ expect(BlockGlyph.lookup(cp)!.rects, [_full]);+ }+ for (var cp = 0x2580; cp <= 0x259F; cp++) {+ if (cp >= 0x2591 && cp <= 0x2593) continue;+ expect(BlockGlyph.lookup(cp)!.opacity, 1.0, reason: _u(cp));+ }+ },+ );+ });++ group('snapRectToDevicePixels', () {+ test('rounds every edge to a device pixel', () {+ expect(+ snapRectToDevicePixels(const Rect.fromLTRB(0.4, 0.6, 7.49, 15.5), 1),+ const Rect.fromLTRB(0, 1, 7, 16),+ );+ expect(+ snapRectToDevicePixels(const Rect.fromLTRB(0.2, 0, 7.8, 15.6), 2),+ const Rect.fromLTRB(0, 0, 8, 15.5),+ );+ });++ test(+ 'two rects that meet at a fractional boundary share the snapped edge',+ () {+ final a = snapRectToDevicePixels(+ const Rect.fromLTRB(0, 0, 7.83, 16),+ 2,+ );+ final b = snapRectToDevicePixels(+ const Rect.fromLTRB(7.83, 0, 15.66, 16),+ 2,+ );+ expect(a.right, b.left);+ },+ );++ test('a strip thinner than a device pixel keeps one', () {+ final strip = snapRectToDevicePixels(+ const Rect.fromLTRB(6.9, 0, 7.3, 16),+ 1,+ );+ expect(strip.width, 1);+ final tall = snapRectToDevicePixels(+ const Rect.fromLTRB(0, 15.9, 8, 16.1),+ 2,+ );+ expect(tall.height, 0.5);+ });+ });++ group('painter', () {+ late TerminalPainter painter;+ late Size cell;++ setUp(() {+ painter = TerminalPainter(+ theme: TerminalThemes.defaultTheme,+ textStyle: const TerminalStyle(fontSize: 13),+ textScaler: TextScaler.noScaling,+ );+ cell = painter.cellSize;+ });++ test(+ 'a full block covers every pixel of the cell with the foreground',+ () async {+ final image = await _raster(painter, _cell(0x2588, foreground: _red));+ for (var y = 0; y < cell.height.floor(); y++) {+ for (var x = 0; x < cell.width.floor(); x++) {+ expect(image.at(x, y), 0xFFFF0000, reason: '($x,$y)');+ }+ }+ },+ );++ test('▛ leaves only the lower-right quadrant empty', () async {+ final image = await _raster(painter, _cell(0x259B, foreground: _red));+ final w = cell.width, h = cell.height;+ expect(image.at((w * 0.25).floor(), (h * 0.25).floor()), 0xFFFF0000);+ expect(image.at((w * 0.75).floor(), (h * 0.25).floor()), 0xFFFF0000);+ expect(image.at((w * 0.25).floor(), (h * 0.75).floor()), 0xFFFF0000);+ expect(image.at((w * 0.75).floor(), (h * 0.75).floor()), 0x00000000);+ });++ test('two blocks side by side and stacked leave no seam', () async {+ final image = await _raster(+ painter,+ _cell(0x2588, foreground: _red),+ columns: 3,+ rows: 2,+ );+ for (var y = 0; y < (cell.height * 2).floor(); y++) {+ for (var x = 0; x < (cell.width * 3).floor(); x++) {+ expect(image.at(x, y), 0xFFFF0000, reason: '($x,$y)');+ }+ }+ });++ test('inverse paints with the cell background colour', () async {+ final image = await _raster(+ painter,+ _cell(0x2588, foreground: _red, flags: CellFlags.inverse),+ );+ expect(image.at(2, 2), TerminalThemes.defaultTheme.background.toARGB32());+ });++ test('faint halves the alpha and shades stack with it', () async {+ final faint = await _raster(+ painter,+ _cell(0x2588, foreground: _red, flags: CellFlags.faint),+ );+ expect(faint.at(2, 2) >>> 24, closeTo(128, 1));++ final shade = await _raster(painter, _cell(0x2592, foreground: _red));+ expect(shade.at(2, 2) >>> 24, closeTo(128, 1));++ final both = await _raster(+ painter,+ _cell(0x2592, foreground: _red, flags: CellFlags.faint),+ );+ expect(both.at(2, 2) >>> 24, closeTo(64, 1));+ });+ });+}++String _u(int cp) => 'U+${cp.toRadixString(16).toUpperCase()}';++const _red = CellColor.rgb | 0xFF0000;++CellData _cell(int codePoint, {required int foreground, int flags = 0}) {+ return CellData(+ foreground: foreground,+ background: 0,+ flags: flags,+ content: codePoint | (1 << CellContent.widthShift),+ );+}++class _Raster {+ _Raster(this.bytes, this.width);+ final ByteData bytes;+ final int width;++ /// ARGB of the pixel at ([x], [y]); the image is rawRgba.+ int at(int x, int y) {+ final i = (y * width + x) * 4;+ final r = bytes.getUint8(i), g = bytes.getUint8(i + 1);+ final b = bytes.getUint8(i + 2), a = bytes.getUint8(i + 3);+ return (a << 24) | (r << 16) | (g << 8) | b;+ }+}++Future<_Raster> _raster(+ TerminalPainter painter,+ CellData cellData, {+ int columns = 1,+ int rows = 1,+}) async {+ final cell = painter.cellSize;+ final recorder = PictureRecorder();+ final canvas = Canvas(recorder);+ for (var r = 0; r < rows; r++) {+ for (var c = 0; c < columns; c++) {+ painter.paintCell(+ canvas,+ Offset(c * cell.width, r * cell.height),+ cellData,+ );+ }+ }+ final width = (cell.width * columns).ceil();+ final height = (cell.height * rows).ceil();+ final image = await recorder.endRecording().toImage(width, height);+ final bytes = await image.toByteData(format: ImageByteFormat.rawRgba);+ return _Raster(bytes!, width);+}diff --git a/desktop/third_party/xterm/README.autonomous.md b/desktop/third_party/xterm/README.autonomous.mdindex 307897586..553081cfa 100644--- a/desktop/third_party/xterm/README.autonomous.md+++ b/desktop/third_party/xterm/README.autonomous.md@@ -136,3 +136,21 @@ it if one is dropped.vertical scrolling and app-owned Meta shortcuts keep their bindings.Regression: the macOS/Linux pair in `test/terminal_panel_focus_test.dart`exercises physical key events through `TerminalPanel` to binary PTY input.++9. **Block Elements (U+2580–U+259F) are painted as rectangles, not font+ glyphs** (`lib/src/ui/block_glyphs.dart`, `lib/src/ui/painter.dart`,+ `lib/src/ui/render.dart`, `lib/src/terminal_view.dart`). A cell is+ `TerminalStyle.height` (1.2) times the font size, rounded to whole pixels+ by SkParagraph (13 pt → 16 px), but a font's block glyphs only cover the+ face's own ascent and descent — and SF Mono's don't reach the cell's edges+ horizontally either — so anything drawn with blocks (Claude Code's mascot,+ progress bars, TUI borders) showed a dark band under every row and seams+ between columns. `paintCellForeground` now hands those code points to+ `paintBlockGlyph`, which fills the cell's own rectangle(s) with every edge+ snapped to a device pixel (the view feeds the painter+ `MediaQuery.devicePixelRatioOf`) and anti-aliasing off; the snapping is+ what makes neighbours tile on Impeller, which ignores the flag. The three+ shade characters are a full cell at 25/50/75 % coverage, and inverse/faint+ follow the text path. Box drawing (U+2500–U+257F) still comes from the+ font. Regression: `test/terminal_block_glyph_test.dart`, which also+ rasterises through the real painter.diff --git a/desktop/third_party/xterm/lib/src/terminal_view.dart b/desktop/third_party/xterm/lib/src/terminal_view.dartindex 2269071c6..66760f36d 100644--- a/desktop/third_party/xterm/lib/src/terminal_view.dart+++ b/desktop/third_party/xterm/lib/src/terminal_view.dart@@ -725,7 +725,7 @@ class _TerminalView extends LeafRenderObjectWidget {onEditableRect: onEditableRect,composingText: composingText,composingBacktrackCells: composingBacktrackCells,- );+ )..devicePixelRatio = MediaQuery.devicePixelRatioOf(context);}@override@@ -747,6 +747,7 @@ class _TerminalView extends LeafRenderObjectWidget {..alwaysShowCursor = alwaysShowCursor..onEditableRect = onEditableRect..composingText = composingText- ..composingBacktrackCells = composingBacktrackCells;+ ..composingBacktrackCells = composingBacktrackCells+ ..devicePixelRatio = MediaQuery.devicePixelRatioOf(context);}}diff --git a/desktop/third_party/xterm/lib/src/ui/block_glyphs.dart b/desktop/third_party/xterm/lib/src/ui/block_glyphs.dartnew file mode 100644index 000000000..94463202f--- /dev/null+++ b/desktop/third_party/xterm/lib/src/ui/block_glyphs.dart@@ -0,0 +1,93 @@+import 'dart:ui';++/// Geometry for one Unicode Block Elements code point (U+2580–U+259F).+///+/// Terminals draw these themselves rather than trusting the font: a cell is+/// `TerminalStyle.height` times the font size tall, and a font's block glyphs+/// only cover the face's own ascent and descent, so glyph-drawn blocks leave a+/// band under every row and seams between columns (xterm.js `customGlyphs`,+/// Ghostty, Kitty and iTerm2 all synthesize them). [rects] are+/// expressed in the unit square — (0,0) top-left, (1,1) bottom-right — and are+/// scaled to the cell and snapped to device pixels when painted. [opacity]+/// carries the three shade characters, which are a full cell at reduced+/// coverage.+class BlockGlyph {+ const BlockGlyph(this.rects, {this.opacity = 1.0});++ final List<Rect> rects;+ final double opacity;++ /// Returns the glyph for [codePoint], or null when it is not a block element.+ static BlockGlyph? lookup(int codePoint) {+ if (codePoint < 0x2580 || codePoint > 0x259F) return null;+ return _table[codePoint - 0x2580];+ }+}++/// Rounds every edge of [rect] to a whole device pixel at [devicePixelRatio],+/// keeping at least one device pixel in each direction so a thin strip is+/// never rounded away. Adjacent cells and quadrants computed from the same+/// fractional boundary therefore round to the same pixel and share an edge.+Rect snapRectToDevicePixels(Rect rect, double devicePixelRatio) {+ final dpr = devicePixelRatio <= 0 ? 1.0 : devicePixelRatio;+ double snap(double v) => (v * dpr).round() / dpr;+ final left = snap(rect.left);+ final top = snap(rect.top);+ var right = snap(rect.right);+ var bottom = snap(rect.bottom);+ if (right <= left) right = left + 1 / dpr;+ if (bottom <= top) bottom = top + 1 / dpr;+ return Rect.fromLTRB(left, top, right, bottom);+}++const _full = Rect.fromLTRB(0, 0, 1, 1);++Rect _lower(int eighths) => Rect.fromLTRB(0, 1 - eighths / 8, 1, 1);+Rect _left(int eighths) => Rect.fromLTRB(0, 0, eighths / 8, 1);++const _upperLeft = Rect.fromLTRB(0, 0, 0.5, 0.5);+const _upperRight = Rect.fromLTRB(0.5, 0, 1, 0.5);+const _lowerLeft = Rect.fromLTRB(0, 0.5, 0.5, 1);+const _lowerRight = Rect.fromLTRB(0.5, 0.5, 1, 1);++/// Indexed by `codePoint - 0x2580`.+final _table = <BlockGlyph>[+ // U+2580 ▀ upper half+ const BlockGlyph([Rect.fromLTRB(0, 0, 1, 0.5)]),+ // U+2581–U+2587 lower one eighth … lower seven eighths+ for (var i = 1; i <= 7; i++) BlockGlyph([_lower(i)]),+ // U+2588 █ full block+ const BlockGlyph([_full]),+ // U+2589–U+258F left seven eighths … left one eighth+ for (var i = 7; i >= 1; i--) BlockGlyph([_left(i)]),+ // U+2590 ▐ right half+ const BlockGlyph([Rect.fromLTRB(0.5, 0, 1, 1)]),+ // U+2591 ░ light shade, U+2592 ▒ medium shade, U+2593 ▓ dark shade+ const BlockGlyph([_full], opacity: 0.25),+ const BlockGlyph([_full], opacity: 0.5),+ const BlockGlyph([_full], opacity: 0.75),+ // U+2594 ▔ upper one eighth+ const BlockGlyph([Rect.fromLTRB(0, 0, 1, 0.125)]),+ // U+2595 ▕ right one eighth+ const BlockGlyph([Rect.fromLTRB(0.875, 0, 1, 1)]),+ // U+2596 ▖ lower left+ const BlockGlyph([_lowerLeft]),+ // U+2597 ▗ lower right+ const BlockGlyph([_lowerRight]),+ // U+2598 ▘ upper left+ const BlockGlyph([_upperLeft]),+ // U+2599 ▙ upper left, lower left, lower right+ const BlockGlyph([_upperLeft, _lowerLeft, _lowerRight]),+ // U+259A ▚ upper left, lower right+ const BlockGlyph([_upperLeft, _lowerRight]),+ // U+259B ▛ upper left, upper right, lower left+ const BlockGlyph([_upperLeft, _upperRight, _lowerLeft]),+ // U+259C ▜ upper left, upper right, lower right+ const BlockGlyph([_upperLeft, _upperRight, _lowerRight]),+ // U+259D ▝ upper right+ const BlockGlyph([_upperRight]),+ // U+259E ▞ upper right, lower left+ const BlockGlyph([_upperRight, _lowerLeft]),+ // U+259F ▟ upper right, lower left, lower right+ const BlockGlyph([_upperRight, _lowerLeft, _lowerRight]),+];diff --git a/desktop/third_party/xterm/lib/src/ui/painter.dart b/desktop/third_party/xterm/lib/src/ui/painter.dartindex bc45fa21c..25cf2efd9 100644--- a/desktop/third_party/xterm/lib/src/ui/painter.dart+++ b/desktop/third_party/xterm/lib/src/ui/painter.dart@@ -1,6 +1,7 @@import 'dart:ui';import 'package:flutter/painting.dart';+import 'package:xterm/src/ui/block_glyphs.dart';import 'package:xterm/src/ui/palette_builder.dart';import 'package:xterm/src/ui/paragraph_cache.dart';import 'package:xterm/xterm.dart';@@ -64,6 +65,18 @@ class TerminalPainter {_paragraphCache.clear();}+ /// Device pixels per logical pixel, used to snap block-glyph edges so that+ /// neighbouring cells share a pixel boundary. Impeller ignores+ /// `Paint.isAntiAlias = false` (flutter/flutter#104721) and resolves every+ /// edge through MSAA, so without snapping two abutting rectangles can leave a+ /// hairline where one would not.+ double get devicePixelRatio => _devicePixelRatio;+ double _devicePixelRatio = 1.0;+ set devicePixelRatio(double value) {+ if (value == _devicePixelRatio) return;+ _devicePixelRatio = value;+ }+Size _measureCharSize() {const test = 'mmmmmmmmmm';@@ -185,6 +198,12 @@ class TerminalPainter {final charCode = cellData.content & CellContent.codepointMask;if (charCode == 0) return;+ final block = BlockGlyph.lookup(charCode);+ if (block != null) {+ paintBlockGlyph(canvas, offset, cellData, block);+ return;+ }+final cacheKey = cellData.getHash() ^ _textScaler.hashCode;var paragraph = _paragraphCache.getLayoutFromCache(cacheKey);@@ -228,6 +247,53 @@ class TerminalPainter {canvas.drawParagraph(paragraph, offset);}+ /// Paints a Block Elements character (U+2580–U+259F) as filled rectangles+ /// covering the whole cell instead of the font's glyph. See [BlockGlyph] for+ /// why; the colour rules match the text path above.+ void paintBlockGlyph(+ Canvas canvas,+ Offset offset,+ CellData cellData,+ BlockGlyph block,+ ) {+ final cellFlags = cellData.flags;++ var color = cellFlags & CellFlags.inverse == 0+ ? resolveForegroundColor(cellData.foreground)+ : resolveBackgroundColor(cellData.background);++ var opacity = block.opacity;+ if (cellFlags & CellFlags.faint != 0) opacity *= 0.5;+ if (opacity != 1.0) color = color.withValues(alpha: opacity);++ // Blocks are meant to tile, so every edge lands on a device pixel and+ // anti-aliasing is off (Skia honours that; Impeller relies on the+ // snapping alone). A strip thinner than one device pixel — an eighth of a+ // narrow cell — is widened to one so it never rasterises to nothing.+ final paint = Paint()+ ..color = color+ ..isAntiAlias = false;++ final widthScale = cellData.content >> CellContent.widthShift == 2 ? 2 : 1;+ final width = _cellSize.width * widthScale;+ final height = _cellSize.height;++ for (final unit in block.rects) {+ canvas.drawRect(+ snapRectToDevicePixels(+ Rect.fromLTRB(+ offset.dx + unit.left * width,+ offset.dy + unit.top * height,+ offset.dx + unit.right * width,+ offset.dy + unit.bottom * height,+ ),+ _devicePixelRatio,+ ),+ paint,+ );+ }+ }+/// Paints the background of a cell represented by [cellData] to [canvas] at/// [offset].@pragma('vm:prefer-inline')diff --git a/desktop/third_party/xterm/lib/src/ui/render.dart b/desktop/third_party/xterm/lib/src/ui/render.dartindex b8da24cd9..4ed9ef71c 100644--- a/desktop/third_party/xterm/lib/src/ui/render.dart+++ b/desktop/third_party/xterm/lib/src/ui/render.dart@@ -142,6 +142,12 @@ class RenderTerminal extends RenderBox with RelayoutWhenSystemFontsChangeMixin {markNeedsPaint();}+ set devicePixelRatio(double value) {+ if (value == _painter.devicePixelRatio) return;+ _painter.devicePixelRatio = value;+ markNeedsPaint();+ }+FocusNode _focusNode;set focusNode(FocusNode value) {if (value == _focusNode) return;