plan view: f opens the feedback input directly
This commit is contained in:
1 parent
a5c7b580ea
commit
b06ae09a98
2 files changed
+30
-1
No files matched your search
@@ -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);
|
||||
|
||||
@@ -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]));
|
||||
|
||||
Reference in new issue
Block a user