Fix some issues with UI getting out of sync. (#7)
Reviewed-on: #7 Co-authored-by: Drew Galbraith <drew@tiramisu.one> Co-committed-by: Drew Galbraith <drew@tiramisu.one>
This commit is contained in:
parent
0fcdf4ed0d
commit
af080710cc
8 changed files with 199 additions and 84 deletions
|
|
@ -26,7 +26,7 @@ use ratatui::Terminal;
|
|||
use ratatui::backend::CrosstermBackend;
|
||||
use tokio::sync::mpsc;
|
||||
|
||||
use crate::core::types::{Role, UIEvent, UserAction};
|
||||
use crate::core::types::{Role, StampedEvent, UserAction};
|
||||
|
||||
/// Errors that can occur in the TUI layer.
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
|
|
@ -78,6 +78,12 @@ pub struct AppState {
|
|||
pub sandbox_yolo: bool,
|
||||
/// Whether network access is currently allowed.
|
||||
pub network_allowed: bool,
|
||||
/// Monotonic epoch incremented on `:clear`. Events with an older epoch are
|
||||
/// discarded by `drain_ui_events` to prevent ghost messages.
|
||||
pub epoch: u64,
|
||||
/// Set by `drain_ui_events` when message content changes; consumed by
|
||||
/// `update_scroll` to auto-follow only when new content arrives.
|
||||
pub content_changed: bool,
|
||||
}
|
||||
|
||||
impl AppState {
|
||||
|
|
@ -94,6 +100,8 @@ impl AppState {
|
|||
pending_approval: None,
|
||||
sandbox_yolo: false,
|
||||
network_allowed: false,
|
||||
epoch: 0,
|
||||
content_changed: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -150,7 +158,7 @@ pub fn install_panic_hook() {
|
|||
/// returns `Ok(())`.
|
||||
pub async fn run(
|
||||
action_tx: mpsc::Sender<UserAction>,
|
||||
mut event_rx: mpsc::Receiver<UIEvent>,
|
||||
mut event_rx: mpsc::Receiver<StampedEvent>,
|
||||
sandbox_yolo: bool,
|
||||
) -> Result<(), TuiError> {
|
||||
install_panic_hook();
|
||||
|
|
@ -194,7 +202,9 @@ pub async fn run(
|
|||
break;
|
||||
}
|
||||
Some(input::LoopControl::ClearHistory) => {
|
||||
let _ = action_tx.send(UserAction::ClearHistory).await;
|
||||
let _ = action_tx
|
||||
.send(UserAction::ClearHistory { epoch: state.epoch })
|
||||
.await;
|
||||
}
|
||||
Some(input::LoopControl::ToolApproval {
|
||||
tool_use_id,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue