Merge pull request 'tui: cap redraw rate' (#152) from fix/paste-throttle into main

This commit was merged in pull request #152.
This commit is contained in:
hermes committed 2026-10-14 21:47:49 +00:00
commit 658edf3f64
1 file changed
+7 -1
+7 -1
View File
@@ -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 lens_tick = tokio::time::interval(std::time::Duration::from_secs(2));
let mut dirty = true; let mut dirty = true;
let mut last_title = String::new(); 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 { 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")); let t = format!("hx · {}", app.title.as_deref().unwrap_or("new session"));
if t != last_title { if t != last_title {
// OSC 2: terminal window 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))?; term.draw(|f| draw(f, &mut app))?;
} }
tokio::select! { tokio::select! {
_ = tokio::time::sleep_until((last_draw + FRAME).into()), if dirty => {}
k = keys.next() => { k = keys.next() => {
let Some(Ok(ev)) = k else { break }; let Some(Ok(ev)) = k else { break };
dirty = true; dirty = true;