From 4d4e76d580a75f02fb8b152abc1291ee97c651a0 Mon Sep 17 00:00:00 2001 From: hermes Date: Wed, 14 Oct 2026 21:28:41 +0000 Subject: [PATCH 1/3] tui: cap redraws at ~60/s so key floods (paste without bracketed paste) stay responsive --- crates/hx-tui/src/lib.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/hx-tui/src/lib.rs b/crates/hx-tui/src/lib.rs index aaf5266..2f309b8 100644 --- a/crates/hx-tui/src/lib.rs +++ b/crates/hx-tui/src/lib.rs @@ -430,8 +430,13 @@ pub async fn run(setup: Setup) -> std::io::Result<()> { let mut lens_tick = tokio::time::interval(std::time::Duration::from_secs(2)); let mut dirty = true; let mut last_title = String::new(); + // a paste without bracketed-paste support is a flood of key events; draw at most ~60/s so input stays ahead of the redraw + const FRAME: std::time::Duration = std::time::Duration::from_millis(16); + let mut last_draw = std::time::Instant::now() - FRAME; while !app.quit { - if std::mem::take(&mut dirty) { + if dirty && last_draw.elapsed() >= FRAME { + dirty = false; + last_draw = std::time::Instant::now(); let t = format!("hx ยท {}", app.title.as_deref().unwrap_or("new session")); if t != last_title { // OSC 2: terminal window title @@ -442,6 +447,7 @@ pub async fn run(setup: Setup) -> std::io::Result<()> { term.draw(|f| draw(f, &mut app))?; } tokio::select! { + _ = tokio::time::sleep_until((last_draw + FRAME).into()), if dirty => {} k = keys.next() => { let Some(Ok(ev)) = k else { break }; dirty = true; -- 2.54.1 From 105c207238c2b9ef1097638aafe6f513007c24c2 Mon Sep 17 00:00:00 2001 From: hermes Date: Wed, 14 Oct 2026 21:42:36 +0000 Subject: [PATCH 2/3] tui: HX_KEYLOG=file logs terminal events (input debugging) --- crates/hx-tui/src/lib.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crates/hx-tui/src/lib.rs b/crates/hx-tui/src/lib.rs index 2f309b8..deab90d 100644 --- a/crates/hx-tui/src/lib.rs +++ b/crates/hx-tui/src/lib.rs @@ -425,6 +425,9 @@ pub async fn run(setup: Setup) -> std::io::Result<()> { } // one Paste event per paste instead of a key event (and redraw) per char; newlines no longer submit let _ = crossterm::execute!(std::io::stdout(), crossterm::event::EnableBracketedPaste); + // HX_KEYLOG=/path: append every terminal event (debug input problems such as paste) + let mut keylog = std::env::var_os("HX_KEYLOG").and_then(|p| std::fs::File::create(p).ok()); + let t0 = std::time::Instant::now(); let mut keys = EventStream::new(); let mut tick = tokio::time::interval(std::time::Duration::from_millis(50)); let mut lens_tick = tokio::time::interval(std::time::Duration::from_secs(2)); @@ -450,6 +453,11 @@ pub async fn run(setup: Setup) -> std::io::Result<()> { _ = tokio::time::sleep_until((last_draw + FRAME).into()), if dirty => {} k = keys.next() => { let Some(Ok(ev)) = k else { break }; + if let Some(f) = &mut keylog { + use std::io::Write; + let d = format!("{ev:?}"); + let _ = writeln!(f, "{:?} {}", t0.elapsed(), d.chars().take(120).collect::()); + } dirty = true; match ev { TEvent::Key(k) if k.kind != KeyEventKind::Release && app.perm.is_some() => { -- 2.54.1 From 5818f143abf59ddbc801e98aed49c148d3cecb1d Mon Sep 17 00:00:00 2001 From: hermes Date: Wed, 14 Oct 2026 21:46:32 +0000 Subject: [PATCH 3/3] Revert "tui: HX_KEYLOG=file logs terminal events (input debugging)" This reverts commit 105c207238c2b9ef1097638aafe6f513007c24c2. --- crates/hx-tui/src/lib.rs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/crates/hx-tui/src/lib.rs b/crates/hx-tui/src/lib.rs index deab90d..2f309b8 100644 --- a/crates/hx-tui/src/lib.rs +++ b/crates/hx-tui/src/lib.rs @@ -425,9 +425,6 @@ pub async fn run(setup: Setup) -> std::io::Result<()> { } // one Paste event per paste instead of a key event (and redraw) per char; newlines no longer submit let _ = crossterm::execute!(std::io::stdout(), crossterm::event::EnableBracketedPaste); - // HX_KEYLOG=/path: append every terminal event (debug input problems such as paste) - let mut keylog = std::env::var_os("HX_KEYLOG").and_then(|p| std::fs::File::create(p).ok()); - let t0 = std::time::Instant::now(); let mut keys = EventStream::new(); let mut tick = tokio::time::interval(std::time::Duration::from_millis(50)); let mut lens_tick = tokio::time::interval(std::time::Duration::from_secs(2)); @@ -453,11 +450,6 @@ pub async fn run(setup: Setup) -> std::io::Result<()> { _ = tokio::time::sleep_until((last_draw + FRAME).into()), if dirty => {} k = keys.next() => { let Some(Ok(ev)) = k else { break }; - if let Some(f) = &mut keylog { - use std::io::Write; - let d = format!("{ev:?}"); - let _ = writeln!(f, "{:?} {}", t0.elapsed(), d.chars().take(120).collect::()); - } dirty = true; match ev { TEvent::Key(k) if k.kind != KeyEventKind::Release && app.perm.is_some() => { -- 2.54.1