summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Smeding <tom.smeding@gmail.com>2020-04-04 11:17:06 +0200
committerTom Smeding <tom.smeding@gmail.com>2020-04-04 11:17:06 +0200
commit7d7d52161a576549edc4e4a6d59908b8838137e8 (patch)
treeca8861ee2d256bdd2479e7d7e20303f3e680f2a2
parentd54479c3e09fa8aaeb5838ee00ed407ce7a65d44 (diff)
Fix behaviour on unknown commands
-rw-r--r--src/main.rs41
1 files changed, 22 insertions, 19 deletions
diff --git a/src/main.rs b/src/main.rs
index 3527410..adaa058 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -194,27 +194,30 @@ fn handle_key(key: Key, st: &mut State) -> Option<bool> {
// Command
Key::Char(c) | Key::Alt(c) => {
- let mut delay_lf = 0;
- if st.input_buffer.len() != 0 {
- match st.input_buffer.parse::<Entry>() {
- Ok(val) => {
- st.stk.push(val);
- print!("{}\r{}{}",
- termion::clear::CurrentLine, " ".repeat(PROMPT_STR.len()),
- val);
- st.input_buffer.clear();
- st.input_cursor = 0;
- if st.entries_drawn < st.term_height - 1 {
- st.entries_drawn += 1;
- }
- delay_lf = 1;
- }
- Err(_) => return None,
- }
- }
-
let name = String::from(c.to_string());
if let Some(&(nargs, ref f)) = st.command_map.get(&name) {
+ let delay_lf;
+ if st.input_buffer.len() != 0 {
+ match st.input_buffer.parse::<Entry>() {
+ Ok(val) => {
+ st.stk.push(val);
+ print!("{}\r{}{}",
+ termion::clear::CurrentLine,
+ " ".repeat(PROMPT_STR.len()),
+ val);
+ st.input_buffer.clear();
+ st.input_cursor = 0;
+ if st.entries_drawn < st.term_height - 1 {
+ st.entries_drawn += 1;
+ }
+ delay_lf = 1;
+ }
+ Err(_) => return None,
+ }
+ } else {
+ delay_lf = 0;
+ }
+
if st.stk.len() < nargs {
return None;
}