Merge branch 'worktree-agent-a2220433c67c864f1'
This commit is contained in:
@@ -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