Skip to content

Commit ce65728

Browse files
committed
fix(tui): restore input after sandbox shell
Discard stale events accumulated around the suspended TUI and let the normal periodic tick refresh state after resuming. Signed-off-by: John T. Myers <9696606+johntmyers@users.noreply.github.com>
1 parent 3be4df2 commit ce65728

2 files changed

Lines changed: 16 additions & 6 deletions

File tree

crates/openshell-tui/src/event.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,15 @@ impl EventHandler {
118118
self.rx.recv().await
119119
}
120120

121+
/// Discard events queued before or while the TUI was suspended.
122+
///
123+
/// The input reader is paused before this is called, so terminal input
124+
/// remains in the TTY for the resumed reader. This primarily removes stale
125+
/// tick events that would otherwise run refresh work before new key input.
126+
pub fn discard_pending(&mut self) {
127+
while self.rx.try_recv().is_ok() {}
128+
}
129+
121130
/// Get a sender handle for dispatching events from background tasks.
122131
pub fn sender(&self) -> mpsc::UnboundedSender<Event> {
123132
self.keepalive.clone()

crates/openshell-tui/src/lib.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,7 @@ pub async fn run(
142142
}
143143
if app.pending_shell_connect {
144144
app.pending_shell_connect = false;
145-
handle_shell_connect(&mut app, &mut terminal, &events).await?;
146-
refresh_data(&mut app).await;
145+
handle_shell_connect(&mut app, &mut terminal, &mut events).await?;
147146
}
148147
// --- Draft actions ---
149148
if app.pending_draft_approve {
@@ -366,7 +365,7 @@ pub async fn run(
366365
handle_exec_command(
367366
&mut app,
368367
&mut terminal,
369-
&events,
368+
&mut events,
370369
&name,
371370
&command,
372371
)
@@ -841,7 +840,7 @@ async fn fetch_sandbox_detail(app: &mut App) {
841840
async fn handle_shell_connect(
842841
app: &mut App,
843842
terminal: &mut Terminal<CrosstermBackend<io::Stdout>>,
844-
events: &EventHandler,
843+
events: &mut EventHandler,
845844
) -> Result<()> {
846845
let sandbox_name = match app.selected_sandbox_name() {
847846
Some(n) => n.to_string(),
@@ -973,7 +972,7 @@ async fn handle_shell_connect(
973972
}
974973
}
975974

976-
// Step 9: Resume and draw the TUI before the caller refreshes gateway data.
975+
// Step 9: Resume and draw the TUI before accepting new terminal input.
977976
enable_raw_mode().into_diagnostic()?;
978977
execute!(
979978
terminal.backend_mut(),
@@ -985,6 +984,7 @@ async fn handle_shell_connect(
985984
terminal
986985
.draw(|frame| ui::draw(frame, app))
987986
.into_diagnostic()?;
987+
events.discard_pending();
988988
events.resume();
989989

990990
Ok(())
@@ -998,7 +998,7 @@ async fn handle_shell_connect(
998998
async fn handle_exec_command(
999999
app: &mut App,
10001000
terminal: &mut Terminal<CrosstermBackend<io::Stdout>>,
1001-
events: &EventHandler,
1001+
events: &mut EventHandler,
10021002
sandbox_name: &str,
10031003
command: &str,
10041004
) -> Result<()> {
@@ -1140,6 +1140,7 @@ async fn handle_exec_command(
11401140
)
11411141
.into_diagnostic()?;
11421142
terminal.clear().into_diagnostic()?;
1143+
events.discard_pending();
11431144
events.resume();
11441145

11451146
Ok(())

0 commit comments

Comments
 (0)