aboutsummaryrefslogtreecommitdiff
path: root/src/gui/question.rs
diff options
context:
space:
mode:
authorJoris2022-10-09 17:38:26 +0200
committerJoris2022-10-09 17:38:26 +0200
commit3c935cc0728f25dab169d2a05dfa153242946c4a (patch)
treeb826abb5bf25be6ec75e04e71b1de2f7469b935f /src/gui/question.rs
parent9a5fe39f8ea1e2a88876c68a797ced28fbfd8457 (diff)
downloadflashcards-3c935cc0728f25dab169d2a05dfa153242946c4a.tar.gz
flashcards-3c935cc0728f25dab169d2a05dfa153242946c4a.tar.bz2
flashcards-3c935cc0728f25dab169d2a05dfa153242946c4a.zip
Abort with C-c
Diffstat (limited to 'src/gui/question.rs')
-rw-r--r--src/gui/question.rs12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/gui/question.rs b/src/gui/question.rs
index 27759f8..8f9ee19 100644
--- a/src/gui/question.rs
+++ b/src/gui/question.rs
@@ -25,12 +25,17 @@ enum Answer {
Difficulty { difficulty: Difficulty },
}
+pub enum Response {
+ Aborted,
+ Answered { difficulty: Difficulty },
+}
+
pub fn ask<B: Backend>(
terminal: &mut Terminal<B>,
events: &Events,
title: &str,
card: &Card,
-) -> Result<Difficulty> {
+) -> Result<Response> {
let mut state = State {
input: String::new(),
answer: Answer::Write,
@@ -155,6 +160,9 @@ pub fn ask<B: Backend>(
state.input = format!("{}{}", words.join(" "), if words.len() > 0 {" " } else {""});
}
}
+ Key::Ctrl('c') => {
+ return Ok(Response::Aborted);
+ }
_ => {}
},
Answer::Difficulty {
@@ -171,7 +179,7 @@ pub fn ask<B: Backend>(
state.answer = Answer::Difficulty { difficulty: *d }
}
}
- Key::Char('\n') => return Ok(selected),
+ Key::Char('\n') => return Ok(Response::Answered { difficulty: selected }),
_ => {}
},
}