9eaa8d18c0
One hue per variant (brightness steps for roles, statuses and chat colours, with cross/ring glyphs where hue alone told status), square corners, 1px phosphor frames, a faint text glow and a static scanline and vignette pattern painted once in its own repaint boundary. Light mode is a paper-white phosphor. Terminal's theme builder is shared, not forked. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
124 lines
3.8 KiB
Dart
124 lines
3.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
/// The width of a terminal transcript's glyph column: about two monospace
|
|
/// cells of the ambient text, so lines after a glyph align like a CLI's.
|
|
double terminalGlyphColumn(BuildContext context) {
|
|
final style = DefaultTextStyle.of(context).style;
|
|
final size = MediaQuery.textScalerOf(context).scale(style.fontSize ?? 14);
|
|
return size * 1.3;
|
|
}
|
|
|
|
/// The height of one line of the ambient text, so a painted glyph centres on
|
|
/// the first line of the text beside it.
|
|
double terminalLineHeight(BuildContext context, [TextStyle? style]) {
|
|
final ambient = style ?? DefaultTextStyle.of(context).style;
|
|
final size = MediaQuery.textScalerOf(context).scale(ambient.fontSize ?? 14);
|
|
return size * (ambient.height ?? 1.35);
|
|
}
|
|
|
|
/// The kind of mark a terminal transcript draws in its glyph column. They
|
|
/// are painted rather than typed: the bundled monospace family has no
|
|
/// record (U+25CF) or bracket corner (U+23BF), and the web engine would
|
|
/// otherwise fetch a fallback font for them.
|
|
enum TerminalGlyphKind {
|
|
/// A filled dot: an answer, or a tool call (its colour gives the status).
|
|
dot,
|
|
|
|
/// A bracket corner under a call: its result line.
|
|
elbow,
|
|
|
|
/// A cross: a failed tool call under a monochrome design, where the dot's
|
|
/// colour cannot say so.
|
|
cross,
|
|
|
|
/// A hollow ring: a running tool call under a monochrome design.
|
|
ring,
|
|
}
|
|
|
|
/// One painted terminal glyph, a glyph column wide and one text line tall,
|
|
/// in [color].
|
|
class TerminalGlyph extends StatelessWidget {
|
|
const TerminalGlyph(this.kind, {super.key, required this.color, this.style});
|
|
|
|
final TerminalGlyphKind kind;
|
|
final Color color;
|
|
|
|
/// The text the glyph sits beside; the ambient style when null.
|
|
final TextStyle? style;
|
|
|
|
@override
|
|
Widget build(BuildContext context) => ExcludeSemantics(
|
|
child: SizedBox(
|
|
width: terminalGlyphColumn(context),
|
|
height: terminalLineHeight(context, style),
|
|
child: CustomPaint(painter: _GlyphPainter(kind, color)),
|
|
),
|
|
);
|
|
}
|
|
|
|
class _GlyphPainter extends CustomPainter {
|
|
const _GlyphPainter(this.kind, this.color);
|
|
|
|
final TerminalGlyphKind kind;
|
|
final Color color;
|
|
|
|
@override
|
|
void paint(Canvas canvas, Size size) {
|
|
final h = size.height;
|
|
final paint = Paint()
|
|
..color = color
|
|
..isAntiAlias = true;
|
|
switch (kind) {
|
|
case TerminalGlyphKind.dot:
|
|
canvas.drawCircle(Offset(h * 0.3, h / 2), h * 0.17, paint);
|
|
case TerminalGlyphKind.elbow:
|
|
paint
|
|
..style = PaintingStyle.stroke
|
|
..strokeWidth = 1;
|
|
final x = h * 0.3;
|
|
final path = Path()
|
|
..moveTo(x, 0)
|
|
..lineTo(x, h * 0.55)
|
|
..lineTo(size.width * 0.95, h * 0.55);
|
|
canvas.drawPath(path, paint);
|
|
case TerminalGlyphKind.cross:
|
|
paint
|
|
..style = PaintingStyle.stroke
|
|
..strokeWidth = 1.5
|
|
..strokeCap = StrokeCap.square;
|
|
final c = Offset(h * 0.3, h / 2);
|
|
final r = h * 0.15;
|
|
canvas
|
|
..drawLine(c - Offset(r, r), c + Offset(r, r), paint)
|
|
..drawLine(c + Offset(-r, r), c + Offset(r, -r), paint);
|
|
case TerminalGlyphKind.ring:
|
|
paint
|
|
..style = PaintingStyle.stroke
|
|
..strokeWidth = 1.25;
|
|
canvas.drawCircle(Offset(h * 0.3, h / 2), h * 0.15, paint);
|
|
}
|
|
}
|
|
|
|
@override
|
|
bool shouldRepaint(_GlyphPainter old) =>
|
|
old.kind != kind || old.color != color;
|
|
}
|
|
|
|
/// [child] after a [glyph] in the glyph column, the glyph centred on the
|
|
/// child's first line.
|
|
class TerminalGlyphRow extends StatelessWidget {
|
|
const TerminalGlyphRow({super.key, required this.glyph, required this.child});
|
|
|
|
final Widget glyph;
|
|
final Widget child;
|
|
|
|
@override
|
|
Widget build(BuildContext context) => Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
glyph,
|
|
Expanded(child: child),
|
|
],
|
|
);
|
|
}
|