Merge branch 'worktree-agent-abb9404cc062f4b30'
This commit is contained in:
@@ -3,6 +3,7 @@ import '../ui/adaptive/window_margins.dart';
|
||||
import '../ui/theme/app_design_controller.dart';
|
||||
import '../ui/theme/glass_backdrop.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';
|
||||
|
||||
@@ -91,11 +92,14 @@ class MyApp extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
static Widget _scaled(BuildContext context, Widget? child) => DesignFocusRing(
|
||||
child: UiScaleHost(
|
||||
child: WindowMargins(
|
||||
child: GlassBackdrop(child: child ?? const SizedBox.shrink()),
|
||||
),
|
||||
),
|
||||
);
|
||||
static Widget _scaled(BuildContext context, Widget? child) =>
|
||||
DesignScreenOverlay(
|
||||
child: DesignFocusRing(
|
||||
child: UiScaleHost(
|
||||
child: WindowMargins(
|
||||
child: GlassBackdrop(child: child ?? const SizedBox.shrink()),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,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 '../../ui/theme/glass_backdrop.dart';
|
||||
import '../app_route.dart';
|
||||
import '../app_session.dart';
|
||||
@@ -224,10 +225,12 @@ class _DetachedWindowAppState extends State<DetachedWindowApp> {
|
||||
: '${_title.value} · Pipelines',
|
||||
scaffoldMessengerKey: appScaffoldMessengerKey,
|
||||
debugShowCheckedModeBanner: false,
|
||||
builder: (context, child) => DesignFocusRing(
|
||||
child: UiScaleHost(
|
||||
child: WindowMargins(
|
||||
child: GlassBackdrop(child: child ?? const SizedBox.shrink()),
|
||||
builder: (context, child) => DesignScreenOverlay(
|
||||
child: DesignFocusRing(
|
||||
child: UiScaleHost(
|
||||
child: WindowMargins(
|
||||
child: GlassBackdrop(child: child ?? const SizedBox.shrink()),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -20,6 +20,7 @@ import '../ui/scale/ui_scale.dart';
|
||||
import '../ui/theme/app_design_controller.dart';
|
||||
import '../ui/theme/glass_backdrop.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';
|
||||
@@ -386,10 +387,12 @@ class _PipelinesRootState extends State<PipelinesRoot> {
|
||||
listenable: Listenable.merge([fonts, designs]),
|
||||
builder: (context, _) => MaterialApp(
|
||||
title: 'Pipelines',
|
||||
builder: (context, child) => DesignFocusRing(
|
||||
child: UiScaleHost(
|
||||
child: WindowMargins(
|
||||
child: GlassBackdrop(child: child ?? const SizedBox.shrink()),
|
||||
builder: (context, child) => DesignScreenOverlay(
|
||||
child: DesignFocusRing(
|
||||
child: UiScaleHost(
|
||||
child: WindowMargins(
|
||||
child: GlassBackdrop(child: child ?? const SizedBox.shrink()),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -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<ArtifactTile> {
|
||||
// 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),
|
||||
|
||||
@@ -227,7 +227,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()
|
||||
|
||||
@@ -14,9 +14,17 @@ import '../../domain/chat_colors.dart';
|
||||
/// the shade lightened or darkened until it reaches that contrast against
|
||||
/// its page, so a chat's bar reads as plainly as text.
|
||||
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 tokens = AppDesignTokens.of(context);
|
||||
final contrast = tokens.minContrast;
|
||||
if (contrast != null) {
|
||||
final page = Theme.of(context).scaffoldBackgroundColor;
|
||||
@@ -58,6 +66,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;
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
|
||||
@@ -3,6 +3,8 @@ import 'package:flutter/material.dart';
|
||||
import 'app_design_tokens.dart';
|
||||
import 'app_theme.dart';
|
||||
import 'compact_theme.dart';
|
||||
import 'crt_palette.dart';
|
||||
import 'crt_theme.dart';
|
||||
import 'glass_theme.dart';
|
||||
import 'high_contrast_theme.dart';
|
||||
import 'notebook_theme.dart';
|
||||
@@ -85,6 +87,22 @@ enum AppDesign {
|
||||
'glass',
|
||||
'Glass',
|
||||
'Frosted panes over a soft gradient, rounded cards and gentle depth.',
|
||||
),
|
||||
|
||||
/// 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);
|
||||
@@ -142,6 +160,14 @@ enum AppDesign {
|
||||
(notebook, _) => notebookTheme(brightness, fontFamily: fontFamily),
|
||||
(highContrast, _) => highContrastTheme(brightness, fontFamily: fontFamily),
|
||||
(glass, _) => glassTheme(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 this design packs the interface densely
|
||||
@@ -152,7 +178,7 @@ enum AppDesign {
|
||||
|
||||
/// 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.
|
||||
@@ -231,6 +257,10 @@ enum AppDesign {
|
||||
Color(0xFF1A1A2B),
|
||||
Color(0xFF5546C7),
|
||||
),
|
||||
retroCrt || retroCrtAmber => () {
|
||||
final ramp = CrtRamp(crtPhosphor!, brightness);
|
||||
return DesignSwatch(ramp.page, ramp.text, ramp.accent);
|
||||
}(),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -165,3 +165,28 @@ class ReadingType {
|
||||
int get hashCode =>
|
||||
Object.hash(family, height, measure, scale, figureWidth, paragraphGap);
|
||||
}
|
||||
|
||||
/// A static pattern a design lays over the whole app, painted once into its
|
||||
/// own layer (see `DesignScreenOverlay`): horizontal scanlines. It never
|
||||
/// animates and never repaints with the content beneath it.
|
||||
@immutable
|
||||
class ScreenPattern {
|
||||
const ScreenPattern({required this.scanline, this.period = 3});
|
||||
|
||||
/// 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;
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
other is ScreenPattern &&
|
||||
other.scanline == scanline &&
|
||||
other.period == period;
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(scanline, period);
|
||||
}
|
||||
|
||||
@@ -68,6 +68,8 @@ class AppDesignTokens extends ThemeExtension<AppDesignTokens> {
|
||||
this.selectedRow = SelectedRowStyle.tonal,
|
||||
this.reading = const ReadingType(),
|
||||
this.chatColorSaturation = 1,
|
||||
this.monochrome,
|
||||
this.screen,
|
||||
this.stroke = 1,
|
||||
this.ringStroke = 2,
|
||||
this.focusRing,
|
||||
@@ -123,6 +125,16 @@ class AppDesignTokens extends ThemeExtension<AppDesignTokens> {
|
||||
/// 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); null paints nothing.
|
||||
final ScreenPattern? screen;
|
||||
|
||||
/// The width of the design's frames: [frameSide], flat panels, the
|
||||
/// composer pill and the floating bar pieces (High contrast's 2px).
|
||||
final double stroke;
|
||||
@@ -249,6 +261,8 @@ class AppDesignTokens extends ThemeExtension<AppDesignTokens> {
|
||||
SelectedRowStyle? selectedRow,
|
||||
ReadingType? reading,
|
||||
double? chatColorSaturation,
|
||||
Color? monochrome,
|
||||
ScreenPattern? screen,
|
||||
double? stroke,
|
||||
double? ringStroke,
|
||||
FocusRingStyle? focusRing,
|
||||
@@ -271,6 +285,8 @@ class AppDesignTokens extends ThemeExtension<AppDesignTokens> {
|
||||
selectedRow: selectedRow ?? this.selectedRow,
|
||||
reading: reading ?? this.reading,
|
||||
chatColorSaturation: chatColorSaturation ?? this.chatColorSaturation,
|
||||
monochrome: monochrome ?? this.monochrome,
|
||||
screen: screen ?? this.screen,
|
||||
stroke: stroke ?? this.stroke,
|
||||
ringStroke: ringStroke ?? this.ringStroke,
|
||||
focusRing: focusRing ?? this.focusRing,
|
||||
@@ -300,6 +316,8 @@ class AppDesignTokens extends ThemeExtension<AppDesignTokens> {
|
||||
other.selectedRow == selectedRow &&
|
||||
other.reading == reading &&
|
||||
other.chatColorSaturation == chatColorSaturation &&
|
||||
other.monochrome == monochrome &&
|
||||
other.screen == screen &&
|
||||
other.stroke == stroke &&
|
||||
other.ringStroke == ringStroke &&
|
||||
other.focusRing == focusRing &&
|
||||
@@ -324,6 +342,8 @@ class AppDesignTokens extends ThemeExtension<AppDesignTokens> {
|
||||
selectedRow,
|
||||
reading,
|
||||
chatColorSaturation,
|
||||
monochrome,
|
||||
screen,
|
||||
stroke,
|
||||
ringStroke,
|
||||
focusRing,
|
||||
|
||||
@@ -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),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
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))
|
||||
: ScreenPattern(scanline: ramp.text.withValues(alpha: 0.035)),
|
||||
// A blend into or out of the glow passes every text shadow through a
|
||||
// near-zero blur; in the browser (skwasm) that corrupted paragraph
|
||||
// layout and hung the page within a few live switches.
|
||||
snapSwitch: true,
|
||||
);
|
||||
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),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'app_design_tokens.dart';
|
||||
|
||||
/// [child] under the design's [AppDesignTokens.screen] pattern (Retro CRT's
|
||||
/// scanlines), 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]: its scanlines as one path of thin rectangles,
|
||||
/// snapped to device pixels and filled solid without anti-aliasing. One draw
|
||||
/// with no shader: a full-screen gradient (and a vignette tried with it)
|
||||
/// doubled the CPU raster time per frame in the browser bench, while solid
|
||||
/// bands touch only a third of the pixels and blend at memory speed.
|
||||
class ScreenPatternPainter extends CustomPainter {
|
||||
const ScreenPatternPainter(this.pattern, this.pixelRatio);
|
||||
|
||||
final ScreenPattern pattern;
|
||||
final double pixelRatio;
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size 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 height = band / pixelRatio;
|
||||
final lines = Path();
|
||||
for (var y = step - height; y < size.height; y += step) {
|
||||
lines.addRect(Rect.fromLTWH(0, y, size.width, height));
|
||||
}
|
||||
canvas.drawPath(
|
||||
lines,
|
||||
Paint()
|
||||
..color = pattern.scanline
|
||||
..isAntiAlias = false,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(ScreenPatternPainter old) =>
|
||||
old.pattern != pattern || old.pixelRatio != pixelRatio;
|
||||
}
|
||||
@@ -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<Brightness, Decoration> _tabIndicators = {};
|
||||
|
||||
const BorderRadius _corners = BorderRadius.all(Radius.circular(terminalRadius));
|
||||
final Map<Color, Decoration> _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<Shadow>? 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),
|
||||
|
||||
@@ -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<Shadow>? 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,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,136 @@
|
||||
# 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é). `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:
|
||||
one solid, non-anti-aliased path of thin rectangles, recorded once and
|
||||
re-recorded only on a resize, pixel-ratio or design change. No saveLayer,
|
||||
no shader, 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.
|
||||
- No vignette. The first version drew the scanlines as a full-screen
|
||||
repeating gradient plus a full-screen radial vignette; the browser bench
|
||||
showed those two shaded fills, replayed every frame, more than doubled the
|
||||
CPU raster time of scrolling (an experiment build with the overlay but no
|
||||
glow: 77 ms vs Terminal's 33 ms raster per frame; with the glow but no
|
||||
overlay: 30 ms, i.e. the glow is about free). Solid bands fixed it; the
|
||||
vignette was optional and is dropped.
|
||||
|
||||
## 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, and
|
||||
`snapSwitch: true` (High contrast's token): a live switch into or out of
|
||||
Retro CRT snaps instead of blending. Blending the glow lerps every text
|
||||
shadow through a near-zero blur, and in the browser bench's `design`
|
||||
scenario (rapid live switches) skwasm then threw "memory access out of
|
||||
bounds" in paragraph layout and the page stopped answering. An experiment
|
||||
build without the glow passed the same scenario; with the snap it passes
|
||||
with the glow.
|
||||
|
||||
## 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/ui/theme/compact_switch_test.dart` and
|
||||
`high_contrast_switch_test.dart` switch live into and out of both entries
|
||||
frame by frame.
|
||||
- `test/perf/design_bench_test.dart` picks up both entries; see the report
|
||||
for the browser bench.
|
||||
@@ -112,6 +112,8 @@ void main() {
|
||||
AppDesign.glass,
|
||||
AppDesign.compact,
|
||||
AppDesign.glass,
|
||||
AppDesign.retroCrt,
|
||||
AppDesign.retroCrtAmber,
|
||||
]) {
|
||||
design.value = other;
|
||||
for (var f = 0; f < 20; f++) {
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
@@ -255,11 +255,11 @@ void main() {
|
||||
expect(tokens.largeTargets, isFalse, reason: design.id);
|
||||
expect(tokens.minContrast, isNull, reason: design.id);
|
||||
expect(tokens.windowRadius, isNull, reason: design.id);
|
||||
// Glass snaps too: its clear pages do not blend with an opaque
|
||||
// design's.
|
||||
// Glass snaps too (its clear pages do not blend with an opaque
|
||||
// design's), and Retro CRT (a blended text glow hung skwasm).
|
||||
expect(
|
||||
tokens.snapSwitch,
|
||||
design == AppDesign.glass,
|
||||
design == AppDesign.glass || design.crtPhosphor != null,
|
||||
reason: design.id,
|
||||
);
|
||||
expect(tokens.transcript, isNot(TranscriptStyle.boxed));
|
||||
|
||||
@@ -0,0 +1,249 @@
|
||||
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);
|
||||
// Live switches snap: a blended glow hung skwasm.
|
||||
expect(tokens.snapSwitch, isTrue);
|
||||
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