CLI quality-of-life fixes. (#521) r=rnewman
* CLI: Update linefeed library to latest version * CLI: Don't store incomplete commands in history * CLI: add curly braces to word separators * Review comment: clean up CLI add_history. Signed-off-by: Thom Chiovoloni <tchiovoloni@mozilla.com>
This commit is contained in:
parent
95e95d735e
commit
579829d091
2 changed files with 23 additions and 9 deletions
|
@ -14,7 +14,7 @@ test = false
|
|||
[dependencies]
|
||||
getopts = "0.2"
|
||||
env_logger = "0.3"
|
||||
linefeed = "0.1"
|
||||
linefeed = "0.4"
|
||||
log = "0.3"
|
||||
tempfile = "1.1"
|
||||
combine = "2.2.2"
|
||||
|
|
|
@ -10,8 +10,11 @@
|
|||
|
||||
use std::io::stdin;
|
||||
|
||||
use linefeed::Reader;
|
||||
use linefeed::terminal::DefaultTerminal;
|
||||
use linefeed::{
|
||||
DefaultTerminal,
|
||||
Reader,
|
||||
ReadResult,
|
||||
};
|
||||
|
||||
use self::InputResult::*;
|
||||
|
||||
|
@ -53,7 +56,7 @@ impl InputReader {
|
|||
pub fn new() -> InputReader {
|
||||
let r = match Reader::new("mentat") {
|
||||
Ok(mut r) => {
|
||||
r.set_word_break_chars(" \t\n!\"#$%&'()*+,-./:;<=>?@[\\]^`");
|
||||
r.set_word_break_chars(" \t\n!\"#$%&'(){}*+,-./:;<=>?@[\\]^`");
|
||||
Some(r)
|
||||
},
|
||||
Err(_) => None,
|
||||
|
@ -81,14 +84,16 @@ impl InputReader {
|
|||
None => return Ok(Eof),
|
||||
};
|
||||
|
||||
if !self.buffer.is_empty() {
|
||||
self.buffer.push('\n');
|
||||
}
|
||||
|
||||
self.buffer.push_str(&line);
|
||||
|
||||
if self.buffer.is_empty() {
|
||||
return Ok(Empty);
|
||||
}
|
||||
|
||||
self.add_history(&line);
|
||||
|
||||
// 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
|
||||
// command again, only the content, which we do later.
|
||||
|
@ -118,14 +123,18 @@ impl InputReader {
|
|||
Ok(More)
|
||||
},
|
||||
_ => {
|
||||
let entry = self.buffer.clone();
|
||||
self.buffer.clear();
|
||||
self.add_history(entry);
|
||||
self.in_process_cmd = None;
|
||||
Ok(InputResult::MetaCommand(cmd))
|
||||
}
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
let entry = self.buffer.clone();
|
||||
self.buffer.clear();
|
||||
self.add_history(entry);
|
||||
self.in_process_cmd = None;
|
||||
Err(e)
|
||||
},
|
||||
|
@ -136,7 +145,12 @@ impl InputReader {
|
|||
match self.reader {
|
||||
Some(ref mut r) => {
|
||||
r.set_prompt(prompt);
|
||||
r.read_line().ok().and_then(|line| line)
|
||||
r.read_line().ok().and_then(|line|
|
||||
match line {
|
||||
ReadResult::Input(s) => Some(s),
|
||||
_ => None
|
||||
})
|
||||
|
||||
},
|
||||
None => self.read_stdin()
|
||||
}
|
||||
|
@ -151,9 +165,9 @@ impl InputReader {
|
|||
}
|
||||
}
|
||||
|
||||
fn add_history(&mut self, line: &str) {
|
||||
fn add_history(&mut self, line: String) {
|
||||
if let Some(ref mut r) = self.reader {
|
||||
r.add_history(line.to_owned());
|
||||
r.add_history(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue