Merge branch 'worktree-agent-ab9de97501bc94a9c'
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -26,7 +26,9 @@ class TerminalTab extends ChangeNotifier {
|
||||
session = ChatShellTerminalSession(
|
||||
_run(),
|
||||
onInput: _input,
|
||||
onReply: (data) => _input(data, reply: true),
|
||||
onResize: _resized,
|
||||
onActivate: _activated,
|
||||
);
|
||||
session.terminal.onTitleChange = _titled;
|
||||
}
|
||||
@@ -85,6 +87,10 @@ class TerminalTab extends ChangeNotifier {
|
||||
_sentSize = null;
|
||||
_update(info);
|
||||
unawaited(resume());
|
||||
// The new connection reports the size it draws at; the server applies
|
||||
// it while no other client is the active one.
|
||||
final size = session.viewSize;
|
||||
if (size != null) _resized(size.$1, size.$2);
|
||||
}
|
||||
|
||||
void disconnected() {
|
||||
@@ -182,19 +188,25 @@ class TerminalTab extends ChangeNotifier {
|
||||
_notify();
|
||||
}
|
||||
|
||||
void _input(String data) {
|
||||
/// Sends typed text, or with [reply] the emulator's automatic answer to a
|
||||
/// query, which the server passes on only from the active client. Typing
|
||||
/// carries the size this client draws at: it becomes the active client.
|
||||
void _input(String data, {bool reply = false}) {
|
||||
if (_disposed || !connected) return;
|
||||
final id = _info.id;
|
||||
final gateway = _gateway;
|
||||
(_pipe ??= ChatShellInputPipe(
|
||||
(data) => gateway.call('terminal_input', {
|
||||
'terminal_request': {'terminal_id': id, 'data': data},
|
||||
}),
|
||||
(failure) {
|
||||
error = '$failure';
|
||||
_notify();
|
||||
},
|
||||
)).add(data);
|
||||
(_pipe ??= ChatShellInputPipe((data, reply) {
|
||||
final size = reply ? null : session.viewSize;
|
||||
return gateway.call('terminal_input', {
|
||||
'terminal_request': {
|
||||
'terminal_id': id,
|
||||
'data': data,
|
||||
if (reply) 'reply': true,
|
||||
'cols': ?size?.$1,
|
||||
'rows': ?size?.$2,
|
||||
},
|
||||
});
|
||||
}, _failed)).add(data, reply: reply);
|
||||
}
|
||||
|
||||
void _resized(int cols, int rows) {
|
||||
@@ -202,23 +214,40 @@ class TerminalTab extends ChangeNotifier {
|
||||
_resize?.cancel();
|
||||
_resize = Timer(chatShellResizeDelay, () {
|
||||
if (_sentSize == (cols, rows) || !connected) return;
|
||||
_sentSize = (cols, rows);
|
||||
_gateway
|
||||
.call('terminal_resize', {
|
||||
'terminal_request': {
|
||||
'terminal_id': _info.id,
|
||||
'cols': cols,
|
||||
'rows': rows,
|
||||
},
|
||||
})
|
||||
.catchError((Object failure) {
|
||||
error = '$failure';
|
||||
_notify();
|
||||
return <String, dynamic>{};
|
||||
});
|
||||
_sendSize(cols, rows, activate: false);
|
||||
});
|
||||
}
|
||||
|
||||
/// A view gained focus: this client becomes the active one and the
|
||||
/// terminal takes its size at once.
|
||||
void _activated(int cols, int rows) {
|
||||
if (_disposed || !_info.running || !connected) return;
|
||||
_resize?.cancel();
|
||||
_sendSize(cols, rows, activate: true);
|
||||
}
|
||||
|
||||
void _sendSize(int cols, int rows, {required bool activate}) {
|
||||
_sentSize = (cols, rows);
|
||||
_gateway
|
||||
.call('terminal_resize', {
|
||||
'terminal_request': {
|
||||
'terminal_id': _info.id,
|
||||
'cols': cols,
|
||||
'rows': rows,
|
||||
if (activate) 'activate': true,
|
||||
},
|
||||
})
|
||||
.catchError((Object failure) {
|
||||
_failed(failure);
|
||||
return <String, dynamic>{};
|
||||
});
|
||||
}
|
||||
|
||||
void _failed(Object failure) {
|
||||
error = '$failure';
|
||||
_notify();
|
||||
}
|
||||
|
||||
void _notify() {
|
||||
if (!_disposed) notifyListeners();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user