Skip to content

Commit

Permalink
fix(console): ignore key release events (#468)
Browse files Browse the repository at this point in the history
On supported platforms, a short key press generates two crossterm
events: One for the initial press and another when the key is released
again. The code was not checking the event kind, so it would treat a
key release as a second key press. Filter out key releases entirely
since they're not explicitly used for anything.
  • Loading branch information
fenhl authored Oct 3, 2023
1 parent caba1a3 commit 715713a
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions tokio-console/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ use color_eyre::{eyre::eyre, Help, SectionExt};
use console_api::tasks::TaskDetails;
use state::State;

use futures::stream::StreamExt;
use futures::{
future,
stream::{StreamExt, TryStreamExt},
};
use ratatui::{
layout::{Constraint, Direction, Layout},
style::Color,
Expand All @@ -11,7 +14,10 @@ use ratatui::{
};
use tokio::sync::{mpsc, watch};

use crate::view::{bold, UpdateKind};
use crate::{
input::{Event, KeyEvent, KeyEventKind},
view::{bold, UpdateKind},
};

mod config;
mod conn;
Expand Down Expand Up @@ -68,7 +74,15 @@ async fn main() -> color_eyre::Result<()> {
warnings::Linter::new(warnings::NeverYielded::default()),
])
.with_retain_for(retain_for);
let mut input = input::EventStream::new();
let mut input = Box::pin(input::EventStream::new().try_filter(|event| {
future::ready(!matches!(
event,
Event::Key(KeyEvent {
kind: KeyEventKind::Release,
..
})
))
}));
let mut view = view::View::new(styles);

loop {
Expand Down

0 comments on commit 715713a

Please sign in to comment.