Draw chat shell runs in an xterm terminal that takes typed input

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.
This commit is contained in:
2026-11-09 20:08:33 +00:00
parent 355b722a1d
commit 89882d90f3
20 changed files with 1428 additions and 201 deletions
@@ -1,43 +1,5 @@
import 'package:flutter/widgets.dart';
/// The one layout bound of a shell command card: how tall its output area
/// may grow. Collapsed it shows about [kChatShellOutputCollapsedLines] lines
/// of the host's (scaled) monospace text; expanded it may take
/// [kChatShellOutputExpandedShare] of the window height. Everything else in
/// the card is content-sized.
/// The one layout bound of a shell command card: how many terminal rows its
/// output area shows. A running command's terminal has this many rows; a
/// finished one shrinks to the rows its output uses, up to this many, and
/// scrolls within them. Full screen takes the whole window instead.
const int kChatShellOutputCollapsedLines = 12;
const double kChatShellOutputExpandedShare = 0.6;
/// The monospace line height factor the output text is set at.
const double kChatShellOutputLineHeight = 1.35;
/// Characters of output drawn at once. A command can print far more than a
/// text layout should carry; the card says when it shows only the newest
/// part, and Copy output still copies everything the server kept.
const int kChatShellRenderedOutputLimit = 64 * 1024;
/// Whether [output] may be taller than the collapsed area, so Expand is worth
/// offering. Counted in lines, with long lines counted as wrapping.
bool chatShellOutputMayOverflow(String output) {
var lines = 0;
for (final line in output.split('\n')) {
lines += 1 + line.length ~/ 80;
if (lines > kChatShellOutputCollapsedLines) return true;
}
return false;
}
/// The output area's maximum height for this window, text scale and font.
double chatShellOutputMaxHeight(
BuildContext context, {
required double fontSize,
required bool expanded,
}) {
if (expanded) {
return MediaQuery.sizeOf(context).height * kChatShellOutputExpandedShare;
}
final line =
MediaQuery.textScalerOf(context).scale(fontSize) *
kChatShellOutputLineHeight;
return line * kChatShellOutputCollapsedLines;
}