Merge branch 'worktree-agent-a2220433c67c864f1'
This commit is contained in:
@@ -27,6 +27,7 @@ class ChatShellRun {
|
||||
this.outputEnd = 0,
|
||||
this.outputBytes = 0,
|
||||
this.gap = false,
|
||||
this.snapshot = false,
|
||||
this.terminal = false,
|
||||
this.cols = 0,
|
||||
this.rows = 0,
|
||||
@@ -59,6 +60,11 @@ class ChatShellRun {
|
||||
/// stretch of what the command wrote.
|
||||
final bool gap;
|
||||
|
||||
/// True when [output] starts with the server's redraw of the terminal's
|
||||
/// state at [outputStart] (screens, scrollback, cursor and modes) instead
|
||||
/// of raw output: nothing earlier is missing from what it shows.
|
||||
final bool snapshot;
|
||||
|
||||
/// True when the command runs in a pseudo-terminal of [cols] x [rows]:
|
||||
/// [output] is then the raw terminal stream and it accepts typed input
|
||||
/// while it runs. Older runs (and servers without terminals) are plain.
|
||||
@@ -78,7 +84,7 @@ class ChatShellRun {
|
||||
final bool purged;
|
||||
|
||||
/// Whether earlier output is not shown here.
|
||||
bool get truncated => outputStart > 0 || gap;
|
||||
bool get truncated => !snapshot && (outputStart > 0 || gap);
|
||||
|
||||
ChatShellRunState get state => switch (status) {
|
||||
'running' => ChatShellRunState.running,
|
||||
@@ -144,6 +150,7 @@ class ChatShellRun {
|
||||
? next.outputBytes
|
||||
: outputBytes,
|
||||
gap: gap,
|
||||
snapshot: snapshot,
|
||||
terminal: next.terminal || terminal,
|
||||
cols: next.cols == 0 ? cols : next.cols,
|
||||
rows: next.rows == 0 ? rows : next.rows,
|
||||
@@ -180,6 +187,7 @@ class ChatShellRun {
|
||||
outputEnd: end,
|
||||
outputBytes: end > outputBytes ? end : outputBytes,
|
||||
gap: gap || dropped || (!contiguous && offset > 0),
|
||||
snapshot: snapshot && contiguous && !dropped,
|
||||
terminal: terminal,
|
||||
cols: cols,
|
||||
rows: rows,
|
||||
|
||||
@@ -113,8 +113,12 @@ class ChatShellTerminalSession {
|
||||
}
|
||||
|
||||
/// Draws [run]'s held output from scratch: on open, after a gap and after
|
||||
/// a readback replaced the card's copy. Answers the emulator gives to old
|
||||
/// queries in that output are not sent: the process asked them long ago.
|
||||
/// a readback replaced the card's copy. A machine terminal's read from
|
||||
/// before the server's tail is the server's snapshot
|
||||
/// ([ChatShellRun.snapshot]), which resets the emulator and restores the
|
||||
/// screens, scrollback, cursor and modes; it is drawn the same way.
|
||||
/// Answers the emulator gives to old queries in that output are not sent:
|
||||
/// the process asked them long ago.
|
||||
/// A large output is drawn in slices across turns of the event loop
|
||||
/// (ChatShellTerminalFeed), so it never stalls the UI.
|
||||
void replay(ChatShellRun run) {
|
||||
@@ -126,6 +130,9 @@ class ChatShellTerminalSession {
|
||||
terminal.useMainBuffer();
|
||||
terminal.buffer.clear();
|
||||
terminal.buffer.setCursor(0, 0);
|
||||
// A full reset (RIS): modes a program set in the output drawn before
|
||||
// (mouse reporting, bracketed paste, the alternate screen) end too.
|
||||
terminal.write('\x1bc');
|
||||
terminal.setCursorVisibleMode(true);
|
||||
terminal.write('\x1b[0m');
|
||||
if (run.truncated) {
|
||||
|
||||
@@ -25,17 +25,29 @@ class TerminalStream {
|
||||
int end = 0;
|
||||
String stream = '';
|
||||
|
||||
/// Whether [text] starts with the server's snapshot of the terminal's
|
||||
/// state at [start] rather than raw output (until its start is dropped).
|
||||
bool snapshot = false;
|
||||
|
||||
/// Whether nothing was received yet.
|
||||
bool get empty => stream.isEmpty && end == 0;
|
||||
|
||||
/// Replaces the held copy with a read of the server's retained tail,
|
||||
/// covering bytes [outputStart, outputEnd) (the server's offsets: the
|
||||
/// text's own UTF-8 length differs where invalid bytes were replaced).
|
||||
void reset(String output, int outputStart, int outputEnd, String name) {
|
||||
/// text's own UTF-8 length differs where invalid bytes were replaced), or
|
||||
/// with its [snapshot] of the terminal at [outputStart].
|
||||
void reset(
|
||||
String output,
|
||||
int outputStart,
|
||||
int outputEnd,
|
||||
String name, {
|
||||
bool snapshot = false,
|
||||
}) {
|
||||
text = output;
|
||||
start = outputStart;
|
||||
end = outputEnd;
|
||||
stream = name;
|
||||
this.snapshot = snapshot;
|
||||
_bound();
|
||||
}
|
||||
|
||||
@@ -59,6 +71,7 @@ class TerminalStream {
|
||||
if (unit >= 0xDC00 && unit <= 0xDFFF) cut++;
|
||||
final dropped = text.substring(0, cut);
|
||||
text = text.substring(cut);
|
||||
snapshot = false;
|
||||
// The server's offsets are not re-derived from the text: only the
|
||||
// dropped part is measured (approximately, for replaced bytes).
|
||||
start += utf8.encode(dropped).length;
|
||||
|
||||
@@ -95,6 +95,7 @@ class TerminalTab extends ChangeNotifier with TerminalTabEvents {
|
||||
output: _stream.text,
|
||||
outputStart: _stream.start,
|
||||
outputEnd: _stream.end,
|
||||
snapshot: _stream.snapshot,
|
||||
terminal: true,
|
||||
cols: _info.cols,
|
||||
rows: _info.rows,
|
||||
@@ -170,8 +171,12 @@ class TerminalTab extends ChangeNotifier with TerminalTabEvents {
|
||||
// The server counts this connection's window from the reply's end.
|
||||
_window = (record['window'] as num?)?.toInt() ?? 0;
|
||||
_acked = end;
|
||||
if (after == null || start > _stream.end) {
|
||||
_stream.reset(output, start, end, info.stream);
|
||||
// A read from before the server's retained tail (a new page, a reload,
|
||||
// a gap) is its snapshot of the terminal: the screens, scrollback,
|
||||
// cursor and modes as of the reply's end.
|
||||
final snapshot = record['output_snapshot'] == true;
|
||||
if (after == null || start > _stream.end || snapshot) {
|
||||
_stream.reset(output, start, end, info.stream, snapshot: snapshot);
|
||||
session.replay(_run());
|
||||
} else {
|
||||
_append(output, start, end);
|
||||
|
||||
Reference in New Issue
Block a user