From 5d4cdbf10d30c0268d30a83573042a71cb171e2a Mon Sep 17 00:00:00 2001 From: hermes Date: Sat, 14 Nov 2026 11:23:38 +0000 Subject: [PATCH] plan view: f opens the feedback input directly --- crates/hx-tui/src/choose.rs | 29 +++++++++++++++++++++++++++++ crates/hx-tui/src/lib.rs | 2 +- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/crates/hx-tui/src/choose.rs b/crates/hx-tui/src/choose.rs index c671c9d..889b398 100644 --- a/crates/hx-tui/src/choose.rs +++ b/crates/hx-tui/src/choose.rs @@ -19,6 +19,8 @@ pub struct Choose { picked: Vec, /// Some while typing an own answer typing: Option, + /// opened straight into the text input: esc dismisses instead of showing the list + direct: bool, } impl Choose { @@ -28,9 +30,18 @@ impl Choose { q, sel: 0, typing: None, + direct: false, } } + /// Free-text question: starts in the input, no option list. + pub fn input(q: Question) -> Self { + let mut c = Self::new(q); + c.typing = Some(String::new()); + c.direct = true; + c + } + fn rows(&self) -> usize { self.q.options.len() + usize::from(self.q.other) } @@ -57,6 +68,7 @@ impl Choose { let picked = if self.q.multi { self.labels() } else { vec![] }; if let Some(t) = &mut self.typing { match k.code { + KeyCode::Esc if self.direct => return Act::Done(None), KeyCode::Esc => self.typing = None, KeyCode::Backspace => { t.pop(); @@ -315,6 +327,23 @@ mod tests { assert!(c.is_other()); } + #[test] + fn input_starts_typing_and_esc_dismisses() { + let q = || Question { + text: "why?".into(), + options: vec![], + multi: false, + other: true, + plan: None, + }; + let mut c = Choose::input(q()); + c.key(k(KeyCode::Char('h'))); + c.key(k(KeyCode::Char('i'))); + assert!(matches!(c.key(k(KeyCode::Enter)), Act::Done(Some(v)) if v == ["hi"])); + let mut c = Choose::input(q()); + assert!(matches!(c.key(k(KeyCode::Esc)), Act::Done(None))); + } + #[test] fn multi_toggle_and_other_text() { let mut c = q(true); diff --git a/crates/hx-tui/src/lib.rs b/crates/hx-tui/src/lib.rs index e546b36..b1f2265 100644 --- a/crates/hx-tui/src/lib.rs +++ b/crates/hx-tui/src/lib.rs @@ -513,7 +513,7 @@ pub async fn run(setup: Setup) -> std::io::Result<()> { q.plan = None; q.text = "What should change in the plan?".into(); q.options = vec![]; - app.choose = Some((choose::Choose::new(q), reply)); + app.choose = Some((choose::Choose::input(q), reply)); } else { app.t.push(Item::Info(format!("plan: {l}"))); let _ = reply.send(Some(vec![l]));