214bbbc54f
Keep the existing Material terminal and chat-shell behavior while removing live Cupertino widgets, icon metadata, and alternate-host branches. Retain only the documented optional compatibility parameters until remaining callers migrate.
79 lines
3.0 KiB
Dart
79 lines
3.0 KiB
Dart
import 'dart:ui' as ui;
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:xterm/xterm.dart';
|
|
|
|
import '../../../ui/text/monospace.dart';
|
|
import '../conversation/chat_card_styles.dart';
|
|
|
|
/// The terminal's colours from the host theme: the card's inset surface as
|
|
/// background, the body text colour as foreground, the accent as cursor and
|
|
/// selection. The sixteen ANSI colours are the emulator's standard palette,
|
|
/// darkened on a light surface so coloured output stays readable.
|
|
TerminalTheme chatShellTerminalTheme(BuildContext context) {
|
|
final dark = Theme.of(context).brightness == Brightness.dark;
|
|
final background = chatCardFillColor(context, false);
|
|
final foreground = Theme.of(context).colorScheme.onSurface;
|
|
final accent = Theme.of(context).colorScheme.primary;
|
|
final base = TerminalThemes.defaultTheme;
|
|
Color ansi(Color color) {
|
|
if (dark) return color;
|
|
final hsl = HSLColor.fromColor(color);
|
|
return hsl.lightness > 0.4 ? hsl.withLightness(0.36).toColor() : color;
|
|
}
|
|
|
|
return TerminalTheme(
|
|
cursor: accent,
|
|
selection: accent.withValues(alpha: 0.35),
|
|
foreground: foreground,
|
|
// Opaque: the emulator paints cells over its own background.
|
|
background: Color.alphaBlend(
|
|
background,
|
|
Theme.of(context).colorScheme.surface,
|
|
),
|
|
black: dark ? base.black : foreground,
|
|
red: ansi(base.red),
|
|
green: ansi(base.green),
|
|
yellow: ansi(base.yellow),
|
|
blue: ansi(base.blue),
|
|
magenta: ansi(base.magenta),
|
|
cyan: ansi(base.cyan),
|
|
white: dark ? base.white : ansi(base.brightBlack),
|
|
brightBlack: ansi(base.brightBlack),
|
|
brightRed: ansi(base.brightRed),
|
|
brightGreen: ansi(base.brightGreen),
|
|
brightYellow: ansi(base.brightYellow),
|
|
brightBlue: ansi(base.brightBlue),
|
|
brightMagenta: ansi(base.brightMagenta),
|
|
brightCyan: ansi(base.brightCyan),
|
|
brightWhite: dark ? base.brightWhite : foreground,
|
|
searchHitBackground: base.searchHitBackground,
|
|
searchHitBackgroundCurrent: base.searchHitBackgroundCurrent,
|
|
searchHitForeground: base.searchHitForeground,
|
|
);
|
|
}
|
|
|
|
/// The terminal's text: the host's monospace family at the card body size.
|
|
TerminalStyle chatShellTerminalStyle(BuildContext context) {
|
|
final body = chatCardBodyStyle(context, false) ?? const TextStyle();
|
|
return TerminalStyle(
|
|
fontFamily: appMonospaceFamily,
|
|
fontSize: (body.fontSize ?? 14) * 0.95,
|
|
height: 1.3,
|
|
);
|
|
}
|
|
|
|
/// The size of one terminal cell in [style] at the context's text scale,
|
|
/// measured exactly as the emulator measures it.
|
|
Size chatShellTerminalCellSize(BuildContext context, TerminalStyle style) {
|
|
final text = style.toTextStyle();
|
|
final builder = ui.ParagraphBuilder(text.getParagraphStyle())
|
|
..pushStyle(text.getTextStyle(textScaler: MediaQuery.textScalerOf(context)))
|
|
..addText('mmmmmmmmmm');
|
|
final paragraph = builder.build()
|
|
..layout(const ui.ParagraphConstraints(width: double.infinity));
|
|
final size = Size(paragraph.maxIntrinsicWidth / 10, paragraph.height);
|
|
paragraph.dispose();
|
|
return size;
|
|
}
|