Clear the CLI buffer when an incorrect command is added. (#500) r=rnewman
* Fix issue whereby when an incorrect command was entered, the buffer wasn't cleared and the next command was appended on the end of the incorrect one. * Cleanup.
This commit is contained in:
parent
95b9c7f7f5
commit
2fc4cb5a2d
1 changed files with 27 additions and 25 deletions
|
@ -17,7 +17,7 @@ use self::InputResult::*;
|
||||||
|
|
||||||
use command_parser::{
|
use command_parser::{
|
||||||
Command,
|
Command,
|
||||||
command
|
command,
|
||||||
};
|
};
|
||||||
|
|
||||||
use errors as cli;
|
use errors as cli;
|
||||||
|
@ -55,8 +55,8 @@ impl InputReader {
|
||||||
Ok(mut r) => {
|
Ok(mut r) => {
|
||||||
r.set_word_break_chars(" \t\n!\"#$%&'()*+,-./:;<=>?@[\\]^`");
|
r.set_word_break_chars(" \t\n!\"#$%&'()*+,-./:;<=>?@[\\]^`");
|
||||||
Some(r)
|
Some(r)
|
||||||
}
|
},
|
||||||
Err(_) => None
|
Err(_) => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
InputReader{
|
InputReader{
|
||||||
|
@ -89,28 +89,30 @@ impl InputReader {
|
||||||
|
|
||||||
self.add_history(&line);
|
self.add_history(&line);
|
||||||
|
|
||||||
// if we have a command in process (i.e. in incomplete query or transaction),
|
// if we have a command in process (i.e. an incomplete query or transaction),
|
||||||
// then we already know which type of command it is and so we don't need to parse the
|
// then we already know which type of command it is and so we don't need to parse the
|
||||||
// command again, only the content, which we do later.
|
// command again, only the content, which we do later.
|
||||||
// Therefore, we add the newly read in line to the existing command args.
|
// Therefore, we add the newly read in line to the existing command args.
|
||||||
// If there is no in process command, we parse the read in line as a new command.
|
// If there is no in process command, we parse the read in line as a new command.
|
||||||
let cmd = match &self.in_process_cmd {
|
let cmd = match &self.in_process_cmd {
|
||||||
&Some(Command::Query(ref args)) => {
|
&Some(Command::Query(ref args)) => {
|
||||||
Command::Query(args.clone() + " " + &line)
|
Ok(Command::Query(args.clone() + " " + &line))
|
||||||
},
|
},
|
||||||
&Some(Command::Transact(ref args)) => {
|
&Some(Command::Transact(ref args)) => {
|
||||||
Command::Transact(args.clone() + " " + &line)
|
Ok(Command::Transact(args.clone() + " " + &line))
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
try!(command(&self.buffer))
|
command(&self.buffer)
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
match cmd {
|
||||||
|
Ok(cmd) => {
|
||||||
match cmd {
|
match cmd {
|
||||||
Command::Query(_) |
|
Command::Query(_) |
|
||||||
Command::Transact(_) if !cmd.is_complete() => {
|
Command::Transact(_) if !cmd.is_complete() => {
|
||||||
// a query or transact is complete if it contains a valid edn.
|
// A query or transact is complete if it contains a valid EDN.
|
||||||
// if the command is not complete, ask for more from the repl and remember
|
// if the command is not complete, ask for more from the REPL and remember
|
||||||
// which type of command we've found here.
|
// which type of command we've found here.
|
||||||
self.in_process_cmd = Some(cmd);
|
self.in_process_cmd = Some(cmd);
|
||||||
Ok(More)
|
Ok(More)
|
||||||
|
@ -121,6 +123,13 @@ impl InputReader {
|
||||||
Ok(InputResult::MetaCommand(cmd))
|
Ok(InputResult::MetaCommand(cmd))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
Err(e) => {
|
||||||
|
self.buffer.clear();
|
||||||
|
self.in_process_cmd = None;
|
||||||
|
Err(e)
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_line(&mut self, prompt: &str) -> Option<String> {
|
fn read_line(&mut self, prompt: &str) -> Option<String> {
|
||||||
|
@ -148,10 +157,3 @@ impl InputReader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
#[test]
|
|
||||||
fn it_works() {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue