tui: HX_KEYLOG=file logs terminal events (input debugging)

This commit is contained in:
hermes committed 2026-10-14 21:42:36 +00:00
1 parent 4d4e76d580
commit 105c207238
1 file changed
+8
+8
View File
@@ -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::<String>());
}
dirty = true;
match ev {
TEvent::Key(k) if k.kind != KeyEventKind::Release && app.perm.is_some() => {