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,37 +89,46 @@ 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 {
|
match cmd {
|
||||||
Command::Query(_) |
|
Ok(cmd) => {
|
||||||
Command::Transact(_) if !cmd.is_complete() => {
|
match cmd {
|
||||||
// a query or transact is complete if it contains a valid edn.
|
Command::Query(_) |
|
||||||
// if the command is not complete, ask for more from the repl and remember
|
Command::Transact(_) if !cmd.is_complete() => {
|
||||||
// which type of command we've found here.
|
// A query or transact is complete if it contains a valid EDN.
|
||||||
self.in_process_cmd = Some(cmd);
|
// if the command is not complete, ask for more from the REPL and remember
|
||||||
Ok(More)
|
// which type of command we've found here.
|
||||||
|
self.in_process_cmd = Some(cmd);
|
||||||
|
Ok(More)
|
||||||
|
},
|
||||||
|
_ => {
|
||||||
|
self.buffer.clear();
|
||||||
|
self.in_process_cmd = None;
|
||||||
|
Ok(InputResult::MetaCommand(cmd))
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
_ => {
|
Err(e) => {
|
||||||
self.buffer.clear();
|
self.buffer.clear();
|
||||||
self.in_process_cmd = None;
|
self.in_process_cmd = None;
|
||||||
Ok(InputResult::MetaCommand(cmd))
|
Err(e)
|
||||||
}
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,10 +157,3 @@ impl InputReader {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
#[test]
|
|
||||||
fn it_works() {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue