Terminal: grapheme-aware widths, drawn box/Powerline glyphs, line pictures

Emulator (vendored xterm):
- Widths follow glibc wcwidth on generated Unicode 16 tables
  (tool/gen_unicode_tables.py); combining marks, variation selectors,
  ZWJ sequences, skin tones, flags and Hangul jamo join the previous cell,
  stored as interned clusters (CellContent.clusterFlag) and drawn and
  copied whole. U+FE0F and flags take two columns, as modern terminals
  do; a wide character never starts in the last column.
- Box drawing, block elements and Powerline separators are drawn as
  geometry filling the cell; rows are whole pixels high.
- Backgrounds merge per colour; each line is a picture reused until the
  line changes (BufferLine.version); a line drawn unchanged settles into
  one laid out paragraph with a span per style. TerminalStyle and
  TerminalTheme compare by value.

App: bundled Symbols Nerd Font Mono subset (568 KiB, MIT) as the
terminal's first fallback, loaded on first use; line height 1.1;
?terminalUnicode=1 fixture showcase; bench gains a progress workload.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-26 01:14:48 +00:00
parent f4ffda7130
commit 018d37f103
30 changed files with 3811 additions and 103 deletions
+31
View File
@@ -33,6 +33,34 @@ const String _attributeShowcase =
'\x1b]11;#000000\x07after strings\r\n'
'abc\x1b[2D';
/// `?terminalUnicode=1`: widths, grapheme clusters, box drawing, blocks,
/// Powerline and Nerd Font glyphs, printed after the build terminal's
/// prompt. Each cluster takes the columns its width says (combining marks
/// none, emoji and CJK two), so the first three lines' `|` fall in columns
/// 6, 11 and 12.
const String _unicodeShowcase =
'printf unicode\r\n'
'e\u0301 n\u0303 a\u0300\u0316 |\r\n'
'\u4E2D\u6587 \u{1F600} \u{1F44D}\u{1F3FD} |\r\n'
'\u{1F468}\u200D\u{1F469}\u200D\u{1F467} \u{1F1F5}\u{1F1F9} '
'\u2764\uFE0F 1\uFE0F\u20E3 |\r\n'
'\u250C\u2500\u252C\u2500\u2510 \u250F\u2501\u2533\u2501\u2513 '
'\u2554\u2550\u2566\u2550\u2557 \u256D\u2500\u2500\u2500\u256E '
'\u2588\u2589\u258A\u258B\u258C\u258D\u258E\u258F '
'\u2581\u2582\u2583\u2584\u2585\u2586\u2587\u2588\r\n'
'\u251C\u2500\u253C\u2500\u2524 \u2523\u2501\u254B\u2501\u252B '
'\u2560\u2550\u256C\u2550\u2563 \u2502 \u2502 '
'\u2591\u2591\u2592\u2592\u2593\u2593\u2588\u2588 '
'\u2596\u2597\u2598\u2599\u259A\u259B\u259C\u259D\u259E\u259F\r\n'
'\u2514\u2500\u2534\u2500\u2518 \u2517\u2501\u253B\u2501\u251B '
'\u255A\u2550\u2569\u2550\u255D \u2570\u2500\u2500\u2500\u256F '
'\u2504\u2504 \u2506 \u254C\u254C \u2571\u2572\u2573\r\n'
'\x1b[30;44m \uE0A0 main \x1b[34;42m\uE0B0\x1b[30m ~/src \x1b[32;49m\uE0B0'
'\x1b[0m \x1b[35m\uE0B6\x1b[30;45mok\x1b[35;49m\uE0B4\x1b[0m '
'\x1b[33m\uE0B2\x1b[30;43m 12:00 \x1b[33;49m\uE0BC\x1b[0m '
'\uE0B1 \uE0B3 |\r\n'
'icons: \uF418 \uF09B \uF303 \uE615 \u23FB |\r\n';
void configureTerminalFixture(Map<String, String> params) {
_enabled = params['terminals'] == '1';
if (!_enabled) return;
@@ -65,6 +93,9 @@ void configureTerminalFixture(Map<String, String> params) {
if (params['terminalAttrs'] == '1') {
_output['term_build'] = _output['term_build']! + _attributeShowcase;
}
if (params['terminalUnicode'] == '1') {
_output['term_build'] = _output['term_build']! + _unicodeShowcase;
}
final mode = switch (params['terminal']) {
'panel' => TerminalMode.panel,
'float' => TerminalMode.float,
+18 -2
View File
@@ -6,7 +6,7 @@
// flutter build web --profile --target tool/perf/terminal_stream_bench.dart \
// --output build/terminal-bench
// Run with tool/perf/terminal_stream_bench.mjs, or open the page with
// `?workload=seq|yes|unicode|colors|screen&mb=30&rate=30` (the window size sets the grid).
// `?workload=seq|yes|unicode|colors|screen|progress&mb=30&rate=30` (the window size sets the grid).
// When the stream ends `window.__benchResult` holds a JSON summary:
// frames, build/raster/total quantiles (ms), rAF interval quantiles (ms),
// MB written, seconds and MB/s.
@@ -101,7 +101,7 @@ class _BenchState extends State<_Bench> {
out.write('y\r\n');
case 'unicode':
out.write(
'$_counter é ñ 中文 😀 👍🏽 🇵🇹 │ ╭─╮ ▓▒░ \u{E0B0} done\r\n',
'$_counter e\u0301 \u00F1 \u4E2D\u6587 \u{1F600} \u{1F44D}\u{1F3FD} \u{1F1F5}\u{1F1F9} \u2502 \u256D\u2500\u256E \u2593\u2592\u2591 \u{E0B0} done\r\n',
);
case 'colors':
final c = 31 + _counter % 7;
@@ -120,6 +120,22 @@ class _BenchState extends State<_Bench> {
'${'process name and arguments ' * 4}\x1b[K\r\n',
);
}
case 'progress':
// A screen of text, then one status line rewritten in place (a
// progress bar, a build counter): one row changes per frame.
if (_counter == 1) {
for (var row = 0; row < 47; row++) {
out.write(
'\x1b[3${row % 7 + 1}mline $row\x1b[0m '
'${'static output that does not change ' * 3}\r\n',
);
}
}
final done = _counter % 50;
out.write(
'\r\x1b[1m[${'#' * done}${'.' * (50 - done)}]\x1b[0m '
'$_counter files',
);
default:
out.write('$_counter\r\n');
}
+4 -2
View File
@@ -5,7 +5,7 @@
// intervals measured in the page, and the throughput reached.
//
// node tool/perf/terminal_stream_bench.mjs --build build/terminal-bench \
// [--workloads seq,yes,unicode,colors,screen] [--mb 30] [--rate 30] [--size 1280x800]
// [--workloads seq,yes,unicode,colors,screen,progress] [--mb 30] [--rate 30] [--size 1280x800]
import { parseArgs } from 'node:util';
import { setTimeout as delay } from 'node:timers/promises';
import { openBrowser } from '../capture/browser.mjs';
@@ -14,11 +14,12 @@ import { serveBuild } from '../capture/serve.mjs';
const { values: options } = parseArgs({
options: {
build: { type: 'string' },
workloads: { type: 'string', default: 'seq,yes,unicode,colors,screen' },
workloads: { type: 'string', default: 'seq,yes,unicode,colors,screen,progress' },
mb: { type: 'string', default: '30' },
rate: { type: 'string', default: '30' },
size: { type: 'string', default: '1280x800' },
timeout: { type: 'string', default: '120000' },
params: { type: 'string', default: '' },
},
});
if (!options.build) throw new Error('--build required');
@@ -45,6 +46,7 @@ try {
url.searchParams.set('workload', workload);
url.searchParams.set('mb', options.mb);
url.searchParams.set('rate', options.rate);
for (const [k, v] of new URLSearchParams(options.params)) url.searchParams.set(k, v);
await browser.send('Emulation.setDeviceMetricsOverride', { width, height, deviceScaleFactor: 1, mobile: false });
await browser.send('Page.navigate', { url: url.href });
await delay(300);
+3 -1
View File
@@ -888,7 +888,9 @@ class _FixtureSink implements WebSocketSink {
/// `?hits=N`, `?chats=N` and `?graph=1` add bench data
/// (tool/perf/perf_fixture.dart);
/// `?terminals=1` lists two machine terminals, and `?terminal=panel` or
/// `?terminal=float` opens them at launch (tool/perf/terminal_fixture.dart);
/// `?terminal=float` opens them at launch, with `?terminalAttrs=1` and
/// `?terminalUnicode=1` adding emulator showcases
/// (tool/perf/terminal_fixture.dart);
/// `?windows=N` opens N floating probe windows whose content opens every
/// kind of popup and a pushed page (tool/capture/window_probe.dart);
/// `?speech=fake` reads replies aloud with a scripted engine, one word per