diff --git a/CHANGELOG.md b/CHANGELOG.md index f1848d56..4c1800da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), - Retain all request history when collection file is reloaded - Previously, pending and failed requests were lost on reload within a single session. These will still be lost when a session is exited. - Fix serialization of query parameter lists +- Don't update UI for useless events (e.g. cursor moves) ## [2.0.0] - 2024-09-06 diff --git a/crates/tui/src/lib.rs b/crates/tui/src/lib.rs index ad2294c2..6c7fc1a6 100644 --- a/crates/tui/src/lib.rs +++ b/crates/tui/src/lib.rs @@ -31,7 +31,7 @@ use crossterm::{ event::{DisableMouseCapture, EnableMouseCapture, Event, EventStream}, terminal::{EnterAlternateScreen, LeaveAlternateScreen}, }; -use futures::StreamExt; +use futures::{pin_mut, StreamExt}; use notify::{event::ModifyKind, RecursiveMode, Watcher}; use ratatui::{prelude::CrosstermBackend, Terminal}; use slumber_config::{Action, Config}; @@ -148,7 +148,14 @@ impl Tui { let input_engine = &TuiContext::get().input_engine; // Stream of terminal input events - let mut input_stream = EventStream::new(); + let input_stream = + // Events that don't map to a message (cursor move, focus, etc.) + // should be filtered out entirely so they don't trigger any updates + EventStream::new().filter_map(|event_result| async move { + let event = event_result.expect("Error reading terminal input"); + input_engine.event_to_message(event) + }); + pin_mut!(input_stream); self.draw()?; // Initial draw @@ -160,11 +167,11 @@ impl Tui { // while the queue is empty so we don't waste CPU cycles. The // timeout here makes sure we don't block forever, so things like // time displays during in-flight requests will update. + let message = select! { - event_result = input_stream.next() => { - if let Some(event) = event_result { - let event = event.expect("Error reading terminal input"); - input_engine.event_to_message(event) + event_option = input_stream.next() => { + if let Some(event) = event_option { + Some(event) } else { // We ran out of input, just end the program break;