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,208 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../../core/api_gateway.dart';
|
||||
import '../../../../../ui/theme/app_design_tokens.dart';
|
||||
import '../../../domain/chat_tool_calls.dart';
|
||||
import '../../../domain/chat_turn_activity.dart';
|
||||
import '../chat_response_pending.dart';
|
||||
import 'terminal_glyphs.dart';
|
||||
|
||||
/// How many of a turn's calls the transcript lists; earlier ones fold into
|
||||
/// one "earlier" line (every call stays in the details dialog).
|
||||
const int terminalActivityMaxCalls = 6;
|
||||
|
||||
/// A turn's activity under a terminal design, as a CLI agent prints it: one
|
||||
/// `● Tool(detail)` line per call, its status in the dot's colour, with a
|
||||
/// `⎿ result` line beneath, and while the turn runs a live status line.
|
||||
/// The block is one button that opens the activity details, like the
|
||||
/// Default design's one-line status.
|
||||
class TerminalActivityRows extends StatelessWidget {
|
||||
const TerminalActivityRows({
|
||||
super.key,
|
||||
required this.data,
|
||||
required this.status,
|
||||
required this.streaming,
|
||||
required this.onOpen,
|
||||
this.seconds = 0,
|
||||
});
|
||||
|
||||
final ChatTurnActivityData data;
|
||||
|
||||
/// The turn's one-line status (with its running seconds while streaming).
|
||||
final String status;
|
||||
final bool streaming;
|
||||
final VoidCallback onOpen;
|
||||
|
||||
/// How long the running turn has been doing what it does now.
|
||||
final int seconds;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final scheme = theme.colorScheme;
|
||||
final ansi = AppDesignTokens.of(context).ansi;
|
||||
final style = theme.textTheme.bodyMedium!;
|
||||
final dim = style.copyWith(color: scheme.onSurfaceVariant);
|
||||
final calls = data.tools;
|
||||
final shown = calls.length > terminalActivityMaxCalls
|
||||
? calls.sublist(calls.length - terminalActivityMaxCalls)
|
||||
: calls;
|
||||
final hidden = calls.length - shown.length;
|
||||
final lines = <Widget>[
|
||||
if (data.reasoning.isNotEmpty && calls.isEmpty && !streaming)
|
||||
_line(context, TerminalGlyphKind.dot, scheme.onSurfaceVariant, [
|
||||
TextSpan(text: 'Thought', style: dim),
|
||||
]),
|
||||
if (hidden > 0)
|
||||
_line(context, null, scheme.onSurfaceVariant, [
|
||||
TextSpan(
|
||||
text: '… +$hidden earlier tool ${hidden == 1 ? 'use' : 'uses'}',
|
||||
style: dim,
|
||||
),
|
||||
]),
|
||||
for (final call in shown) ..._call(context, call, style, dim, ansi),
|
||||
if (calls.isEmpty && data.reasoning.isEmpty && !streaming)
|
||||
_line(context, TerminalGlyphKind.dot, scheme.onSurfaceVariant, [
|
||||
TextSpan(text: status, style: dim),
|
||||
]),
|
||||
if (streaming) _live(context, style),
|
||||
];
|
||||
return Semantics(
|
||||
button: true,
|
||||
label: '$status, expand for details',
|
||||
excludeSemantics: true,
|
||||
onTap: onOpen,
|
||||
child: InkWell(
|
||||
key: const Key('chat-turn-activity'),
|
||||
onTap: onOpen,
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(minHeight: 40),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
child: DefaultTextStyle.merge(
|
||||
style: style,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: lines,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> _call(
|
||||
BuildContext context,
|
||||
JsonMap call,
|
||||
TextStyle style,
|
||||
TextStyle dim,
|
||||
AnsiAccents? ansi,
|
||||
) {
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final failed = chatToolFailed(call);
|
||||
final running = chatToolRunning(call);
|
||||
final color = failed
|
||||
? ansi?.red ?? scheme.error
|
||||
: running
|
||||
? ansi?.yellow ?? scheme.tertiary
|
||||
: ansi?.green ?? scheme.primary;
|
||||
final detail = chatToolDetail(call);
|
||||
final head = [
|
||||
TextSpan(
|
||||
text: chatToolLabel(call),
|
||||
style: style.copyWith(fontWeight: FontWeight.w700),
|
||||
),
|
||||
if (detail != null) TextSpan(text: '($detail)', style: dim),
|
||||
];
|
||||
final duration = chatToolDurationMillis(call);
|
||||
final String result;
|
||||
if (running) {
|
||||
result = 'running…';
|
||||
} else {
|
||||
final text = failed ? chatToolErrorText(call) : chatToolOutputText(call);
|
||||
final first = text
|
||||
.split('\n')
|
||||
.map((line) => line.trim())
|
||||
.firstWhere((line) => line.isNotEmpty, orElse: () => '');
|
||||
final more = text.trim().split('\n').length - 1;
|
||||
result = [
|
||||
if (first.isNotEmpty) first,
|
||||
if (more > 0) '+$more lines',
|
||||
if (duration != null) formatChatToolDuration(duration),
|
||||
].join(' · ');
|
||||
}
|
||||
return [
|
||||
_line(context, TerminalGlyphKind.dot, color, head),
|
||||
if (result.isNotEmpty)
|
||||
_line(context, TerminalGlyphKind.elbow, scheme.outline, [
|
||||
TextSpan(
|
||||
text: result,
|
||||
style: failed ? dim.copyWith(color: color) : dim,
|
||||
),
|
||||
], indent: true),
|
||||
];
|
||||
}
|
||||
|
||||
/// The running status: the pending dots, then what the turn is doing and
|
||||
/// for how long, in the accent colour.
|
||||
Widget _live(BuildContext context, TextStyle style) {
|
||||
final accent =
|
||||
AppDesignTokens.of(context).ansi?.yellow ??
|
||||
Theme.of(context).colorScheme.primary;
|
||||
return Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: terminalGlyphColumn(context),
|
||||
child: ExcludeSemantics(
|
||||
child: DefaultTextStyle.merge(
|
||||
style: TextStyle(color: accent),
|
||||
child: const Align(
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
child: ChatResponsePending(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Flexible(
|
||||
child: Text(
|
||||
'${data.label}… (${seconds}s)',
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: style.copyWith(color: accent),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _line(
|
||||
BuildContext context,
|
||||
TerminalGlyphKind? glyph,
|
||||
Color glyphColor,
|
||||
List<TextSpan> spans, {
|
||||
bool indent = false,
|
||||
}) {
|
||||
final column = terminalGlyphColumn(context);
|
||||
return Padding(
|
||||
padding: EdgeInsetsDirectional.only(start: indent ? column * 0.5 : 0),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (glyph == null)
|
||||
SizedBox(width: column)
|
||||
else
|
||||
TerminalGlyph(glyph, color: glyphColor),
|
||||
Flexible(
|
||||
child: Text.rich(
|
||||
TextSpan(children: spans),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// The width of a terminal transcript's glyph column: about two monospace
|
||||
/// cells of the ambient text, so lines after a glyph align like a CLI's.
|
||||
double terminalGlyphColumn(BuildContext context) {
|
||||
final style = DefaultTextStyle.of(context).style;
|
||||
final size = MediaQuery.textScalerOf(context).scale(style.fontSize ?? 14);
|
||||
return size * 1.3;
|
||||
}
|
||||
|
||||
/// The height of one line of the ambient text, so a painted glyph centres on
|
||||
/// the first line of the text beside it.
|
||||
double terminalLineHeight(BuildContext context, [TextStyle? style]) {
|
||||
final ambient = style ?? DefaultTextStyle.of(context).style;
|
||||
final size = MediaQuery.textScalerOf(context).scale(ambient.fontSize ?? 14);
|
||||
return size * (ambient.height ?? 1.35);
|
||||
}
|
||||
|
||||
/// The kind of mark a terminal transcript draws in its glyph column. They
|
||||
/// are painted rather than typed: the bundled monospace family has no
|
||||
/// record (U+25CF) or bracket corner (U+23BF), and the web engine would
|
||||
/// otherwise fetch a fallback font for them.
|
||||
enum TerminalGlyphKind {
|
||||
/// A filled dot: an answer, or a tool call (its colour gives the status).
|
||||
dot,
|
||||
|
||||
/// A bracket corner under a call: its result line.
|
||||
elbow,
|
||||
}
|
||||
|
||||
/// One painted terminal glyph, a glyph column wide and one text line tall,
|
||||
/// in [color].
|
||||
class TerminalGlyph extends StatelessWidget {
|
||||
const TerminalGlyph(this.kind, {super.key, required this.color, this.style});
|
||||
|
||||
final TerminalGlyphKind kind;
|
||||
final Color color;
|
||||
|
||||
/// The text the glyph sits beside; the ambient style when null.
|
||||
final TextStyle? style;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => ExcludeSemantics(
|
||||
child: SizedBox(
|
||||
width: terminalGlyphColumn(context),
|
||||
height: terminalLineHeight(context, style),
|
||||
child: CustomPaint(painter: _GlyphPainter(kind, color)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class _GlyphPainter extends CustomPainter {
|
||||
const _GlyphPainter(this.kind, this.color);
|
||||
|
||||
final TerminalGlyphKind kind;
|
||||
final Color color;
|
||||
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
final h = size.height;
|
||||
final paint = Paint()
|
||||
..color = color
|
||||
..isAntiAlias = true;
|
||||
switch (kind) {
|
||||
case TerminalGlyphKind.dot:
|
||||
canvas.drawCircle(Offset(h * 0.3, h / 2), h * 0.17, paint);
|
||||
case TerminalGlyphKind.elbow:
|
||||
paint
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = 1;
|
||||
final x = h * 0.3;
|
||||
final path = Path()
|
||||
..moveTo(x, 0)
|
||||
..lineTo(x, h * 0.55)
|
||||
..lineTo(size.width * 0.95, h * 0.55);
|
||||
canvas.drawPath(path, paint);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(_GlyphPainter old) =>
|
||||
old.kind != kind || old.color != color;
|
||||
}
|
||||
|
||||
/// [child] after a [glyph] in the glyph column, the glyph centred on the
|
||||
/// child's first line.
|
||||
class TerminalGlyphRow extends StatelessWidget {
|
||||
const TerminalGlyphRow({super.key, required this.glyph, required this.child});
|
||||
|
||||
final Widget glyph;
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
glyph,
|
||||
Expanded(child: child),
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../../ui/theme/app_design_tokens.dart';
|
||||
import '../../sessions/chat_color_palette.dart';
|
||||
import '../chat_message_bubble.dart';
|
||||
|
||||
/// How strongly a coloured chat's shade washes a prompt line's band.
|
||||
const double terminalPromptTint = 0.1;
|
||||
|
||||
/// The operator's turn under a terminal design: a prompt line, the prompt
|
||||
/// glyph then the message, over a faint band with a dim gutter on its
|
||||
/// leading edge (in the chat's colour when it has one). It spans the reading
|
||||
/// column instead of shrinking into a bubble.
|
||||
class TerminalPromptLine extends StatelessWidget {
|
||||
const TerminalPromptLine({super.key, required this.child});
|
||||
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final tokens = AppDesignTokens.of(context);
|
||||
final scheme = Theme.of(context).colorScheme;
|
||||
final shade = chatColorShade(context, ChatBubbleColor.of(context));
|
||||
final gutter = shade ?? scheme.outline;
|
||||
final glyph = shade ?? scheme.primary;
|
||||
return Material(
|
||||
key: const Key('chat-terminal-prompt-line'),
|
||||
// A faint wash of the chat's colour: its gutter and glyph carry it.
|
||||
color: shade == null
|
||||
? scheme.surfaceContainerLow
|
||||
: Color.alphaBlend(
|
||||
shade.withValues(alpha: terminalPromptTint),
|
||||
scheme.surfaceContainerLow,
|
||||
),
|
||||
shape: BorderDirectional(start: BorderSide(color: gutter, width: 2)),
|
||||
child: Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(10, 6, 12, 6),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ExcludeSemantics(
|
||||
child: Padding(
|
||||
padding: const EdgeInsetsDirectional.only(end: 10),
|
||||
child: Text(
|
||||
tokens.promptGlyph,
|
||||
style: chatMessageTextStyle(
|
||||
context,
|
||||
)?.copyWith(color: glyph, fontWeight: FontWeight.w700),
|
||||
),
|
||||
),
|
||||
),
|
||||
Flexible(child: child),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user