plan view: f opens the feedback input directly
This commit is contained in:
1 parent
4949a4b558
commit
5d4cdbf10d
2 files changed
+30
-1
No files matched your search
@@ -19,6 +19,8 @@ pub struct Choose {
|
|||||||
picked: Vec<bool>,
|
picked: Vec<bool>,
|
||||||
/// Some while typing an own answer
|
/// Some while typing an own answer
|
||||||
typing: Option<String>,
|
typing: Option<String>,
|
||||||
|
/// opened straight into the text input: esc dismisses instead of showing the list
|
||||||
|
direct: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Choose {
|
impl Choose {
|
||||||
@@ -28,9 +30,18 @@ impl Choose {
|
|||||||
q,
|
q,
|
||||||
sel: 0,
|
sel: 0,
|
||||||
typing: None,
|
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 {
|
fn rows(&self) -> usize {
|
||||||
self.q.options.len() + usize::from(self.q.other)
|
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![] };
|
let picked = if self.q.multi { self.labels() } else { vec![] };
|
||||||
if let Some(t) = &mut self.typing {
|
if let Some(t) = &mut self.typing {
|
||||||
match k.code {
|
match k.code {
|
||||||
|
KeyCode::Esc if self.direct => return Act::Done(None),
|
||||||
KeyCode::Esc => self.typing = None,
|
KeyCode::Esc => self.typing = None,
|
||||||
KeyCode::Backspace => {
|
KeyCode::Backspace => {
|
||||||
t.pop();
|
t.pop();
|
||||||
@@ -315,6 +327,23 @@ mod tests {
|
|||||||
assert!(c.is_other());
|
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]
|
#[test]
|
||||||
fn multi_toggle_and_other_text() {
|
fn multi_toggle_and_other_text() {
|
||||||
let mut c = q(true);
|
let mut c = q(true);
|
||||||
|
|||||||
@@ -513,7 +513,7 @@ pub async fn run(setup: Setup) -> std::io::Result<()> {
|
|||||||
q.plan = None;
|
q.plan = None;
|
||||||
q.text = "What should change in the plan?".into();
|
q.text = "What should change in the plan?".into();
|
||||||
q.options = vec![];
|
q.options = vec![];
|
||||||
app.choose = Some((choose::Choose::new(q), reply));
|
app.choose = Some((choose::Choose::input(q), reply));
|
||||||
} else {
|
} else {
|
||||||
app.t.push(Item::Info(format!("plan: {l}")));
|
app.t.push(Item::Info(format!("plan: {l}")));
|
||||||
let _ = reply.send(Some(vec![l]));
|
let _ = reply.send(Some(vec![l]));
|
||||||
|
|||||||
Reference in new issue
Block a user