Retro CRT design: Terminal on a green or amber phosphor tube
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>
This commit is contained in:
@@ -0,0 +1,123 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_design.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_design_tokens.dart';
|
||||
import 'package:pipelines_app/ui/theme/design_screen_overlay.dart';
|
||||
|
||||
class _Counted extends StatefulWidget {
|
||||
const _Counted({required this.controller});
|
||||
|
||||
final ScrollController controller;
|
||||
|
||||
static int mounts = 0;
|
||||
|
||||
@override
|
||||
State<_Counted> createState() => _CountedState();
|
||||
}
|
||||
|
||||
class _CountedState extends State<_Counted> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_Counted.mounts++;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => ListView.builder(
|
||||
controller: widget.controller,
|
||||
itemCount: 200,
|
||||
itemBuilder: (_, i) => ListTile(title: Text('Row $i')),
|
||||
);
|
||||
}
|
||||
|
||||
/// Layer kinds that cost a saveLayer on every raster.
|
||||
int _saveLayers(Layer root) {
|
||||
var n = 0;
|
||||
void visit(Layer layer) {
|
||||
if (layer is OpacityLayer ||
|
||||
layer is BackdropFilterLayer ||
|
||||
layer is ImageFilterLayer ||
|
||||
layer is ColorFilterLayer ||
|
||||
layer is ShaderMaskLayer) {
|
||||
n++;
|
||||
}
|
||||
if (layer is ContainerLayer) {
|
||||
for (var c = layer.firstChild; c != null; c = c.nextSibling) {
|
||||
visit(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
visit(root);
|
||||
return n;
|
||||
}
|
||||
|
||||
void main() {
|
||||
final overlay = find.byKey(const Key('design-screen-overlay'));
|
||||
|
||||
Widget host(AppDesign design, ScrollController controller) => MaterialApp(
|
||||
theme: design.light(),
|
||||
darkTheme: design.dark(),
|
||||
themeMode: ThemeMode.dark,
|
||||
builder: (_, child) => DesignScreenOverlay(child: child!),
|
||||
home: Scaffold(body: _Counted(controller: controller)),
|
||||
);
|
||||
|
||||
testWidgets('Retro CRT paints its pattern once, in its own layer, over '
|
||||
'content that scrolls beneath it', (tester) async {
|
||||
final controller = ScrollController();
|
||||
addTearDown(controller.dispose);
|
||||
await tester.pumpWidget(host(AppDesign.terminal, controller));
|
||||
expect(overlay, findsNothing);
|
||||
final plain = _saveLayers(tester.binding.renderViews.first.debugLayer!);
|
||||
_Counted.mounts = 0;
|
||||
|
||||
await tester.pumpWidget(host(AppDesign.retroCrt, controller));
|
||||
await tester.pumpAndSettle();
|
||||
expect(overlay, findsOneWidget);
|
||||
// Switching designs does not remount the app beneath the pattern.
|
||||
expect(_Counted.mounts, 0);
|
||||
expect(
|
||||
_saveLayers(tester.binding.renderViews.first.debugLayer!),
|
||||
plain,
|
||||
reason: 'the pattern adds no saveLayer',
|
||||
);
|
||||
final boundary = tester.renderObject<RenderRepaintBoundary>(overlay);
|
||||
final painted =
|
||||
boundary.debugSymmetricPaintCount + boundary.debugAsymmetricPaintCount;
|
||||
for (var i = 0; i < 20; i++) {
|
||||
controller.jumpTo(controller.offset + 90);
|
||||
await tester.pump();
|
||||
}
|
||||
expect(
|
||||
boundary.debugSymmetricPaintCount + boundary.debugAsymmetricPaintCount,
|
||||
painted,
|
||||
reason: 'scrolling repainted the pattern',
|
||||
);
|
||||
// The pattern lets every pointer through to the rows.
|
||||
final hit = tester.hitTestOnBinding(tester.getCenter(overlay));
|
||||
expect(hit.path.any((entry) => entry.target == boundary), isFalse);
|
||||
expect(hit.path.any((entry) => entry.target is RenderParagraph), isTrue);
|
||||
|
||||
await tester.pumpWidget(host(AppDesign.terminal, controller));
|
||||
await tester.pumpAndSettle();
|
||||
expect(overlay, findsNothing);
|
||||
expect(_Counted.mounts, 0);
|
||||
});
|
||||
|
||||
test('the pattern repaints only for a new pattern or pixel ratio', () {
|
||||
final pattern = AppDesign.retroCrt
|
||||
.dark()
|
||||
.extension<AppDesignTokens>()!
|
||||
.screen!;
|
||||
final painter = ScreenPatternPainter(pattern, 2);
|
||||
expect(painter.shouldRepaint(ScreenPatternPainter(pattern, 2)), isFalse);
|
||||
expect(painter.shouldRepaint(ScreenPatternPainter(pattern, 3)), isTrue);
|
||||
final amber = AppDesign.retroCrtAmber
|
||||
.light()
|
||||
.extension<AppDesignTokens>()!
|
||||
.screen!;
|
||||
expect(painter.shouldRepaint(ScreenPatternPainter(amber, 2)), isTrue);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,247 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/chat/domain/chat_colors.dart';
|
||||
import 'package:pipelines_app/features/chat/domain/chat_transcript.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/chat_color_palette.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/transcript/chat_message_view.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/transcript/terminal/terminal_glyphs.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/transcript/terminal/terminal_prompt_line.dart';
|
||||
import 'package:pipelines_app/ui/text/monospace.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_design.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_design_tokens.dart';
|
||||
import 'package:pipelines_app/ui/theme/crt_palette.dart';
|
||||
|
||||
const _crts = [AppDesign.retroCrt, AppDesign.retroCrtAmber];
|
||||
|
||||
ThemeData _theme(AppDesign design, Brightness brightness) =>
|
||||
brightness == Brightness.dark ? design.dark() : design.light();
|
||||
|
||||
double _contrast(Color a, Color b) {
|
||||
final la = a.computeLuminance(), lb = b.computeLuminance();
|
||||
return (la > lb ? la + 0.05 : lb + 0.05) / (la > lb ? lb + 0.05 : la + 0.05);
|
||||
}
|
||||
|
||||
/// Whether [color] is a shade of [hue] (or a neutral black/white).
|
||||
bool _ofHue(Color color, double hue) {
|
||||
final hsl = HSLColor.fromColor(color);
|
||||
if (hsl.saturation < 0.05 || hsl.lightness < 0.01) return true;
|
||||
final d = (hsl.hue - hue).abs() % 360;
|
||||
return (d > 180 ? 360 - d : d) < 3;
|
||||
}
|
||||
|
||||
JsonMap _tool(String id, String status) => {
|
||||
'type': 'tool',
|
||||
'id': id,
|
||||
'name': 'Bash',
|
||||
'state': {
|
||||
'status': status,
|
||||
'input': {'command': 'go test ./...'},
|
||||
if (status == 'error') 'error': {'message': 'exit status 1'},
|
||||
},
|
||||
};
|
||||
|
||||
void main() {
|
||||
test(
|
||||
'Retro CRT is listed in green and amber, monospace, with stable ids',
|
||||
() {
|
||||
expect(AppDesign.fromId('retro-crt'), AppDesign.retroCrt);
|
||||
expect(AppDesign.fromId('retro-crt-amber'), AppDesign.retroCrtAmber);
|
||||
expect(AppDesign.retroCrt.label, 'Retro CRT');
|
||||
expect(AppDesign.retroCrtAmber.label, 'Retro CRT (amber)');
|
||||
expect(AppDesign.retroCrt.crtPhosphor, CrtPhosphor.green);
|
||||
expect(AppDesign.retroCrtAmber.crtPhosphor, CrtPhosphor.amber);
|
||||
expect(AppDesign.terminal.crtPhosphor, isNull);
|
||||
for (final design in _crts) {
|
||||
expect(design.description, isNot(contains('\n')));
|
||||
expect(design.usesInterfaceFont, isFalse);
|
||||
expect(
|
||||
design.dark(fontFamily: 'Inter').textTheme.bodyMedium?.fontFamily,
|
||||
appMonospaceFamily,
|
||||
);
|
||||
}
|
||||
// The green tube's text is the classic #33FF66.
|
||||
final green = CrtRamp(CrtPhosphor.green, Brightness.dark).text;
|
||||
expect(green.toARGB32(), 0xFF33FF66);
|
||||
},
|
||||
);
|
||||
|
||||
test('tokens: Terminal structure, square corners, phosphor frames, one '
|
||||
'hue, a static screen pattern', () {
|
||||
for (final design in _crts) {
|
||||
for (final brightness in Brightness.values) {
|
||||
final theme = _theme(design, brightness);
|
||||
final tokens = theme.extension<AppDesignTokens>()!;
|
||||
expect(tokens.design, design);
|
||||
expect(tokens.transcript, TranscriptStyle.prompt);
|
||||
expect(tokens.selectedRow, SelectedRowStyle.framed);
|
||||
expect(tokens.composer, ComposerStyle.pill);
|
||||
expect(tokens.radius, 0);
|
||||
expect(tokens.flat, isTrue);
|
||||
expect(tokens.frame, theme.colorScheme.outlineVariant);
|
||||
expect(tokens.monochrome, theme.colorScheme.onSurface);
|
||||
expect(tokens.screen, isNotNull);
|
||||
expect(tokens.ansi, isNotNull);
|
||||
final dialog = theme.dialogTheme.shape! as RoundedRectangleBorder;
|
||||
expect(dialog.borderRadius, BorderRadius.zero);
|
||||
final tooltip = theme.tooltipTheme.decoration! as BoxDecoration;
|
||||
expect(tooltip.borderRadius, BorderRadius.zero);
|
||||
}
|
||||
}
|
||||
// Every other design keeps no pattern and full colour.
|
||||
for (final design in AppDesign.values) {
|
||||
if (_crts.contains(design)) continue;
|
||||
final tokens =
|
||||
design.dark().extension<AppDesignTokens>() ??
|
||||
AppDesignTokens.standard;
|
||||
expect(tokens.screen, isNull);
|
||||
expect(tokens.monochrome, isNull);
|
||||
}
|
||||
});
|
||||
|
||||
test('every colour is a shade of the phosphor; contrast stays high', () {
|
||||
for (final design in _crts) {
|
||||
final hue = design.crtPhosphor!.hue;
|
||||
for (final brightness in Brightness.values) {
|
||||
final scheme = _theme(design, brightness).colorScheme;
|
||||
for (final color in [
|
||||
scheme.primary,
|
||||
scheme.secondary,
|
||||
scheme.tertiary,
|
||||
scheme.error,
|
||||
scheme.surface,
|
||||
scheme.surfaceContainerHighest,
|
||||
scheme.onSurface,
|
||||
scheme.onSurfaceVariant,
|
||||
scheme.outline,
|
||||
scheme.outlineVariant,
|
||||
scheme.primaryContainer,
|
||||
scheme.errorContainer,
|
||||
]) {
|
||||
expect(_ofHue(color, hue), isTrue, reason: '$design $color');
|
||||
}
|
||||
final page = scheme.surface;
|
||||
expect(_contrast(scheme.onSurface, page), greaterThan(7));
|
||||
expect(_contrast(scheme.onSurfaceVariant, page), greaterThan(4.5));
|
||||
expect(_contrast(scheme.outline, page), greaterThan(1.8));
|
||||
// Statuses step in brightness: success (text), warning, error.
|
||||
final ansi = _theme(
|
||||
design,
|
||||
brightness,
|
||||
).extension<AppDesignTokens>()!.ansi!;
|
||||
final steps = [
|
||||
ansi.green,
|
||||
ansi.yellow,
|
||||
ansi.red,
|
||||
].map((c) => _contrast(c, page)).toList();
|
||||
expect(steps[1], greaterThan(steps[0] * 1.15), reason: '$design');
|
||||
expect(steps[2], greaterThan(steps[1] * 1.1), reason: '$design');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test('dark text glows with one small shadow; light text has none', () {
|
||||
for (final design in _crts) {
|
||||
final dark = design.dark().textTheme;
|
||||
for (final style in [dark.bodyMedium, dark.titleLarge, dark.labelSmall]) {
|
||||
final shadows = style!.shadows!;
|
||||
expect(shadows, hasLength(1));
|
||||
expect(shadows.single.blurRadius, lessThanOrEqualTo(4));
|
||||
expect(shadows.single.offset, Offset.zero);
|
||||
expect(shadows.single.color.a, lessThan(0.5));
|
||||
}
|
||||
expect(design.light().textTheme.bodyMedium!.shadows, isNull);
|
||||
}
|
||||
expect(AppDesign.terminal.dark().textTheme.bodyMedium!.shadows, isNull);
|
||||
});
|
||||
|
||||
testWidgets('chat colours become distinct brightness steps of the phosphor', (
|
||||
tester,
|
||||
) async {
|
||||
for (final design in _crts) {
|
||||
for (final brightness in Brightness.values) {
|
||||
final theme = _theme(design, brightness);
|
||||
late BuildContext context;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
// A fresh app per theme: no theme animation from the last one.
|
||||
key: UniqueKey(),
|
||||
theme: theme,
|
||||
home: Builder(
|
||||
builder: (c) {
|
||||
context = c;
|
||||
return const SizedBox();
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
final page = theme.colorScheme.surface;
|
||||
final shades = [
|
||||
for (final name in chatColorNames) chatColorShade(context, name)!,
|
||||
];
|
||||
expect(shades.toSet(), hasLength(chatColorNames.length));
|
||||
for (final shade in shades) {
|
||||
expect(_ofHue(shade, design.crtPhosphor!.hue), isTrue);
|
||||
expect(_contrast(shade, page), greaterThan(3));
|
||||
}
|
||||
final lum = [for (final s in shades) s.computeLuminance()];
|
||||
for (var i = 1; i < lum.length; i++) {
|
||||
expect(lum[i], isNot(lum[i - 1]));
|
||||
}
|
||||
expect(chatColorShade(context, null), isNull);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('failed and running tool lines take their own glyph without '
|
||||
'hue; Terminal keeps its dots', (tester) async {
|
||||
final row = transcriptRows([
|
||||
{
|
||||
'id': 'a1',
|
||||
'role': 'assistant',
|
||||
'parts': [
|
||||
_tool('t1', 'completed'),
|
||||
_tool('t2', 'error'),
|
||||
_tool('t3', 'running'),
|
||||
{'type': 'text', 'text': 'Done.'},
|
||||
],
|
||||
},
|
||||
]).single;
|
||||
Finder glyph(TerminalGlyphKind kind) =>
|
||||
find.byWidgetPredicate((w) => w is TerminalGlyph && w.kind == kind);
|
||||
for (final (design, cross, ring) in [
|
||||
(AppDesign.retroCrt, 1, 1),
|
||||
(AppDesign.terminal, 0, 0),
|
||||
]) {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: design.dark(),
|
||||
home: Scaffold(body: ChatMessageView(row: row)),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(glyph(TerminalGlyphKind.cross), findsNWidgets(cross));
|
||||
expect(glyph(TerminalGlyphKind.ring), findsNWidgets(ring));
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('the operator turn is Terminal\'s prompt line', (tester) async {
|
||||
final row = transcriptRows([
|
||||
{
|
||||
'id': 'u1',
|
||||
'role': 'user',
|
||||
'parts': [
|
||||
{'type': 'text', 'text': 'Fix it.'},
|
||||
],
|
||||
},
|
||||
]).single;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: AppDesign.retroCrt.dark(),
|
||||
themeMode: ThemeMode.dark,
|
||||
home: Scaffold(body: ChatMessageView(row: row)),
|
||||
),
|
||||
);
|
||||
expect(find.byType(TerminalPromptLine), findsOneWidget);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user