App: add a selectable app design with a Terminal look
AppDesign builds each design's light and dark ThemeData with an AppDesignTokens extension (corner radius, flat surfaces, frame colour, ANSI accents, prompt glyph). Settings gains a Design picker stored per device; the theme hosts rebuild live. Terminal is monospace (bundled RobotoMono), near-black or paper, flat 1px frames with 3px corners, and draws the chat transcript as prompt lines, tool dot/result lines and bracketed follow-up lines. Default keeps its exact themes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_design.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_design_controller.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
void main() {
|
||||
test('restore applies the stored design; unknown ids keep Default', () async {
|
||||
final stored = AppDesignController(store: MemoryAppDesignStore('terminal'));
|
||||
var notified = 0;
|
||||
stored.addListener(() => notified++);
|
||||
await stored.restore();
|
||||
expect(stored.design, AppDesign.terminal);
|
||||
expect(notified, 1);
|
||||
|
||||
final unknown = AppDesignController(store: MemoryAppDesignStore('neon'));
|
||||
await unknown.restore();
|
||||
expect(unknown.design, AppDesign.standard);
|
||||
});
|
||||
|
||||
test('select applies at once and stores the id', () async {
|
||||
final store = MemoryAppDesignStore();
|
||||
final designs = AppDesignController(store: store);
|
||||
final pending = designs.select(AppDesign.terminal);
|
||||
expect(designs.design, AppDesign.terminal);
|
||||
await pending;
|
||||
expect(store.id, 'terminal');
|
||||
expect(designs.saveFailed, isFalse);
|
||||
});
|
||||
|
||||
test('a failed save is reported and the choice still applies', () async {
|
||||
final store = MemoryAppDesignStore()..failSaves = true;
|
||||
final designs = AppDesignController(store: store);
|
||||
await designs.select(AppDesign.terminal);
|
||||
expect(designs.design, AppDesign.terminal);
|
||||
expect(designs.saveFailed, isTrue);
|
||||
store.failSaves = false;
|
||||
await designs.select(AppDesign.standard);
|
||||
expect(designs.saveFailed, isFalse);
|
||||
});
|
||||
|
||||
test('a choice made while restoring wins over the stored one', () async {
|
||||
final designs = AppDesignController(
|
||||
store: MemoryAppDesignStore('terminal'),
|
||||
);
|
||||
final restoring = designs.restore();
|
||||
await designs.select(AppDesign.standard);
|
||||
await restoring;
|
||||
expect(designs.design, AppDesign.standard);
|
||||
});
|
||||
|
||||
test('shared preferences keep the choice per device', () async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
const store = SharedPreferencesAppDesignStore();
|
||||
expect(await store.load(), isNull);
|
||||
expect(await store.save('terminal'), isTrue);
|
||||
expect(await store.load(), 'terminal');
|
||||
final designs = AppDesignController(store: store);
|
||||
await designs.restore();
|
||||
expect(designs.design, AppDesign.terminal);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/application/app.dart';
|
||||
import 'package:pipelines_app/shell/destination.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_controller.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_design_tokens.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_font_controller.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_font_store.dart';
|
||||
import 'package:pipelines_app/ui/theme/app_theme.dart';
|
||||
|
||||
void main() {
|
||||
test('ids round-trip and an unknown id is the Default design', () {
|
||||
for (final design in AppDesign.values) {
|
||||
expect(AppDesign.fromId(design.id), design);
|
||||
}
|
||||
expect(AppDesign.fromId(null), AppDesign.standard);
|
||||
expect(AppDesign.fromId('neon'), AppDesign.standard);
|
||||
expect(AppDesign.standard.id, 'default');
|
||||
});
|
||||
|
||||
test('the Default design builds exactly the existing themes', () {
|
||||
expect(AppDesign.standard.light(), appLightTheme());
|
||||
expect(AppDesign.standard.dark(), appDarkTheme());
|
||||
expect(
|
||||
AppDesign.standard.light(fontFamily: 'Inter'),
|
||||
appLightTheme(fontFamily: 'Inter'),
|
||||
);
|
||||
expect(AppDesign.standard.dark().extension<AppDesignTokens>(), isNull);
|
||||
});
|
||||
|
||||
test('Terminal is monospace, flat and near-black in dark', () {
|
||||
for (final brightness in Brightness.values) {
|
||||
final theme = brightness == Brightness.dark
|
||||
? AppDesign.terminal.dark(fontFamily: 'Inter')
|
||||
: AppDesign.terminal.light(fontFamily: 'Inter');
|
||||
final tokens = theme.extension<AppDesignTokens>()!;
|
||||
expect(tokens.terminal, isTrue);
|
||||
expect(tokens.flat, isTrue);
|
||||
expect(tokens.radius, lessThanOrEqualTo(4));
|
||||
expect(tokens.ansi, isNotNull);
|
||||
expect(theme.colorScheme.brightness, brightness);
|
||||
// The interface font choice does not apply: monospace everywhere.
|
||||
for (final style in [
|
||||
theme.textTheme.bodyLarge,
|
||||
theme.textTheme.titleMedium,
|
||||
theme.textTheme.labelLarge,
|
||||
]) {
|
||||
expect(style?.fontFamily, appMonospaceFamily);
|
||||
expect(style?.letterSpacing, 0);
|
||||
}
|
||||
expect(theme.cardTheme.elevation, 0);
|
||||
expect(theme.dialogTheme.elevation, 0);
|
||||
expect(theme.appBarTheme.scrolledUnderElevation, 0);
|
||||
final dialog = theme.dialogTheme.shape! as RoundedRectangleBorder;
|
||||
expect(dialog.borderRadius, BorderRadius.circular(tokens.radius!));
|
||||
expect(dialog.side.width, 1);
|
||||
}
|
||||
final dark = AppDesign.terminal.dark();
|
||||
expect(dark.scaffoldBackgroundColor.computeLuminance(), lessThan(0.01));
|
||||
final light = AppDesign.terminal.light();
|
||||
expect(light.scaffoldBackgroundColor.computeLuminance(), greaterThan(0.85));
|
||||
});
|
||||
|
||||
test('tokens reshape only under a design that sets a radius', () {
|
||||
const stadium = StadiumBorder();
|
||||
expect(AppDesignTokens.standard.shape(stadium), same(stadium));
|
||||
final terminal = AppDesign.terminal.dark().extension<AppDesignTokens>()!;
|
||||
final shaped = terminal.shape(stadium) as RoundedRectangleBorder;
|
||||
expect(shaped.borderRadius, BorderRadius.circular(terminal.radius!));
|
||||
});
|
||||
|
||||
testWidgets('the Material host switches design live, without a restart', (
|
||||
tester,
|
||||
) async {
|
||||
final designs = AppDesignController(store: MemoryAppDesignStore());
|
||||
final fonts = AppFontController(
|
||||
store: MemoryAppFontStore(),
|
||||
loader: (family, assets) async {},
|
||||
);
|
||||
late AppDesignTokens tokens;
|
||||
String? family;
|
||||
await tester.pumpWidget(
|
||||
MyApp(
|
||||
fonts: fonts,
|
||||
designs: designs,
|
||||
destination: AppDestination.settings,
|
||||
destinationBodies: <AppDestination, WidgetBuilder>{
|
||||
AppDestination.settings: (context) => Builder(
|
||||
builder: (context) {
|
||||
tokens = AppDesignTokens.of(context);
|
||||
family = DefaultTextStyle.of(context).style.fontFamily;
|
||||
return const Text('body');
|
||||
},
|
||||
),
|
||||
},
|
||||
),
|
||||
);
|
||||
expect(tokens.terminal, isFalse);
|
||||
expect(family, isNot(appMonospaceFamily));
|
||||
await designs.select(AppDesign.terminal);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tokens.terminal, isTrue);
|
||||
expect(family, appMonospaceFamily);
|
||||
await designs.select(AppDesign.standard);
|
||||
await tester.pumpAndSettle();
|
||||
expect(tokens.terminal, isFalse);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user