Skip to content
Snippets Groups Projects
Commit 85327e1b authored by gwenn's avatar gwenn
Browse files

Rustfmt & clippy

parent a562b76c
No related branches found
No related tags found
No related merge requests found
...@@ -42,7 +42,7 @@ fn main() { ...@@ -42,7 +42,7 @@ fn main() {
let c = FilenameCompleter::new(); let c = FilenameCompleter::new();
let mut rl = Editor::with_config(config); let mut rl = Editor::with_config(config);
rl.set_completer(Some(Rc::new(RefCell::new(c)))); rl.set_completer(Some(Rc::new(RefCell::new(c))));
rl.set_hinter(Some(Rc::new(RefCell::new(Hints{})))); rl.set_hinter(Some(Rc::new(RefCell::new(Hints {}))));
rl.bind_sequence(KeyPress::Meta('N'), Cmd::HistorySearchForward); rl.bind_sequence(KeyPress::Meta('N'), Cmd::HistorySearchForward);
rl.bind_sequence(KeyPress::Meta('P'), Cmd::HistorySearchBackward); rl.bind_sequence(KeyPress::Meta('P'), Cmd::HistorySearchBackward);
if rl.load_history("history.txt").is_err() { if rl.load_history("history.txt").is_err() {
......
...@@ -3,4 +3,5 @@ wrap_comments = true ...@@ -3,4 +3,5 @@ wrap_comments = true
force_format_strings = true force_format_strings = true
format_strings = true format_strings = true
reorder_imported_names = true reorder_imported_names = true
write_mode = "Overwrite" write_mode = "Overwrite"
\ No newline at end of file error_on_line_overflow_comments = false
\ No newline at end of file
...@@ -6,4 +6,4 @@ pub trait Hinter { ...@@ -6,4 +6,4 @@ pub trait Hinter {
/// returns the string that should be displayed or `None` /// returns the string that should be displayed or `None`
/// if no hint is available for the text the user currently typed. /// if no hint is available for the text the user currently typed.
fn hint(&mut self, line: &str, pos: usize) -> Option<String>; fn hint(&mut self, line: &str, pos: usize) -> Option<String>;
} }
\ No newline at end of file
...@@ -93,7 +93,8 @@ impl History { ...@@ -93,7 +93,8 @@ impl History {
/// just the latest `len` elements if the new history length value is /// just the latest `len` elements if the new history length value is
/// smaller than the amount of items already inside the history. /// smaller than the amount of items already inside the history.
/// ///
/// Like [stifle_history](http://cnswww.cns.cwru.edu/php/chet/readline/history.html#IDX11). /// Like [stifle_history](http://cnswww.cns.cwru.
/// edu/php/chet/readline/history.html#IDX11).
pub fn set_max_len(&mut self, len: usize) { pub fn set_max_len(&mut self, len: usize) {
self.max_len = len; self.max_len = len;
if len == 0 { if len == 0 {
......
...@@ -75,11 +75,11 @@ pub type Result<T> = result::Result<T, error::ReadlineError>; ...@@ -75,11 +75,11 @@ pub type Result<T> = result::Result<T, error::ReadlineError>;
/// Implement rendering. /// Implement rendering.
struct State<'out, 'prompt> { struct State<'out, 'prompt> {
out: &'out mut Renderer, out: &'out mut Renderer,
prompt: &'prompt str, // Prompt to display prompt: &'prompt str, // Prompt to display
prompt_size: Position, // Prompt Unicode/visible width and height prompt_size: Position, // Prompt Unicode/visible width and height
line: LineBuffer, // Edited line buffer line: LineBuffer, // Edited line buffer
cursor: Position, /* Cursor position (relative to the start of the prompt cursor: Position, /* Cursor position (relative to the start of the prompt
* for `row`) */ * for `row`) */
old_rows: usize, // Number of rows used so far (from start of prompt to end of input) old_rows: usize, // Number of rows used so far (from start of prompt to end of input)
history_index: usize, // The history index we are currently editing history_index: usize, // The history index we are currently editing
saved_line_for_history: LineBuffer, // Current edited line before history browsing saved_line_for_history: LineBuffer, // Current edited line before history browsing
...@@ -182,7 +182,9 @@ impl<'out, 'prompt> State<'out, 'prompt> { ...@@ -182,7 +182,9 @@ impl<'out, 'prompt> State<'out, 'prompt> {
fn hint(&self) -> Option<String> { fn hint(&self) -> Option<String> {
if let Some(ref hinter) = self.hinter { if let Some(ref hinter) = self.hinter {
hinter.borrow_mut().hint(self.line.as_str(), self.line.pos()) hinter
.borrow_mut()
.hint(self.line.as_str(), self.line.pos())
} else { } else {
None None
} }
...@@ -210,7 +212,9 @@ fn edit_insert(s: &mut State, ch: char, n: RepeatCount) -> Result<()> { ...@@ -210,7 +212,9 @@ fn edit_insert(s: &mut State, ch: char, n: RepeatCount) -> Result<()> {
if push { if push {
let prompt_size = s.prompt_size; let prompt_size = s.prompt_size;
let hint = s.hint(); let hint = s.hint();
if n == 1 && s.cursor.col + ch.width().unwrap_or(0) < s.out.get_columns() && hint.is_none() { if n == 1 && s.cursor.col + ch.width().unwrap_or(0) < s.out.get_columns() &&
hint.is_none()
{
// Avoid a full update of the line in the trivial case. // Avoid a full update of the line in the trivial case.
let cursor = s.out let cursor = s.out
.calculate_position(&s.line[..s.line.pos()], s.prompt_size); .calculate_position(&s.line[..s.line.pos()], s.prompt_size);
...@@ -537,7 +541,7 @@ fn edit_history(s: &mut State, history: &History, first: bool) -> Result<()> { ...@@ -537,7 +541,7 @@ fn edit_history(s: &mut State, history: &History, first: bool) -> Result<()> {
} }
/// Completes the line/word /// Completes the line/word
fn complete_line<R: RawReader, C: Completer+?Sized>( fn complete_line<R: RawReader, C: Completer + ?Sized>(
rdr: &mut R, rdr: &mut R,
s: &mut State, s: &mut State,
completer: &mut C, completer: &mut C,
...@@ -807,7 +811,7 @@ fn readline_edit( ...@@ -807,7 +811,7 @@ fn readline_edit(
original_mode: tty::Mode, original_mode: tty::Mode,
) -> Result<String> { ) -> Result<String> {
let completer = editor.completer.as_ref(); let completer = editor.completer.as_ref();
let hinter = editor.hinter.as_ref().map(|h| h.clone()); let hinter = editor.hinter.as_ref().cloned();
let mut stdout = editor.term.create_writer(); let mut stdout = editor.term.create_writer();
...@@ -825,7 +829,8 @@ fn readline_edit( ...@@ -825,7 +829,8 @@ fn readline_edit(
s.line.set_change_listener(s.changes.clone()); s.line.set_change_listener(s.changes.clone());
if let Some((left, right)) = initial { if let Some((left, right)) = initial {
s.line.update((left.to_owned() + right).as_ref(), left.len()); s.line
.update((left.to_owned() + right).as_ref(), left.len());
} }
try!(s.refresh_line()); try!(s.refresh_line());
...@@ -1088,7 +1093,11 @@ impl Drop for Guard { ...@@ -1088,7 +1093,11 @@ impl Drop for Guard {
/// Readline method that will enable RAW mode, call the `readline_edit()` /// Readline method that will enable RAW mode, call the `readline_edit()`
/// method and disable raw mode /// method and disable raw mode
fn readline_raw(prompt: &str, initial: Option<(&str, &str)>, editor: &mut Editor) -> Result<String> { fn readline_raw(
prompt: &str,
initial: Option<(&str, &str)>,
editor: &mut Editor,
) -> Result<String> {
let original_mode = try!(editor.term.enable_raw_mode()); let original_mode = try!(editor.term.enable_raw_mode());
let guard = Guard(original_mode); let guard = Guard(original_mode);
let user_input = readline_edit(prompt, initial, editor, original_mode); let user_input = readline_edit(prompt, initial, editor, original_mode);
...@@ -1144,22 +1153,26 @@ impl Editor { ...@@ -1144,22 +1153,26 @@ impl Editor {
/// This method will read a line from STDIN and will display a `prompt`. /// This method will read a line from STDIN and will display a `prompt`.
/// ///
/// It uses terminal-style interaction if `stdin` is connected to a terminal. /// It uses terminal-style interaction if `stdin` is connected to a
/// terminal.
/// Otherwise (e.g., if `stdin` is a pipe or the terminal is not supported), /// Otherwise (e.g., if `stdin` is a pipe or the terminal is not supported),
/// it uses file-style interaction. /// it uses file-style interaction.
pub fn readline(&mut self, prompt: &str) -> Result<String> { pub fn readline(&mut self, prompt: &str) -> Result<String> {
self.readline_with(prompt, None) self.readline_with(prompt, None)
} }
/// This function behaves in the exact same manner as `readline`, except that it pre-populates the input area. /// This function behaves in the exact same manner as `readline`, except
/// that it pre-populates the input area.
/// ///
/// The text that resides in the input area is given as a 2-tuple. /// The text that resides in the input area is given as a 2-tuple.
/// The string on the left of the tuple what will appear to the left of the cursor /// The string on the left of the tuple what will appear to the left of the
/// and the string on the right is what will appear to the right of the cursor. /// cursor
pub fn readline_with_initial(&mut self, prompt: &str, initial: (&str,&str)) -> Result<String> { /// and the string on the right is what will appear to the right of the
/// cursor.
pub fn readline_with_initial(&mut self, prompt: &str, initial: (&str, &str)) -> Result<String> {
self.readline_with(prompt, Some(initial)) self.readline_with(prompt, Some(initial))
} }
fn readline_with(&mut self, prompt: &str, initial: Option<(&str,&str)>) -> Result<String> { fn readline_with(&mut self, prompt: &str, initial: Option<(&str, &str)>) -> Result<String> {
if self.term.is_unsupported() { if self.term.is_unsupported() {
debug!(target: "rustyline", "unsupported terminal"); debug!(target: "rustyline", "unsupported terminal");
// Write prompt and flush it to stdout // Write prompt and flush it to stdout
...@@ -1258,8 +1271,7 @@ impl fmt::Debug for Editor { ...@@ -1258,8 +1271,7 @@ impl fmt::Debug for Editor {
} }
/// Edited lines iterator /// Edited lines iterator
pub struct Iter<'a> pub struct Iter<'a> {
{
editor: &'a mut Editor, editor: &'a mut Editor,
prompt: &'a str, prompt: &'a str,
} }
...@@ -1270,9 +1282,7 @@ impl<'a> Iterator for Iter<'a> { ...@@ -1270,9 +1282,7 @@ impl<'a> Iterator for Iter<'a> {
fn next(&mut self) -> Option<Result<String>> { fn next(&mut self) -> Option<Result<String>> {
let readline = self.editor.readline(self.prompt); let readline = self.editor.readline(self.prompt);
match readline { match readline {
Ok(l) => { Ok(l) => Some(Ok(l)),
Some(Ok(l))
}
Err(error::ReadlineError::Eof) => None, Err(error::ReadlineError::Eof) => None,
e @ Err(_) => Some(e), e @ Err(_) => Some(e),
} }
...@@ -1370,7 +1380,8 @@ mod test { ...@@ -1370,7 +1380,8 @@ mod test {
let keys = &[KeyPress::Enter]; let keys = &[KeyPress::Enter];
let mut rdr = keys.iter(); let mut rdr = keys.iter();
let mut completer = SimpleCompleter; let mut completer = SimpleCompleter;
let cmd = super::complete_line(&mut rdr, &mut s, &mut completer, &Config::default()).unwrap(); let cmd =
super::complete_line(&mut rdr, &mut s, &mut completer, &Config::default()).unwrap();
assert_eq!(Some(Cmd::AcceptLine), cmd); assert_eq!(Some(Cmd::AcceptLine), cmd);
assert_eq!("rust", s.line.as_str()); assert_eq!("rust", s.line.as_str());
assert_eq!(4, s.line.pos()); assert_eq!(4, s.line.pos());
......
...@@ -129,7 +129,8 @@ impl PosixRawReader { ...@@ -129,7 +129,8 @@ impl PosixRawReader {
'5' => KeyPress::PageUp, // kpp '5' => KeyPress::PageUp, // kpp
'6' => KeyPress::PageDown, // knp '6' => KeyPress::PageDown, // knp
_ => { _ => {
debug!(target: "rustyline", "unsupported esc sequence: ESC [ {} ~", seq2); debug!(target: "rustyline",
"unsupported esc sequence: ESC [ {} ~", seq2);
KeyPress::UnknownEscSeq KeyPress::UnknownEscSeq
} }
}) })
...@@ -150,7 +151,8 @@ impl PosixRawReader { ...@@ -150,7 +151,8 @@ impl PosixRawReader {
('2', '3') => KeyPress::F(11), // kf11 ('2', '3') => KeyPress::F(11), // kf11
('2', '4') => KeyPress::F(12), // kf12 ('2', '4') => KeyPress::F(12), // kf12
_ => { _ => {
debug!(target: "rustyline", "unsupported esc sequence: ESC [ {}{} ~", seq1, seq2); debug!(target: "rustyline",
"unsupported esc sequence: ESC [ {}{} ~", seq1, seq2);
KeyPress::UnknownEscSeq KeyPress::UnknownEscSeq
} }
}) })
...@@ -158,13 +160,16 @@ impl PosixRawReader { ...@@ -158,13 +160,16 @@ impl PosixRawReader {
let seq5 = try!(self.next_char()); let seq5 = try!(self.next_char());
if seq5.is_digit(10) { if seq5.is_digit(10) {
let seq6 = try!(self.next_char()); // '~' expected let seq6 = try!(self.next_char()); // '~' expected
debug!(target: "rustyline", "unsupported esc sequence: ESC [ {}{} ; {} {}", seq2, seq3, seq5, seq6); debug!(target: "rustyline",
"unsupported esc sequence: ESC [ {}{} ; {} {}", seq2, seq3, seq5, seq6);
} else { } else {
debug!(target: "rustyline", "unsupported esc sequence: ESC [ {}{} ; {:?}", seq2, seq3, seq5); debug!(target: "rustyline",
"unsupported esc sequence: ESC [ {}{} ; {:?}", seq2, seq3, seq5);
} }
Ok(KeyPress::UnknownEscSeq) Ok(KeyPress::UnknownEscSeq)
} else { } else {
debug!(target: "rustyline", "unsupported esc sequence: ESC [ {}{} {:?}", seq2, seq3, seq4); debug!(target: "rustyline",
"unsupported esc sequence: ESC [ {}{} {:?}", seq2, seq3, seq4);
Ok(KeyPress::UnknownEscSeq) Ok(KeyPress::UnknownEscSeq)
} }
} else if seq3 == ';' { } else if seq3 == ';' {
...@@ -182,16 +187,19 @@ impl PosixRawReader { ...@@ -182,16 +187,19 @@ impl PosixRawReader {
('2', 'C') => KeyPress::ShiftRight, ('2', 'C') => KeyPress::ShiftRight,
('2', 'D') => KeyPress::ShiftLeft, ('2', 'D') => KeyPress::ShiftLeft,
_ => { _ => {
debug!(target: "rustyline", "unsupported esc sequence: ESC [ {} ; {} {}", seq2, seq4, seq5); debug!(target: "rustyline",
"unsupported esc sequence: ESC [ {} ; {} {}", seq2, seq4, seq5);
KeyPress::UnknownEscSeq KeyPress::UnknownEscSeq
} }
}) })
} else { } else {
debug!(target: "rustyline", "unsupported esc sequence: ESC [ {} ; {} {}", seq2, seq4, seq5); debug!(target: "rustyline",
"unsupported esc sequence: ESC [ {} ; {} {}", seq2, seq4, seq5);
Ok(KeyPress::UnknownEscSeq) Ok(KeyPress::UnknownEscSeq)
} }
} else { } else {
debug!(target: "rustyline", "unsupported esc sequence: ESC [ {} ; {:?}", seq2, seq4); debug!(target: "rustyline",
"unsupported esc sequence: ESC [ {} ; {:?}", seq2, seq4);
Ok(KeyPress::UnknownEscSeq) Ok(KeyPress::UnknownEscSeq)
} }
} else { } else {
...@@ -201,7 +209,8 @@ impl PosixRawReader { ...@@ -201,7 +209,8 @@ impl PosixRawReader {
('5', 'C') => KeyPress::ControlRight, ('5', 'C') => KeyPress::ControlRight,
('5', 'D') => KeyPress::ControlLeft, ('5', 'D') => KeyPress::ControlLeft,
_ => { _ => {
debug!(target: "rustyline", "unsupported esc sequence: ESC [ {} {:?}", seq2, seq3); debug!(target: "rustyline",
"unsupported esc sequence: ESC [ {} {:?}", seq2, seq3);
KeyPress::UnknownEscSeq KeyPress::UnknownEscSeq
} }
}) })
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment