Rustfmt
diff --git a/rustfmt.toml b/rustfmt.toml
index 34977e4..83697e3 100644
--- a/rustfmt.toml
+++ b/rustfmt.toml
@@ -1,3 +1,4 @@
wrap_comments = true
format_strings = true
error_on_unformatted = false
+reorder_impl_items = true
diff --git a/src/completion.rs b/src/completion.rs
index 1d05753..aeb9a34 100644
--- a/src/completion.rs
+++ b/src/completion.rs
@@ -24,6 +24,7 @@
fn display(&self) -> &str {
self.as_str()
}
+
fn replacement(&self) -> &str {
self.as_str()
}
@@ -38,6 +39,7 @@
fn display(&self) -> &str {
self.display.as_str()
}
+
fn replacement(&self) -> &str {
self.replacement.as_str()
}
@@ -66,6 +68,7 @@
fn complete(&self, _line: &str, _pos: usize) -> Result<(usize, Vec<String>)> {
Ok((0, Vec::with_capacity(0)))
}
+
fn update(&self, _line: &mut LineBuffer, _start: usize, _elected: &str) {
unreachable!()
}
@@ -77,6 +80,7 @@
fn complete(&self, line: &str, pos: usize) -> Result<(usize, Vec<Self::Candidate>)> {
(**self).complete(line, pos)
}
+
fn update(&self, line: &mut LineBuffer, start: usize, elected: &str) {
(**self).update(line, start, elected)
}
diff --git a/src/edit.rs b/src/edit.rs
index 7dae766..6a82da6 100644
--- a/src/edit.rs
+++ b/src/edit.rs
@@ -80,6 +80,7 @@
self.saved_line_for_history
.update(self.line.as_str(), self.line.pos());
}
+
pub fn restore(&mut self) {
self.line.update(
self.saved_line_for_history.as_str(),
@@ -136,12 +137,15 @@
let hint = self.hint();
self.refresh(prompt, prompt_size, hint)
}
+
fn doing_insert(&mut self) {
self.changes.borrow_mut().begin();
}
+
fn done_inserting(&mut self) {
self.changes.borrow_mut().end();
}
+
fn last_insert(&self) -> Option<String> {
self.changes.borrow().last_insert()
}
diff --git a/src/history.rs b/src/history.rs
index 60821d3..76a5bcf 100644
--- a/src/history.rs
+++ b/src/history.rs
@@ -32,6 +32,7 @@
pub fn new() -> History {
Self::with_config(Config::default())
}
+
pub fn with_config(config: Config) -> History {
History {
entries: VecDeque::new(),
@@ -83,6 +84,7 @@
pub fn len(&self) -> usize {
self.entries.len()
}
+
/// Return true if the history has no entry.
pub fn is_empty(&self) -> bool {
self.entries.is_empty()
@@ -213,8 +215,8 @@
}
impl<'a> IntoIterator for &'a History {
- type Item = &'a String;
type IntoIter = Iter<'a>;
+ type Item = &'a String;
fn into_iter(self) -> Iter<'a> {
self.iter()
diff --git a/src/keymap.rs b/src/keymap.rs
index eb3d560..877a12d 100644
--- a/src/keymap.rs
+++ b/src/keymap.rs
@@ -111,6 +111,7 @@
_ => false,
}
}
+
fn is_repeatable(&self) -> bool {
match *self {
Cmd::Move(_) => true,
diff --git a/src/kill_ring.rs b/src/kill_ring.rs
index 15b6649..b5d8778 100644
--- a/src/kill_ring.rs
+++ b/src/kill_ring.rs
@@ -109,6 +109,7 @@
fn start_killing(&mut self) {
self.killing = true;
}
+
fn delete(&mut self, _: usize, string: &str, dir: Direction) {
if !self.killing {
return;
@@ -119,6 +120,7 @@
};
self.kill(string, mode);
}
+
fn stop_killing(&mut self) {
self.killing = false;
}
diff --git a/src/lib.rs b/src/lib.rs
index 9d2f876..9cd6a16 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -677,6 +677,7 @@
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.
///
@@ -710,22 +711,27 @@
pub fn load_history<P: AsRef<Path> + ?Sized>(&mut self, path: &P) -> Result<()> {
self.history.load(path)
}
+
/// Save the history in the specified file.
pub fn save_history<P: AsRef<Path> + ?Sized>(&self, path: &P) -> Result<()> {
self.history.save(path)
}
+
/// Add a new entry in the history.
pub fn add_history_entry<S: AsRef<str> + Into<String>>(&mut self, line: S) -> bool {
self.history.add(line)
}
+
/// Clear history.
pub fn clear_history(&mut self) {
self.history.clear()
}
+
/// Return a mutable reference to the history object.
pub fn get_history(&mut self) -> &mut History {
&mut self.history
}
+
/// Return an immutable reference to the history object.
pub fn get_history_const(&self) -> &History {
&self.history
@@ -747,6 +753,7 @@
let mut bindings = self.custom_bindings.write().unwrap();
bindings.insert(key_seq, cmd)
}
+
/// Remove a binding for the given sequence.
pub fn unbind_sequence(&mut self, key_seq: KeyPress) -> Option<Cmd> {
let mut bindings = self.custom_bindings.write().unwrap();
diff --git a/src/line_buffer.rs b/src/line_buffer.rs
index 1e7ddc2..1c220ca 100644
--- a/src/line_buffer.rs
+++ b/src/line_buffer.rs
@@ -93,9 +93,11 @@
pub(crate) fn set_delete_listener(&mut self, dl: Arc<Mutex<DeleteListener>>) {
self.dl = Some(dl);
}
+
pub(crate) fn set_change_listener(&mut self, dl: Rc<RefCell<ChangeListener>>) {
self.cl = Some(dl);
}
+
pub(crate) fn remove_change_listener(&mut self) {
self.cl = None;
}
@@ -114,6 +116,7 @@
pub fn pos(&self) -> usize {
self.pos
}
+
/// Set cursor position (byte position)
pub fn set_pos(&mut self, pos: usize) {
assert!(pos <= self.buf.len());
@@ -124,6 +127,7 @@
pub fn len(&self) -> usize {
self.buf.len()
}
+
/// Returns `true` if this buffer has a length of zero.
pub fn is_empty(&self) -> bool {
self.buf.is_empty()
@@ -169,6 +173,7 @@
.last()
.map(|(i, s)| i + self.pos + s.len())
}
+
/// Returns the position of the character just before the current cursor
/// position.
fn prev_pos(&self, n: RepeatCount) -> Option<usize> {
@@ -583,6 +588,7 @@
.next()
.map(|i| i + self.pos)
}
+
/// Alter the next word.
pub fn edit_word(&mut self, a: WordAction) -> bool {
if let Some(start) = self.skip_whitespace() {
@@ -872,14 +878,18 @@
impl DeleteListener for Listener {
fn start_killing(&mut self) {}
+
fn delete(&mut self, _: usize, string: &str, _: Direction) {
self.deleted_str = Some(string.to_owned());
}
+
fn stop_killing(&mut self) {}
}
impl ChangeListener for Listener {
fn insert_char(&mut self, _: usize, _: char) {}
+
fn insert_str(&mut self, _: usize, _: &str) {}
+
fn replace(&mut self, _: usize, _: &str, _: &str) {}
}
diff --git a/src/tty/mod.rs b/src/tty/mod.rs
index 1047c42..e96f676 100644
--- a/src/tty/mod.rs
+++ b/src/tty/mod.rs
@@ -77,6 +77,7 @@
fn move_cursor(&mut self, old: Position, new: Position) -> Result<()> {
(**self).move_cursor(old, new)
}
+
fn refresh_line(
&mut self,
prompt: &str,
@@ -88,27 +89,35 @@
) -> Result<(Position, Position)> {
(**self).refresh_line(prompt, prompt_size, line, hint, current_row, old_rows)
}
+
fn calculate_position(&self, s: &str, orig: Position) -> Position {
(**self).calculate_position(s, orig)
}
+
fn write_and_flush(&mut self, buf: &[u8]) -> Result<()> {
(**self).write_and_flush(buf)
}
+
fn beep(&mut self) -> Result<()> {
(**self).beep()
}
+
fn clear_screen(&mut self) -> Result<()> {
(**self).clear_screen()
}
+
fn sigwinch(&self) -> bool {
(**self).sigwinch()
}
+
fn update_size(&mut self) {
(**self).update_size()
}
+
fn get_columns(&self) -> usize {
(**self).get_columns()
}
+
fn get_rows(&self) -> usize {
(**self).get_rows()
}
diff --git a/src/tty/test.rs b/src/tty/test.rs
index b8e5df5..4166948 100644
--- a/src/tty/test.rs
+++ b/src/tty/test.rs
@@ -25,6 +25,7 @@
None => Err(ReadlineError::Eof),
}
}
+
#[cfg(unix)]
fn next_char(&mut self) -> Result<char> {
unimplemented!();
@@ -38,6 +39,7 @@
None => Err(ReadlineError::Eof),
}
}
+
#[cfg(unix)]
fn next_char(&mut self) -> Result<char> {
match self.next() {
@@ -99,10 +101,13 @@
fn sigwinch(&self) -> bool {
false
}
+
fn update_size(&mut self) {}
+
fn get_columns(&self) -> usize {
80
}
+
fn get_rows(&self) -> usize {
24
}
@@ -117,9 +122,9 @@
}
impl Term for DummyTerminal {
+ type Mode = Mode;
type Reader = IntoIter<KeyPress>;
type Writer = Sink;
- type Mode = Mode;
fn new(_color_mode: ColorMode) -> DummyTerminal {
DummyTerminal {
diff --git a/src/tty/unix.rs b/src/tty/unix.rs
index fd366d5..22dd675 100644
--- a/src/tty/unix.rs
+++ b/src/tty/unix.rs
@@ -528,6 +528,7 @@
fn get_columns(&self) -> usize {
self.cols
}
+
/// Try to get the number of rows in the current terminal,
/// or assume 24 if it fails.
fn get_rows(&self) -> usize {
@@ -566,9 +567,9 @@
}
impl Term for PosixTerminal {
+ type Mode = Mode;
type Reader = PosixRawReader;
type Writer = PosixRenderer;
- type Mode = Mode;
fn new(color_mode: ColorMode) -> PosixTerminal {
let term = PosixTerminal {
diff --git a/src/tty/windows.rs b/src/tty/windows.rs
index 5618f8c..a27b9fb 100644
--- a/src/tty/windows.rs
+++ b/src/tty/windows.rs
@@ -407,9 +407,9 @@
impl Console {}
impl Term for Console {
+ type Mode = Mode;
type Reader = ConsoleRawReader;
type Writer = ConsoleRenderer;
- type Mode = Mode;
fn new(color_mode: ColorMode) -> Console {
use std::ptr;
diff --git a/src/undo.rs b/src/undo.rs
index 333e5b4..7f7c9ab 100644
--- a/src/undo.rs
+++ b/src/undo.rs
@@ -329,18 +329,22 @@
impl DeleteListener for Changeset {
fn start_killing(&mut self) {}
+
fn delete(&mut self, idx: usize, string: &str, _: Direction) {
self.delete(idx, string);
}
+
fn stop_killing(&mut self) {}
}
impl ChangeListener for Changeset {
fn insert_char(&mut self, idx: usize, c: char) {
self.insert(idx, c);
}
+
fn insert_str(&mut self, idx: usize, string: &str) {
self.insert_str(idx, string);
}
+
fn replace(&mut self, idx: usize, old: &str, new: &str) {
self.replace(idx, old, new);
}