From 7d7d52161a576549edc4e4a6d59908b8838137e8 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Sat, 4 Apr 2020 11:17:06 +0200 Subject: Fix behaviour on unknown commands --- src/main.rs | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) (limited to 'src') 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 { // Command Key::Char(c) | Key::Alt(c) => { - let mut delay_lf = 0; - if st.input_buffer.len() != 0 { - match st.input_buffer.parse::() { - 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::() { + 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; } -- cgit v1.2.3-70-g09d2