Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't trigger updates for useless events #391

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 13 additions & 6 deletions crates/tui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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

Expand All @@ -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;
Expand Down
Loading