Skip to content

Commit

Permalink
reset terminal after running commands to clear any lingering corruption
Browse files Browse the repository at this point in the history
  • Loading branch information
kallsyms committed Jan 14, 2025
1 parent 7ccd386 commit d50d3ee
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1350,6 +1350,7 @@ impl Widget for &mut ACIVizWidget {
#[derive(Clone, Debug)]
enum AppState {
Chat,
TerminalReset,
SelectSession(SelectSessionWidget),
Popup(String, String),
ReviewDiff(DiffReviewWidget),
Expand Down Expand Up @@ -1783,7 +1784,8 @@ impl App {
widget.status = status;
}
api::ws::ACIMessage::End => {
*state = AppState::Chat;
// Fully reset terminal before going back to chat to clear any corruption from running commands
*state = AppState::TerminalReset;
}
}
}
Expand Down Expand Up @@ -1895,6 +1897,13 @@ impl App {
if let Ok(res) = dead_rx.try_recv() {
return res.map(|_| None);
}
if let AppState::TerminalReset = state {
terminal.clear()?;
let mut state = self.state.lock().unwrap();
*state = AppState::Chat;
continue;
}

if last_draw.elapsed() > Duration::from_millis(40) {
last_draw = Instant::now();
terminal.draw(|frame| {
Expand All @@ -1906,11 +1915,13 @@ impl App {
)
})?;
}

if !tokio::task::spawn_blocking(move || event::poll(Duration::from_millis(40)))
.await??
{
continue;
}

match state {
AppState::Exit => {
return Ok(None);
Expand Down Expand Up @@ -2240,6 +2251,8 @@ impl App {
},
_ => {}
},
// Handled before event polling
AppState::TerminalReset => {}
}
}
}
Expand Down

0 comments on commit d50d3ee

Please sign in to comment.