Rustfmt & clippy
diff --git a/examples/example.rs b/examples/example.rs
index 45b14da..9bd3ccb 100644
--- a/examples/example.rs
+++ b/examples/example.rs
@@ -42,7 +42,7 @@
let c = FilenameCompleter::new();
let mut rl = Editor::with_config(config);
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('P'), Cmd::HistorySearchBackward);
if rl.load_history("history.txt").is_err() {
diff --git a/rustfmt.toml b/rustfmt.toml
index ea29d79..b0d7dd1 100644
--- a/rustfmt.toml
+++ b/rustfmt.toml
@@ -3,4 +3,5 @@
force_format_strings = true
format_strings = true
reorder_imported_names = true
-write_mode = "Overwrite"
\ No newline at end of file
+write_mode = "Overwrite"
+error_on_line_overflow_comments = false
\ No newline at end of file
diff --git a/src/hint.rs b/src/hint.rs
index 2a5634a..84342dc 100644
--- a/src/hint.rs
+++ b/src/hint.rs
@@ -6,4 +6,4 @@
/// returns the string that should be displayed or `None`
/// if no hint is available for the text the user currently typed.
fn hint(&mut self, line: &str, pos: usize) -> Option<String>;
-}
\ No newline at end of file
+}
diff --git a/src/history.rs b/src/history.rs
index af13052..e26b60b 100644
--- a/src/history.rs
+++ b/src/history.rs
@@ -93,7 +93,8 @@
/// just the latest `len` elements if the new history length value is
/// 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) {
self.max_len = len;
if len == 0 {
diff --git a/src/lib.rs b/src/lib.rs
index ae5676d..31011eb 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -75,11 +75,11 @@
/// Implement rendering.
struct State<'out, 'prompt> {
out: &'out mut Renderer,
- prompt: &'prompt str, // Prompt to display
- prompt_size: Position, // Prompt Unicode/visible width and height
- line: LineBuffer, // Edited line buffer
- cursor: Position, /* Cursor position (relative to the start of the prompt
- * for `row`) */
+ prompt: &'prompt str, // Prompt to display
+ prompt_size: Position, // Prompt Unicode/visible width and height
+ line: LineBuffer, // Edited line buffer
+ cursor: Position, /* Cursor position (relative to the start of the prompt
+ * for `row`) */
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
saved_line_for_history: LineBuffer, // Current edited line before history browsing
@@ -182,7 +182,9 @@
fn hint(&self) -> Option<String> {
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 {
None
}
@@ -210,7 +212,9 @@
if push {
let prompt_size = s.prompt_size;
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.
let cursor = s.out
.calculate_position(&s.line[..s.line.pos()], s.prompt_size);
@@ -537,7 +541,7 @@
}
/// Completes the line/word
-fn complete_line<R: RawReader, C: Completer+?Sized>(
+fn complete_line<R: RawReader, C: Completer + ?Sized>(
rdr: &mut R,
s: &mut State,
completer: &mut C,
@@ -807,7 +811,7 @@
original_mode: tty::Mode,
) -> Result<String> {
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();
@@ -825,7 +829,8 @@
s.line.set_change_listener(s.changes.clone());
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());
@@ -1088,7 +1093,11 @@
/// Readline method that will enable RAW mode, call the `readline_edit()`
/// 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 guard = Guard(original_mode);
let user_input = readline_edit(prompt, initial, editor, original_mode);
@@ -1144,22 +1153,26 @@
/// 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),
/// it uses file-style interaction.
pub fn readline(&mut self, prompt: &str) -> Result<String> {
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 string on the left of the tuple what will appear to the left of the cursor
- /// 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> {
+ /// The string on the left of the tuple what will appear to the left of the
+ /// cursor
+ /// 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))
}
- 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() {
debug!(target: "rustyline", "unsupported terminal");
// Write prompt and flush it to stdout
@@ -1258,8 +1271,7 @@
}
/// Edited lines iterator
-pub struct Iter<'a>
-{
+pub struct Iter<'a> {
editor: &'a mut Editor,
prompt: &'a str,
}
@@ -1270,9 +1282,7 @@
fn next(&mut self) -> Option<Result<String>> {
let readline = self.editor.readline(self.prompt);
match readline {
- Ok(l) => {
- Some(Ok(l))
- }
+ Ok(l) => Some(Ok(l)),
Err(error::ReadlineError::Eof) => None,
e @ Err(_) => Some(e),
}
@@ -1370,7 +1380,8 @@
let keys = &[KeyPress::Enter];
let mut rdr = keys.iter();
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!("rust", s.line.as_str());
assert_eq!(4, s.line.pos());
diff --git a/src/tty/unix.rs b/src/tty/unix.rs
index b3f1675..6e5280a 100644
--- a/src/tty/unix.rs
+++ b/src/tty/unix.rs
@@ -129,7 +129,8 @@
'5' => KeyPress::PageUp, // kpp
'6' => KeyPress::PageDown, // knp
_ => {
- debug!(target: "rustyline", "unsupported esc sequence: ESC [ {} ~", seq2);
+ debug!(target: "rustyline",
+ "unsupported esc sequence: ESC [ {} ~", seq2);
KeyPress::UnknownEscSeq
}
})
@@ -150,7 +151,8 @@
('2', '3') => KeyPress::F(11), // kf11
('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
}
})
@@ -158,13 +160,16 @@
let seq5 = try!(self.next_char());
if seq5.is_digit(10) {
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 {
- debug!(target: "rustyline", "unsupported esc sequence: ESC [ {}{} ; {:?}", seq2, seq3, seq5);
+ debug!(target: "rustyline",
+ "unsupported esc sequence: ESC [ {}{} ; {:?}", seq2, seq3, seq5);
}
Ok(KeyPress::UnknownEscSeq)
} else {
- debug!(target: "rustyline", "unsupported esc sequence: ESC [ {}{} {:?}", seq2, seq3, seq4);
+ debug!(target: "rustyline",
+ "unsupported esc sequence: ESC [ {}{} {:?}", seq2, seq3, seq4);
Ok(KeyPress::UnknownEscSeq)
}
} else if seq3 == ';' {
@@ -182,16 +187,19 @@
('2', 'C') => KeyPress::ShiftRight,
('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
}
})
} else {
- debug!(target: "rustyline", "unsupported esc sequence: ESC [ {} ; {} {}", seq2, seq4, seq5);
+ debug!(target: "rustyline",
+ "unsupported esc sequence: ESC [ {} ; {} {}", seq2, seq4, seq5);
Ok(KeyPress::UnknownEscSeq)
}
} else {
- debug!(target: "rustyline", "unsupported esc sequence: ESC [ {} ; {:?}", seq2, seq4);
+ debug!(target: "rustyline",
+ "unsupported esc sequence: ESC [ {} ; {:?}", seq2, seq4);
Ok(KeyPress::UnknownEscSeq)
}
} else {
@@ -201,7 +209,8 @@
('5', 'C') => KeyPress::ControlRight,
('5', 'D') => KeyPress::ControlLeft,
_ => {
- debug!(target: "rustyline", "unsupported esc sequence: ESC [ {} {:?}", seq2, seq3);
+ debug!(target: "rustyline",
+ "unsupported esc sequence: ESC [ {} {:?}", seq2, seq3);
KeyPress::UnknownEscSeq
}
})