fix(tui): pause/resume stdin subscription around external editor
io.stdin is a single-subscription stream — calling listen() a second time after cancel() throws 'Stream has already been listened to'. Use keySub.pause() before launching the editor and keySub.resume() after it exits instead. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
5c3d00e2a4
commit
eeed3fdba0
1 changed files with 3 additions and 9 deletions
|
|
@ -302,9 +302,7 @@ class TuiCommand extends DewCommand {
|
|||
}
|
||||
|
||||
// Key stream — raw bytes converted to Key values without blocking.
|
||||
// Declared as var so it can be cancelled and re-created around external editor.
|
||||
StreamSubscription<List<int>> keySub;
|
||||
keySub = io.stdin.listen((bytes) {
|
||||
final keySub = io.stdin.listen((bytes) {
|
||||
for (final key in _parseKeys(bytes)) {
|
||||
if (!events.isClosed) events.add(_TuiKey(key));
|
||||
}
|
||||
|
|
@ -649,7 +647,7 @@ class TuiCommand extends DewCommand {
|
|||
'${io.Directory.systemTemp.path}/dew_edit_${es.ticket.id}.md',
|
||||
);
|
||||
await tmpFile.writeAsString(es.body);
|
||||
await keySub.cancel();
|
||||
keySub.pause();
|
||||
console.rawMode = false;
|
||||
console.showCursor();
|
||||
console.clearScreen();
|
||||
|
|
@ -661,13 +659,9 @@ class TuiCommand extends DewCommand {
|
|||
await proc.exitCode;
|
||||
es.body = await tmpFile.readAsString();
|
||||
await tmpFile.delete();
|
||||
keySub = io.stdin.listen((bytes) {
|
||||
for (final key in _parseKeys(bytes)) {
|
||||
if (!events.isClosed) events.add(_TuiKey(key));
|
||||
}
|
||||
});
|
||||
console.rawMode = true;
|
||||
console.hideCursor();
|
||||
keySub.resume();
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue