plan mode (/plan, exit_plan shows full plan) #187

Merged
hermes merged 5 commits from feat/plan-mode into main 2026-11-14 11:45:20 +00:00
2 changed files with 30 additions and 1 deletions
Showing only changes of commit 5d4cdbf10d - Show all commits

No files matched your search

+29
View File
@@ -19,6 +19,8 @@ pub struct Choose {
picked: Vec<bool>,
/// Some while typing an own answer
typing: Option<String>,
/// 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);
+1 -1
View File
@@ -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]));