89882d90f3
The card's output area is now an xterm.dart emulator kept per run by the controller: it is fed the raw stream in order, takes typing and paste while the command runs (with a key toolbar and a soft-keyboard field on touch platforms), resizes the process to its layout, opens printed links, shrinks finished runs to their output and opens full screen. A reconnect resumes from the byte the card holds; Copy output copies the server's plain text.
86 lines
3.2 KiB
Dart
86 lines
3.2 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
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, bool cupertino) {
|
|
final brightness = cupertino
|
|
? CupertinoTheme.brightnessOf(context)
|
|
: Theme.of(context).brightness;
|
|
final dark = brightness == Brightness.dark;
|
|
final background = chatCardFillColor(context, cupertino);
|
|
final foreground = cupertino
|
|
? CupertinoColors.label.resolveFrom(context)
|
|
: Theme.of(context).colorScheme.onSurface;
|
|
final accent = cupertino
|
|
? CupertinoTheme.of(context).primaryColor
|
|
: 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,
|
|
cupertino
|
|
? CupertinoColors.systemBackground.resolveFrom(context)
|
|
: 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, bool cupertino) {
|
|
final body = chatCardBodyStyle(context, cupertino) ?? const TextStyle();
|
|
return TerminalStyle(
|
|
fontFamily: appMonospaceFamily,
|
|
fontSize: (body.fontSize ?? 14) * 0.95,
|
|
height: 1.3,
|
|
);
|
|
}
|
|
|
|
/// The height of one terminal row in [style] at the context's text scale,
|
|
/// measured the way the emulator measures its cells.
|
|
double chatShellTerminalLineHeight(BuildContext context, TerminalStyle style) {
|
|
final painter = TextPainter(
|
|
text: TextSpan(text: 'mmmmmmmmmm', style: style.toTextStyle()),
|
|
textDirection: TextDirection.ltr,
|
|
textScaler: MediaQuery.textScalerOf(context),
|
|
)..layout();
|
|
final height = painter.height;
|
|
painter.dispose();
|
|
return height;
|
|
}
|