Files
pipelines/app/lib/features/chat/shell/chat_shell_terminal_links.dart
alan 89882d90f3 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.
2026-11-09 20:08:33 +00:00

39 lines
1.4 KiB
Dart

import 'package:xterm/core.dart';
final RegExp _link = RegExp(r'''https?://[^\s<>"'`]+''');
/// The web link drawn at [offset] in [buffer], if any: the operator taps the
/// login URL an auth command printed. A link the terminal wrapped across
/// rows is joined first. Only http and https links are offered.
Uri? chatShellLinkAt(Buffer buffer, CellOffset offset) {
if (offset.y < 0 || offset.y >= buffer.height) return null;
var first = offset.y;
while (first > 0 && buffer.lines[first].isWrapped) {
first--;
}
var last = offset.y;
while (last + 1 < buffer.height && buffer.lines[last + 1].isWrapped) {
last++;
}
final text = StringBuffer();
var tapped = 0;
for (var y = first; y <= last; y++) {
final line = buffer.lines[y];
if (y == offset.y) tapped = text.length + offset.x;
for (var x = 0; x < line.length; x++) {
final code = line.getCodePoint(x);
// One character per cell keeps cell and string positions aligned.
text.write(code == 0 || code > 0xFFFF ? ' ' : String.fromCharCode(code));
}
}
for (final match in _link.allMatches(text.toString())) {
if (tapped < match.start || tapped >= match.end) continue;
final trimmed = match[0]!.replaceFirst(RegExp(r'[.,;:!?)\]}]+$'), '');
if (tapped >= match.start + trimmed.length) return null;
final uri = Uri.tryParse(trimmed);
if (uri == null || uri.host.isEmpty) return null;
return uri;
}
return null;
}