diff --git a/app/lib/application/app.dart b/app/lib/application/app.dart index 9b97b0d9..27229402 100644 --- a/app/lib/application/app.dart +++ b/app/lib/application/app.dart @@ -2,6 +2,7 @@ import '../ui/adaptive/window_margins.dart'; import '../ui/theme/app_design.dart'; import '../ui/theme/app_design_controller.dart'; import '../ui/theme/app_font_controller.dart'; +import '../ui/theme/design_screen_overlay.dart'; import '../ui/scale/ui_scale.dart'; import 'package:flutter/material.dart'; @@ -87,7 +88,10 @@ class MyApp extends StatelessWidget { ); } - static Widget _scaled(BuildContext context, Widget? child) => UiScaleHost( - child: WindowMargins(child: child ?? const SizedBox.shrink()), - ); + static Widget _scaled(BuildContext context, Widget? child) => + DesignScreenOverlay( + child: UiScaleHost( + child: WindowMargins(child: child ?? const SizedBox.shrink()), + ), + ); } diff --git a/app/lib/application/detached/detached_app.dart b/app/lib/application/detached/detached_app.dart index 7dd3126d..a5d1e0cf 100644 --- a/app/lib/application/detached/detached_app.dart +++ b/app/lib/application/detached/detached_app.dart @@ -14,6 +14,7 @@ import '../../ui/adaptive/window_margins.dart'; import '../../ui/scale/ui_scale.dart'; import '../../ui/theme/app_font_controller.dart'; import '../../ui/theme/app_design_controller.dart'; +import '../../ui/theme/design_screen_overlay.dart'; import '../app_route.dart'; import '../app_session.dart'; import '../app_terminals.dart'; @@ -218,8 +219,10 @@ class _DetachedWindowAppState extends State { : '${_title.value} · Pipelines', scaffoldMessengerKey: appScaffoldMessengerKey, debugShowCheckedModeBanner: false, - builder: (context, child) => UiScaleHost( - child: WindowMargins(child: child ?? const SizedBox.shrink()), + builder: (context, child) => DesignScreenOverlay( + child: UiScaleHost( + child: WindowMargins(child: child ?? const SizedBox.shrink()), + ), ), theme: designs.design.light(fontFamily: fonts.family), darkTheme: designs.design.dark(fontFamily: fonts.family), diff --git a/app/lib/application/pipelines_root.dart b/app/lib/application/pipelines_root.dart index 0694a204..65706198 100644 --- a/app/lib/application/pipelines_root.dart +++ b/app/lib/application/pipelines_root.dart @@ -18,6 +18,7 @@ import '../features/settings/settings_store.dart'; import '../ui/scale/ui_scale.dart'; import '../ui/theme/app_design_controller.dart'; import '../ui/theme/app_font_controller.dart'; +import '../ui/theme/design_screen_overlay.dart'; import 'detached/detached_app.dart'; import 'detached/detached_route.dart'; import 'pipelines_app.dart'; @@ -384,8 +385,10 @@ class _PipelinesRootState extends State { listenable: Listenable.merge([fonts, designs]), builder: (context, _) => MaterialApp( title: 'Pipelines', - builder: (context, child) => UiScaleHost( - child: WindowMargins(child: child ?? const SizedBox.shrink()), + builder: (context, child) => DesignScreenOverlay( + child: UiScaleHost( + child: WindowMargins(child: child ?? const SizedBox.shrink()), + ), ), theme: designs.design.light(fontFamily: fonts.family), darkTheme: designs.design.dark(fontFamily: fonts.family), diff --git a/app/lib/features/artifacts/ui/artifact_tile.dart b/app/lib/features/artifacts/ui/artifact_tile.dart index 4b5999df..f43289bf 100644 --- a/app/lib/features/artifacts/ui/artifact_tile.dart +++ b/app/lib/features/artifacts/ui/artifact_tile.dart @@ -1,3 +1,5 @@ +import 'dart:math' as math; + import 'package:flutter/material.dart'; import '../domain/artifact_groups.dart'; @@ -59,7 +61,7 @@ class _ArtifactTileState extends State { // Just inside the tile's frame: its corners less the line. borderRadius: BorderRadius.vertical( top: Radius.circular( - (AppDesignTokens.of(context).radius ?? 12) - 1, + math.max(0, (AppDesignTokens.of(context).radius ?? 12) - 1), ), ), child: ColoredBox(color: surface, child: preview), diff --git a/app/lib/features/chat/conversation/chat_send_usage_ring.dart b/app/lib/features/chat/conversation/chat_send_usage_ring.dart index b190dcf2..8d351778 100644 --- a/app/lib/features/chat/conversation/chat_send_usage_ring.dart +++ b/app/lib/features/chat/conversation/chat_send_usage_ring.dart @@ -217,7 +217,11 @@ class ChatUsageRingPainter extends CustomPainter { width: half * 2, height: half * 2, ); - final r = Radius.circular(corner + gap + stroke / 2); + // A square button (no corner radius) keeps a square ring; a rounded one + // a ring with its corners offset by the gap. + final r = corner <= 0 + ? Radius.zero + : Radius.circular(corner + gap + stroke / 2); final c = rect.center; // Built clockwise from the top centre, so the used length starts there. final path = Path() diff --git a/app/lib/features/chat/ui/sessions/chat_color_palette.dart b/app/lib/features/chat/ui/sessions/chat_color_palette.dart index e81b3c1d..4e7a01d5 100644 --- a/app/lib/features/chat/ui/sessions/chat_color_palette.dart +++ b/app/lib/features/chat/ui/sessions/chat_color_palette.dart @@ -9,9 +9,18 @@ import '../../domain/chat_colors.dart'; /// to the design's [AppDesignTokens.chatColorSaturation] (Paper's ink tones). /// Null for no (or an unknown) colour. Color? chatColorShade(BuildContext context, String? name) { + final tokens = AppDesignTokens.of(context); + final mono = tokens.monochrome; + if (mono != null) { + return chatMonochromeShade( + mono, + name, + Theme.of(context).brightness == Brightness.dark, + ); + } final shade = _materialShade(context, name); if (shade == null) return null; - final saturation = AppDesignTokens.of(context).chatColorSaturation; + final saturation = tokens.chatColorSaturation; if (saturation >= 1) return shade; final hsl = HSLColor.fromColor(shade); return hsl.withSaturation(hsl.saturation * saturation).toColor(); @@ -47,6 +56,20 @@ Color? _materialShade(BuildContext context, String? name) { }; } +/// A chat colour under a monochrome design ([AppDesignTokens.monochrome]): +/// hue is gone, so each name is its own brightness step of [phosphor], in +/// picker order from dimmest to brightest on a dark page (deepest to palest +/// ink on a light one), every step legible on the page. Null for no (or an +/// unknown) colour. +Color? chatMonochromeShade(Color phosphor, String? name, bool dark) { + final index = name == null ? -1 : chatColorNames.indexOf(name); + if (index < 0) return null; + final t = index / (chatColorNames.length - 1); + final hsl = HSLColor.fromColor(phosphor); + final lightness = dark ? 0.30 + t * 0.58 : 0.08 + t * 0.22; + return hsl.withLightness(lightness).withSaturation(1).toColor(); +} + /// Whether the surrounding theme is dark. bool chatColorDarkSurface(BuildContext context) => Theme.of(context).brightness == Brightness.dark; diff --git a/app/lib/features/chat/ui/transcript/terminal/terminal_activity_rows.dart b/app/lib/features/chat/ui/transcript/terminal/terminal_activity_rows.dart index c1dd0f36..13fe6000 100644 --- a/app/lib/features/chat/ui/transcript/terminal/terminal_activity_rows.dart +++ b/app/lib/features/chat/ui/transcript/terminal/terminal_activity_rows.dart @@ -133,8 +133,17 @@ class TerminalActivityRows extends StatelessWidget { if (duration != null) formatChatToolDuration(duration), ].join(' · '); } + // Without hue, a failed or running call also takes its own glyph. + final mono = AppDesignTokens.of(context).monochrome != null; + final glyph = !mono + ? TerminalGlyphKind.dot + : failed + ? TerminalGlyphKind.cross + : running + ? TerminalGlyphKind.ring + : TerminalGlyphKind.dot; return [ - _line(context, TerminalGlyphKind.dot, color, head), + _line(context, glyph, color, head), if (result.isNotEmpty) _line(context, TerminalGlyphKind.elbow, scheme.outline, [ TextSpan( diff --git a/app/lib/features/chat/ui/transcript/terminal/terminal_glyphs.dart b/app/lib/features/chat/ui/transcript/terminal/terminal_glyphs.dart index 5d20fd45..363923ff 100644 --- a/app/lib/features/chat/ui/transcript/terminal/terminal_glyphs.dart +++ b/app/lib/features/chat/ui/transcript/terminal/terminal_glyphs.dart @@ -26,6 +26,13 @@ enum TerminalGlyphKind { /// 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, @@ -74,6 +81,21 @@ class _GlyphPainter extends CustomPainter { ..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); } } diff --git a/app/lib/features/graph/widgets/graph_edge_hover.dart b/app/lib/features/graph/widgets/graph_edge_hover.dart index db5c239d..eb5713a2 100644 --- a/app/lib/features/graph/widgets/graph_edge_hover.dart +++ b/app/lib/features/graph/widgets/graph_edge_hover.dart @@ -221,8 +221,10 @@ Widget graphEdgeHighlight({ color: Theme.of(context).colorScheme.primary, strokeWidth: edgeWidth * 2.5, // A design's own corners (the stage cards take them) plus the - // glow's 5px spread; the Default keeps its rounder glow. + // glow's 5px spread; the Default keeps its rounder glow, and a + // square design (no corner radius) a square one. glowRadius: switch (AppDesignTokens.of(context).radius) { + final radius? when radius <= 0 => 0, final radius? => radius + 5, null => 14, }, diff --git a/app/lib/ui/theme/app_design.dart b/app/lib/ui/theme/app_design.dart index 99494e51..bf2c352b 100644 --- a/app/lib/ui/theme/app_design.dart +++ b/app/lib/ui/theme/app_design.dart @@ -2,6 +2,8 @@ import 'package:flutter/material.dart'; import 'app_design_tokens.dart'; import 'app_theme.dart'; +import 'crt_palette.dart'; +import 'crt_theme.dart'; import 'paper_theme.dart'; import 'terminal_theme.dart'; @@ -49,6 +51,22 @@ enum AppDesign { 'paper', 'Paper', 'Warm paper, serif reading text and ink colours; calm for long reads.', + ), + + /// Terminal's structure on a monochrome tube: green phosphor shades, square + /// frames, a faint glow and static scanlines; [retroCrtAmber] is the same + /// design in amber. + retroCrt( + 'retro-crt', + 'Retro CRT', + 'Terminal on a green phosphor tube: one hue, glow and scanlines.', + ), + + /// [retroCrt] in amber phosphor. + retroCrtAmber( + 'retro-crt-amber', + 'Retro CRT (amber)', + 'Terminal on an amber phosphor tube: one hue, glow and scanlines.', ); const AppDesign(this.id, this.label, this.description); @@ -94,17 +112,27 @@ enum AppDesign { /// Builds the design's theme for [brightness] from scratch, uncached; /// [light] and [dark] keep the result. - ThemeData build(Brightness brightness, {String? fontFamily}) => - switch ((this, brightness)) { - (standard, Brightness.light) => appLightTheme(fontFamily: fontFamily), - (standard, Brightness.dark) => appDarkTheme(fontFamily: fontFamily), - (terminal, _) => terminalTheme(brightness), - (paper, _) => paperTheme(brightness, fontFamily: fontFamily), - }; + ThemeData build(Brightness brightness, {String? fontFamily}) => switch (( + this, + brightness, + )) { + (standard, Brightness.light) => appLightTheme(fontFamily: fontFamily), + (standard, Brightness.dark) => appDarkTheme(fontFamily: fontFamily), + (terminal, _) => terminalTheme(brightness), + (paper, _) => paperTheme(brightness, fontFamily: fontFamily), + (retroCrt || retroCrtAmber, _) => crtTheme(crtPhosphor!, this, brightness), + }; + + /// The phosphor of a Retro CRT design; null for every other design. + CrtPhosphor? get crtPhosphor => switch (this) { + retroCrt => CrtPhosphor.green, + retroCrtAmber => CrtPhosphor.amber, + _ => null, + }; /// Whether the device's interface font applies under this design (Paper /// keeps it for its interface text and sets reading text in its serif). - bool get usesInterfaceFont => this != terminal; + bool get usesInterfaceFont => this != terminal && crtPhosphor == null; /// The picker's preview: the design's page, ink and accent in [brightness], /// without building its theme. @@ -147,6 +175,10 @@ enum AppDesign { Color(0xFF221E19), Color(0xFF2C4F86), ), + retroCrt || retroCrtAmber => () { + final ramp = CrtRamp(crtPhosphor!, brightness); + return DesignSwatch(ramp.page, ramp.text, ramp.accent); + }(), }; } } diff --git a/app/lib/ui/theme/app_design_styles.dart b/app/lib/ui/theme/app_design_styles.dart index ff36b944..8831db8a 100644 --- a/app/lib/ui/theme/app_design_styles.dart +++ b/app/lib/ui/theme/app_design_styles.dart @@ -103,3 +103,34 @@ class ReadingType { @override int get hashCode => Object.hash(family, height, measure, scale, figureWidth); } + +/// A static pattern a design lays over the whole app, painted once into its +/// own layer (see `DesignScreenOverlay`): horizontal scanlines and a soft +/// vignette darkening the corners. It never animates and never repaints with +/// the content beneath it. +@immutable +class ScreenPattern { + const ScreenPattern({required this.scanline, this.period = 3, this.vignette}); + + /// The colour of each scanline's dark band (a translucent shade). + final Color scanline; + + /// The distance between scanlines in device pixels; each dark band is a + /// third of it (at least one device pixel), so lines stay crisp at any + /// pixel ratio. + final int period; + + /// The colour the corners fade to, transparent at the centre; null for + /// no vignette. + final Color? vignette; + + @override + bool operator ==(Object other) => + other is ScreenPattern && + other.scanline == scanline && + other.period == period && + other.vignette == vignette; + + @override + int get hashCode => Object.hash(scanline, period, vignette); +} diff --git a/app/lib/ui/theme/app_design_tokens.dart b/app/lib/ui/theme/app_design_tokens.dart index 349fc00b..1c0e554b 100644 --- a/app/lib/ui/theme/app_design_tokens.dart +++ b/app/lib/ui/theme/app_design_tokens.dart @@ -65,6 +65,8 @@ class AppDesignTokens extends ThemeExtension { this.selectedRow = SelectedRowStyle.tonal, this.reading = const ReadingType(), this.chatColorSaturation = 1, + this.monochrome, + this.screen, }); /// The Classic design: every widget keeps its own shapes. @@ -111,6 +113,16 @@ class AppDesignTokens extends ThemeExtension { /// palette as is, lower to quieten it towards ink. final double chatColorSaturation; + /// The one hue of a monochrome design (Retro CRT's phosphor); null for a + /// design with colour. Under it chat colours become brightness steps of + /// this hue, and a status that only colour told apart (a failed or running + /// tool line) gets its own glyph too. + final Color? monochrome; + + /// A static pattern painted once over the whole app (Retro CRT's + /// scanlines and vignette); null paints nothing. + final ScreenPattern? screen; + /// Whether the transcript draws prompt and tool lines rather than bubbles. bool get terminal => transcript == TranscriptStyle.prompt; @@ -156,6 +168,8 @@ class AppDesignTokens extends ThemeExtension { SelectedRowStyle? selectedRow, ReadingType? reading, double? chatColorSaturation, + Color? monochrome, + ScreenPattern? screen, }) => AppDesignTokens( design: design ?? this.design, radius: radius ?? this.radius, @@ -169,6 +183,8 @@ class AppDesignTokens extends ThemeExtension { selectedRow: selectedRow ?? this.selectedRow, reading: reading ?? this.reading, chatColorSaturation: chatColorSaturation ?? this.chatColorSaturation, + monochrome: monochrome ?? this.monochrome, + screen: screen ?? this.screen, ); // Value equality keeps a rebuilt theme equal to the one it replaces, so @@ -188,7 +204,9 @@ class AppDesignTokens extends ThemeExtension { other.composer == composer && other.selectedRow == selectedRow && other.reading == reading && - other.chatColorSaturation == chatColorSaturation; + other.chatColorSaturation == chatColorSaturation && + other.monochrome == monochrome && + other.screen == screen; @override int get hashCode => Object.hash( @@ -204,6 +222,8 @@ class AppDesignTokens extends ThemeExtension { selectedRow, reading, chatColorSaturation, + monochrome, + screen, ); /// Designs switch whole: a theme animation snaps halfway rather than diff --git a/app/lib/ui/theme/crt_palette.dart b/app/lib/ui/theme/crt_palette.dart new file mode 100644 index 00000000..e26ccf4a --- /dev/null +++ b/app/lib/ui/theme/crt_palette.dart @@ -0,0 +1,118 @@ +import 'package:flutter/material.dart'; + +import 'app_design_tokens.dart'; + +/// A CRT phosphor: the one hue Retro CRT draws everything in, and how light +/// its normal text glows on the dark tube ([text] lightness), since equal +/// lightness looks brighter in amber than in green. +enum CrtPhosphor { + /// P1 green, `#33FF66` text on a green-black tube. + green(135, 0.60), + + /// P3 amber, `#FFAA00` text on a brown-black tube. + amber(40, 0.50); + + const CrtPhosphor(this.hue, this.text); + + /// The phosphor's hue in degrees. + final double hue; + + /// The HSL lightness of normal text on the dark tube. + final double text; + + /// The phosphor at [lightness] and [saturation]. + Color at(double lightness, [double saturation = 1]) => + HSLColor.fromAHSL(1, hue, saturation, lightness).toColor(); +} + +/// The lightness steps of one phosphor, darkest page to brightest glow (dark +/// tube) or palest page to deepest ink (paper-white phosphor in light). +/// Brightness, never hue, tells roles apart: dim secondary text, normal text, +/// a brighter accent, a brighter warning and the brightest error (each of +/// those statuses also has its own glyph or icon). +class CrtRamp { + CrtRamp(this.phosphor, this.brightness); + + final CrtPhosphor phosphor; + final Brightness brightness; + + bool get _dark => brightness == Brightness.dark; + + /// A surface step: pages and containers, barely tinted. + Color surface(double darkL, double lightL) => + phosphor.at(_dark ? darkL : lightL, _dark ? 0.45 : 0.40); + + Color get page => surface(0.03, 0.93); + Color get frame => phosphor.at(_dark ? 0.20 : 0.70, _dark ? 0.75 : 0.32); + Color get outline => phosphor.at(_dark ? 0.32 : 0.48, _dark ? 0.75 : 0.40); + Color get dim => phosphor.at(_dark ? 0.42 : 0.28, 0.70); + Color get text => phosphor.at(_dark ? phosphor.text : 0.17); + Color get accent => phosphor.at(_dark ? phosphor.text + 0.15 : 0.22); + Color get warning => phosphor.at(_dark ? phosphor.text + 0.20 : 0.12); + + /// Success sits below normal text: a finished call is the calm case, so + /// the brighter steps are left for what needs a look. + Color get success => phosphor.at(_dark ? phosphor.text - 0.16 : 0.28); + Color get error => phosphor.at(_dark ? 0.93 : 0.07); + + /// A container tone under [ink]: dark tube containers glow a little, the + /// light page's sit a step deeper than the page. + Color container(double darkL, double lightL) => + phosphor.at(_dark ? darkL : lightL, _dark ? 0.6 : 0.45); + + /// The status accents, as brightness steps: success a step below normal + /// text, running a step above it, waiting and warnings brighter, errors + /// brightest. + AnsiAccents get ansi => AnsiAccents( + green: success, + cyan: phosphor.at(_dark ? phosphor.text - 0.08 : 0.24), + yellow: warning, + red: error, + magenta: dim, + blue: accent, + ); +} + +/// Retro CRT's colour scheme for [phosphor] in [brightness]: every colour a +/// shade of the one hue. +ColorScheme crtColorScheme(CrtPhosphor phosphor, Brightness brightness) { + final r = CrtRamp(phosphor, brightness); + final page = r.page; + return ColorScheme( + brightness: brightness, + primary: r.accent, + onPrimary: page, + primaryContainer: r.container(0.14, 0.82), + onPrimaryContainer: r.accent, + secondary: r.text, + onSecondary: page, + secondaryContainer: r.container(0.11, 0.86), + onSecondaryContainer: r.text, + tertiary: r.warning, + onTertiary: page, + tertiaryContainer: r.container(0.17, 0.78), + onTertiaryContainer: r.warning, + error: r.error, + onError: page, + errorContainer: r.container(0.20, 0.74), + onErrorContainer: r.error, + surface: page, + onSurface: r.text, + onSurfaceVariant: r.dim, + surfaceDim: page, + surfaceBright: r.surface(0.14, 0.97), + surfaceContainerLowest: r.surface(0.02, 0.97), + surfaceContainerLow: r.surface(0.05, 0.90), + surfaceContainer: r.surface(0.065, 0.87), + surfaceContainerHigh: r.surface(0.08, 0.84), + surfaceContainerHighest: r.surface(0.10, 0.80), + outline: r.outline, + outlineVariant: r.frame, + shadow: const Color(0xFF000000), + scrim: const Color(0xFF000000), + inverseSurface: r.text, + onInverseSurface: page, + inversePrimary: r.dim, + surfaceTint: const Color(0x00000000), + ); +} diff --git a/app/lib/ui/theme/crt_theme.dart b/app/lib/ui/theme/crt_theme.dart new file mode 100644 index 00000000..6ba7e388 --- /dev/null +++ b/app/lib/ui/theme/crt_theme.dart @@ -0,0 +1,60 @@ +import 'package:flutter/material.dart'; + +import 'app_design.dart'; +import 'app_design_tokens.dart'; +import 'crt_palette.dart'; +import 'terminal_theme.dart'; + +/// Retro CRT's corner radius: square, like a character cell. +const double crtRadius = 0; + +/// The Retro CRT design's theme: Terminal's structure (monospace, prompt +/// transcript, flat framed surfaces) in one [phosphor]'s shades, square +/// corners, 1px phosphor frames, a faint glow under every text role and a +/// static scanline pattern over the app ([AppDesignTokens.screen]). +/// +/// Dark is the tube: the phosphor glowing on near-black. Light is a +/// "paper-white phosphor": deep phosphor ink on a pale tinted page, without +/// glow (a halo round dark ink reads as smudge) and with scanlines faint +/// enough to read as texture only. +ThemeData crtTheme( + CrtPhosphor phosphor, + AppDesign design, + Brightness brightness, +) { + final scheme = crtColorScheme(phosphor, brightness); + final ramp = CrtRamp(phosphor, brightness); + final dark = brightness == Brightness.dark; + final tokens = AppDesignTokens( + design: design, + radius: crtRadius, + flat: true, + frame: scheme.outlineVariant, + panel: scheme.surfaceContainerLow, + ansi: ramp.ansi, + transcript: TranscriptStyle.prompt, + selectedRow: SelectedRowStyle.framed, + monochrome: ramp.text, + screen: dark + ? const ScreenPattern( + scanline: Color(0x29000000), + vignette: Color(0x47000000), + ) + : ScreenPattern(scanline: ramp.text.withValues(alpha: 0.035)), + ); + final theme = terminalStructureTheme( + scheme, + tokens, + glow: dark + ? [Shadow(color: ramp.text.withValues(alpha: 0.38), blurRadius: 3)] + : null, + ); + return theme.copyWith( + textSelectionTheme: TextSelectionThemeData( + cursorColor: scheme.primary, + selectionColor: ramp.text.withValues(alpha: dark ? 0.28 : 0.22), + selectionHandleColor: scheme.primary, + ), + iconTheme: theme.iconTheme.copyWith(color: scheme.onSurface), + ); +} diff --git a/app/lib/ui/theme/design_screen_overlay.dart b/app/lib/ui/theme/design_screen_overlay.dart new file mode 100644 index 00000000..3ee8dcdf --- /dev/null +++ b/app/lib/ui/theme/design_screen_overlay.dart @@ -0,0 +1,97 @@ +import 'dart:ui' as ui; + +import 'package:flutter/material.dart'; + +import 'app_design_tokens.dart'; + +/// [child] under the design's [AppDesignTokens.screen] pattern (Retro CRT's +/// scanlines and vignette), or [child] alone under a design without one. +/// +/// The pattern is one [CustomPaint] in its own [RepaintBoundary]: it paints +/// once (again only on a resize, a pixel-ratio change or a design switch) +/// and the compositor reuses its picture every frame. It adds no saveLayer, +/// no filter and no animation, ignores the pointer and has no semantics. +/// [child] stays the Stack's first child either way, so switching to or +/// from a patterned design never remounts the app beneath. +class DesignScreenOverlay extends StatelessWidget { + const DesignScreenOverlay({super.key, required this.child}); + + final Widget child; + + @override + Widget build(BuildContext context) { + final pattern = AppDesignTokens.of(context).screen; + return Stack( + fit: StackFit.passthrough, + children: [ + child, + if (pattern != null) + Positioned.fill( + child: IgnorePointer( + child: RepaintBoundary( + key: const Key('design-screen-overlay'), + child: CustomPaint( + painter: ScreenPatternPainter( + pattern, + MediaQuery.devicePixelRatioOf(context), + ), + ), + ), + ), + ), + ], + ); + } +} + +/// Paints a [ScreenPattern]: one rectangle filled with a hard-stopped, +/// repeating vertical gradient (the scanlines, snapped to device pixels) and +/// one with a radial gradient (the vignette). Two draws, no layers. +class ScreenPatternPainter extends CustomPainter { + const ScreenPatternPainter(this.pattern, this.pixelRatio); + + final ScreenPattern pattern; + final double pixelRatio; + + @override + void paint(Canvas canvas, Size size) { + final rect = Offset.zero & size; + final period = pattern.period.clamp(2, 12); + final band = (period / 3).round().clamp(1, period - 1); + // In logical pixels, on device-pixel boundaries. + final step = period / pixelRatio; + final clear = (period - band) / period; + canvas.drawRect( + rect, + Paint() + ..shader = ui.Gradient.linear( + Offset.zero, + Offset(0, step), + [ + const Color(0x00000000), + const Color(0x00000000), + pattern.scanline, + pattern.scanline, + ], + [0, clear, clear, 1], + TileMode.repeated, + ), + ); + final vignette = pattern.vignette; + if (vignette == null) return; + canvas.drawRect( + rect, + Paint() + ..shader = ui.Gradient.radial( + rect.center, + size.longestSide * 0.75, + [const Color(0x00000000), const Color(0x00000000), vignette], + [0, 0.55, 1], + ), + ); + } + + @override + bool shouldRepaint(ScreenPatternPainter old) => + old.pattern != pattern || old.pixelRatio != pixelRatio; +} diff --git a/app/lib/ui/theme/terminal_theme.dart b/app/lib/ui/theme/terminal_theme.dart index de6dcf7a..8f934f22 100644 --- a/app/lib/ui/theme/terminal_theme.dart +++ b/app/lib/ui/theme/terminal_theme.dart @@ -12,11 +12,9 @@ import 'terminal_typography.dart'; /// enough not to alias. const double terminalRadius = 3; -/// One tab indicator per brightness: [UnderlineTabIndicator] compares by +/// One tab indicator per accent: [UnderlineTabIndicator] compares by /// identity, so a fresh one would make a rebuilt theme unequal to the last. -final Map _tabIndicators = {}; - -const BorderRadius _corners = BorderRadius.all(Radius.circular(terminalRadius)); +final Map _tabIndicators = {}; /// The Terminal design's theme: the bundled monospace family everywhere, /// compact text, flat surfaces with 1px dim frames and no elevation, and @@ -28,9 +26,37 @@ ThemeData terminalTheme(Brightness brightness) { final ansi = brightness == Brightness.dark ? terminalDarkAnsi : terminalLightAnsi; - final frame = BorderSide(color: scheme.outlineVariant); - final framed = RoundedRectangleBorder(borderRadius: _corners, side: frame); - const square = RoundedRectangleBorder(borderRadius: _corners); + return terminalStructureTheme( + scheme, + AppDesignTokens( + design: AppDesign.terminal, + radius: terminalRadius, + flat: true, + frame: scheme.outlineVariant, + ansi: ansi, + transcript: TranscriptStyle.prompt, + selectedRow: SelectedRowStyle.framed, + ), + ); +} + +/// Terminal's structure over [scheme]: monospace text, flat framed surfaces, +/// no elevation and the same corners on every Material component. [tokens] +/// is the design's extension; its [AppDesignTokens.radius] shapes every +/// corner and its [AppDesignTokens.frame] every hairline. A design built on +/// Terminal (Retro CRT) passes its own scheme and tokens, and [glow] for a +/// shadow under every text role. +ThemeData terminalStructureTheme( + ColorScheme scheme, + AppDesignTokens tokens, { + List? glow, +}) { + final corners = BorderRadius.all( + Radius.circular(tokens.radius ?? terminalRadius), + ); + final frame = BorderSide(color: tokens.frame ?? scheme.outlineVariant); + final framed = RoundedRectangleBorder(borderRadius: corners, side: frame); + final square = RoundedRectangleBorder(borderRadius: corners); final base = ThemeData( platform: kIsWeb ? TargetPlatform.android : null, colorScheme: scheme, @@ -42,21 +68,11 @@ ThemeData terminalTheme(Brightness brightness) { splashFactory: NoSplash.splashFactory, shadowColor: const Color(0x00000000), dividerColor: scheme.outlineVariant, - extensions: [ - AppDesignTokens( - design: AppDesign.terminal, - radius: terminalRadius, - flat: true, - frame: scheme.outlineVariant, - ansi: ansi, - transcript: TranscriptStyle.prompt, - selectedRow: SelectedRowStyle.framed, - ), - ], + extensions: [tokens], ); ButtonStyle buttons(ButtonStyle? style) => (style ?? const ButtonStyle()).copyWith( - shape: const WidgetStatePropertyAll(square), + shape: WidgetStatePropertyAll(square), elevation: const WidgetStatePropertyAll(0), shadowColor: const WidgetStatePropertyAll(Color(0x00000000)), ); @@ -67,14 +83,14 @@ ThemeData terminalTheme(Brightness brightness) { surfaceTintColor: const WidgetStatePropertyAll(Color(0x00000000)), shape: WidgetStatePropertyAll( RoundedRectangleBorder( - borderRadius: _corners, + borderRadius: corners, side: BorderSide(color: scheme.outline), ), ), ); return base.copyWith( - textTheme: terminalTextTheme(base.textTheme), - primaryTextTheme: terminalTextTheme(base.primaryTextTheme), + textTheme: terminalTextTheme(base.textTheme, glow: glow), + primaryTextTheme: terminalTextTheme(base.primaryTextTheme, glow: glow), appBarTheme: AppBarTheme( backgroundColor: scheme.surface, surfaceTintColor: const Color(0x00000000), @@ -95,7 +111,7 @@ ThemeData terminalTheme(Brightness brightness) { surfaceTintColor: const Color(0x00000000), elevation: 0, shape: RoundedRectangleBorder( - borderRadius: _corners, + borderRadius: corners, side: BorderSide(color: scheme.outline), ), ), @@ -106,7 +122,7 @@ ThemeData terminalTheme(Brightness brightness) { elevation: 0, modalElevation: 0, shape: RoundedRectangleBorder( - borderRadius: _corners, + borderRadius: corners, side: BorderSide(color: scheme.outline), ), ), @@ -115,7 +131,7 @@ ThemeData terminalTheme(Brightness brightness) { surfaceTintColor: const Color(0x00000000), elevation: 0, shape: RoundedRectangleBorder( - borderRadius: _corners, + borderRadius: corners, side: BorderSide(color: scheme.outline), ), ), @@ -152,7 +168,7 @@ ThemeData terminalTheme(Brightness brightness) { backgroundColor: scheme.surfaceContainerHigh, foregroundColor: scheme.primary, shape: RoundedRectangleBorder( - borderRadius: _corners, + borderRadius: corners, side: BorderSide(color: scheme.outline), ), ), @@ -168,13 +184,13 @@ ThemeData terminalTheme(Brightness brightness) { inputDecorationTheme: InputDecorationTheme( isDense: true, border: OutlineInputBorder( - borderRadius: _corners, + borderRadius: corners, borderSide: BorderSide(color: scheme.outline), ), ), searchBarTheme: SearchBarThemeData( elevation: const WidgetStatePropertyAll(0), - shape: const WidgetStatePropertyAll(square), + shape: WidgetStatePropertyAll(square), side: WidgetStatePropertyAll(BorderSide(color: scheme.outline)), backgroundColor: WidgetStatePropertyAll(scheme.surfaceContainerLow), ), @@ -191,7 +207,7 @@ ThemeData terminalTheme(Brightness brightness) { indicatorShape: square, surfaceTintColor: const Color(0x00000000), ), - listTileTheme: const ListTileThemeData(shape: square), + listTileTheme: ListTileThemeData(shape: square), dividerTheme: DividerThemeData( color: scheme.outlineVariant, thickness: 1, @@ -200,7 +216,7 @@ ThemeData terminalTheme(Brightness brightness) { tabBarTheme: TabBarThemeData( dividerColor: scheme.outlineVariant, indicatorSize: TabBarIndicatorSize.tab, - indicator: _tabIndicators[brightness] ??= UnderlineTabIndicator( + indicator: _tabIndicators[scheme.primary] ??= UnderlineTabIndicator( borderSide: BorderSide(color: scheme.primary, width: 2), ), ), @@ -209,23 +225,25 @@ ThemeData terminalTheme(Brightness brightness) { contentTextStyle: TextStyle( color: scheme.onSurface, fontFamily: appMonospaceFamily, + shadows: glow, ), elevation: 0, shape: RoundedRectangleBorder( - borderRadius: _corners, + borderRadius: corners, side: BorderSide(color: scheme.outline), ), ), tooltipTheme: TooltipThemeData( decoration: BoxDecoration( color: scheme.surfaceContainerHighest, - borderRadius: _corners, + borderRadius: corners, border: Border.all(color: scheme.outline), ), textStyle: TextStyle( color: scheme.onSurface, fontFamily: appMonospaceFamily, fontSize: 12, + shadows: glow, ), ), scrollbarTheme: const ScrollbarThemeData(radius: Radius.zero), diff --git a/app/lib/ui/theme/terminal_typography.dart b/app/lib/ui/theme/terminal_typography.dart index eb6fe27c..082f6ef3 100644 --- a/app/lib/ui/theme/terminal_typography.dart +++ b/app/lib/ui/theme/terminal_typography.dart @@ -3,8 +3,9 @@ import 'package:flutter/material.dart'; import '../text/monospace.dart'; /// [base] in the monospace family at a terminal's compact size: Material's -/// roles a step smaller (monospace runs wide), with no added letter spacing. -TextTheme terminalTextTheme(TextTheme base) { +/// roles a step smaller (monospace runs wide), with no added letter spacing, +/// and [glow] (Retro CRT's phosphor halo) as every role's shadow. +TextTheme terminalTextTheme(TextTheme base, {List? glow}) { TextStyle? mono(TextStyle? style) { if (style == null) return null; final size = style.fontSize; @@ -12,6 +13,7 @@ TextTheme terminalTextTheme(TextTheme base) { fontFamily: appMonospaceFamily, fontSize: size == null ? null : (size * 0.875).roundToDouble(), letterSpacing: 0, + shadows: glow, ); } diff --git a/app/notes/design-retro-crt.md b/app/notes/design-retro-crt.md new file mode 100644 index 00000000..9ec71f8c --- /dev/null +++ b/app/notes/design-retro-crt.md @@ -0,0 +1,119 @@ +# Retro CRT design + +Terminal on a monochrome tube (Settings > Design > Retro CRT, or Retro CRT +(amber); the Alt+L switcher lists both). Everything Terminal draws (the +prompt line, glyph-led tool rows, framed list rows, flat framed panels, the +monospace family) is reused as is; only the colours, the corners, a text glow +and a static scanline pattern change. + +## Variants + +Amber is a second registry entry (`retro-crt-amber`), not an option: one enum +value and no new setting, store or UI. Both entries build through +`crtTheme(phosphor, design, brightness)`; `AppDesign.crtPhosphor` names the +phosphor (`CrtPhosphor.green`, hue 135, `#33FF66` text; `CrtPhosphor.amber`, +hue 40, `#FFAA00` text). + +## Palette (`crt_palette.dart`) + +Every colour is a shade of the one phosphor hue (`CrtRamp`). Roles differ by +brightness only: + +| role | dark tube | light (paper-white phosphor) | +| --- | --- | --- | +| page / containers | L 3–10 %, barely tinted | L 80–97 %, pale tint | +| frames (`outlineVariant`) / `outline` | L 20 % / 32 % | L 70 % / 48 % | +| secondary text (`onSurfaceVariant`) | L 42 % | L 28 % | +| text (`onSurface`) | `#33FF66` / `#FFAA00` | L 17 % ink | +| accent (`primary`) | text + 15 % | L 22 % | +| warning (`tertiary`, ANSI yellow) | text + 20 % | L 12 % | +| error | L 93 % (near white) | L 7 % (near black) | +| success (ANSI green) | text − 16 % | L 28 % | + +Status is never told by hue alone: run states already pair a distinct icon +with each colour (`RunStatusIcon`), and under a monochrome design a failed +tool line draws a cross and a running one a hollow ring instead of the dot +(`TerminalGlyphKind.cross` / `ring`). Errors are also the brightest text. + +Chat colours (`chatMonochromeShade`): each of the 13 names is its own +brightness step of the phosphor in picker order (L 30–88 % on the tube, 8–30 % +ink on the light page), every step at least 3:1 on the page. Thirteen steps of +one hue are distinct but close; neighbouring names are hard to tell apart, +which is the honest cost of a monochrome palette. + +## Light mode + +A "paper-white phosphor": deep phosphor ink on a pale tinted page, with the +same roles and frames. No glow (a halo around dark ink reads as a smudge) and +scanlines at 3.5 % ink, a texture only. Chosen over a dark-only fallback so a +device in light mode still gets a light page. + +## Glow and screen + +- Glow: one `Shadow` (phosphor at 38 % alpha, blur 3, no offset) on every + text role, tooltip and snack bar text, in dark only. It is a per-glyph mask + blur in the text draw, not a layer filter. +- Screen (`AppDesignTokens.screen`, `ScreenPattern`): scanlines every 3 + device pixels (a 1-device-pixel band of 16 % black; snapped to device + pixels so they never moiré) and a vignette fading the corners to 28 % + black. `DesignScreenOverlay` (in the `MaterialApp.builder` of the app, the + connect flow and detached windows) paints it with one `CustomPaint` in its + own `RepaintBoundary` above everything (menus and dialogs included), + `IgnorePointer`, no semantics: two gradient-filled rectangles, painted + once, repainted only on a resize, pixel-ratio or design change. No + saveLayer, no filter, no animation (so nothing for reduced motion to stop). + The app stays the Stack's first child, so a design switch does not remount + it. + +## Tokens added to `AppDesignTokens` (defaults keep every other design) + +- `monochrome` (`Color?`, default null): the one hue; chat colours become its + brightness steps and hue-only statuses get glyphs. +- `screen` (`ScreenPattern?`, default null): the static overlay pattern. + +Retro CRT also sets: `radius: 0`, `flat`, `frame: outlineVariant`, `panel: +surfaceContainerLow`, `ansi` (brightness steps above), `transcript: prompt`, +`selectedRow: framed`, the default `pill` composer and `>` prompt glyph. + +## Terminal reuse + +`terminalTheme` is now `terminalStructureTheme(scheme, tokens, {glow})` +called with Terminal's scheme and tokens (Terminal's theme is value-equal to +before); the corners come from `tokens.radius`, the frame from +`tokens.frame`, and the tab indicator cache keys on the accent instead of +the brightness. `terminalTextTheme` takes the optional glow. + +## Square details + +- Corners 0 everywhere the theme reaches (buttons, chips, menus, dialogs, + sheets, tooltips, snack bars, inputs, cards, nav indicators, stack discs + and labels, count badges). +- Send button usage ring: a square button keeps a square ring (radius 0, not + the gap-offset 4 px), 3 px clear gap. +- Graph edge hover: the stage glow is square under a 0 radius. +- Artifact tile thumbnails: the inner clip radius clamps at 0 (it was + `radius - 1`, negative under a square design). + +## Still default / known gaps + +- Terminal's own spacings are kept, including the prompt line's 10/6/12 px + padding (off the 4/8 grid); changing them would change Terminal. +- The design picker's swatch previews keep their 6 px corners (they preview + every design), and Material `Badge` counts (Artifacts) stay round: the + badge theme has no shape. +- The text cursor is the theme's line cursor in the accent colour; a block + cursor needs a per-field `cursorWidth`, not a theme value. +- Snack bars follow the theme (square, framed, glowing text) but were not + captured. +- Code and diff syntax colours keep their own palette where they set one. + +## Checks + +- `test/ui/theme/retro_crt_design_test.dart`: registry, tokens, one hue, + contrast (text > 7:1, secondary > 4.5:1), status brightness steps, glow, + chat colour steps, cross/ring glyphs (and Terminal keeps dots). +- `test/ui/theme/design_screen_overlay_test.dart`: the pattern is one + boundary, adds no saveLayer, is not repainted while content scrolls, lets + pointers through, and a design switch does not remount the app. +- `test/perf/design_bench_test.dart` picks up both entries; see the report + for the browser bench. diff --git a/app/test/ui/theme/design_screen_overlay_test.dart b/app/test/ui/theme/design_screen_overlay_test.dart new file mode 100644 index 00000000..8ab109ff --- /dev/null +++ b/app/test/ui/theme/design_screen_overlay_test.dart @@ -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(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()! + .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()! + .screen!; + expect(painter.shouldRepaint(ScreenPatternPainter(amber, 2)), isTrue); + }); +} diff --git a/app/test/ui/theme/retro_crt_design_test.dart b/app/test/ui/theme/retro_crt_design_test.dart new file mode 100644 index 00000000..c020c72a --- /dev/null +++ b/app/test/ui/theme/retro_crt_design_test.dart @@ -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()!; + 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.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()!.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); + }); +}