Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cargo +nightly fix --edition #829

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl Event {
/// Return `i`th key event
#[must_use]
pub fn get(&self, i: usize) -> Option<&KeyEvent> {
if let Self::KeySeq(ref ks) = self {
if let &Self::KeySeq(ref ks) = self {
ks.get(i)
} else {
None
Expand Down
32 changes: 19 additions & 13 deletions src/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,20 +334,26 @@ fn filename_complete(
if let Ok(read_dir) = dir.read_dir() {
let file_name = normalize(file_name);
for entry in read_dir.flatten() {
if let Some(s) = entry.file_name().to_str() {
let ns = normalize(s);
if ns.starts_with(file_name.as_ref()) {
if let Ok(metadata) = fs::metadata(entry.path()) {
let mut path = String::from(dir_name) + s;
if metadata.is_dir() {
path.push(sep);
}
entries.push(Pair {
display: String::from(s),
replacement: escape(path, esc_char, is_break_char, quote),
});
} // else ignore PermissionDenied
match entry.file_name().to_str() {
Some(s) => {
let ns = normalize(s);
if ns.starts_with(file_name.as_ref()) {
match fs::metadata(entry.path()) {
Ok(metadata) => {
let mut path = String::from(dir_name) + s;
if metadata.is_dir() {
path.push(sep);
}
entries.push(Pair {
display: String::from(s),
replacement: escape(path, esc_char, is_break_char, quote),
});
}
_ => {}
} // else ignore PermissionDenied
}
}
_ => {}
}
}
}
Expand Down
30 changes: 18 additions & 12 deletions src/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,24 +229,30 @@ impl MemHistory {
.skip(self.len() - 1 - start)
.enumerate()
{
if let Some(cursor) = test(entry) {
return Some(SearchResult {
idx: start - idx,
entry: Cow::Borrowed(entry),
pos: cursor,
});
match test(entry) {
Some(cursor) => {
return Some(SearchResult {
idx: start - idx,
entry: Cow::Borrowed(entry),
pos: cursor,
});
}
_ => {}
}
}
None
}
SearchDirection::Forward => {
for (idx, entry) in self.entries.iter().skip(start).enumerate() {
if let Some(cursor) = test(entry) {
return Some(SearchResult {
idx: idx + start,
entry: Cow::Borrowed(entry),
pos: cursor,
});
match test(entry) {
Some(cursor) => {
return Some(SearchResult {
idx: idx + start,
entry: Cow::Borrowed(entry),
pos: cursor,
});
}
_ => {}
}
}
None
Expand Down
2 changes: 1 addition & 1 deletion src/keymap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,7 @@ impl InputState<'_> {
) -> Result<Option<Cmd>> {
while let Some(subtrie) = self.custom_bindings.get_raw_descendant(evt) {
let snd_key = rdr.next_key(true)?;
if let Event::KeySeq(ref mut key_seq) = evt {
if let &mut Event::KeySeq(ref mut key_seq) = evt {
key_seq.push(snd_key);
} else {
break;
Expand Down
13 changes: 8 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -707,12 +707,15 @@ impl<H: Helper, I: History> Editor<H, I> {
.term
.create_reader(self.buffer.take(), &self.config, term_key_map);
if self.term.is_output_tty() && self.config.check_cursor_position() {
if let Err(e) = s.move_cursor_at_leftmost(&mut rdr) {
if let ReadlineError::WindowResized = e {
s.out.update_size();
} else {
return Err(e);
match s.move_cursor_at_leftmost(&mut rdr) {
Err(e) => {
if let ReadlineError::WindowResized = e {
s.out.update_size();
} else {
return Err(e);
}
}
_ => {}
}
}
s.refresh_line()?;
Expand Down
60 changes: 37 additions & 23 deletions src/tty/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -757,12 +757,20 @@ impl PosixRawReader {
} else if readfds.contains(tty_in) {
// prefer user input over external print
return self.next_key(single_esc_abort).map(Event::KeyPress);
} else if let Some(ref pipe_reader) = self.pipe_reader {
let mut guard = pipe_reader.lock().unwrap();
let mut buf = [0; 1];
guard.0.read_exact(&mut buf)?;
if let Ok(msg) = guard.1.try_recv() {
return Ok(Event::ExternalPrint(msg));
} else {
match self.pipe_reader {
Some(ref pipe_reader) => {
let mut guard = pipe_reader.lock().unwrap();
let mut buf = [0; 1];
guard.0.read_exact(&mut buf)?;
match guard.1.try_recv() {
Ok(msg) => {
return Ok(Event::ExternalPrint(msg));
}
_ => {}
}
}
_ => {}
}
}
}
Expand Down Expand Up @@ -1304,18 +1312,19 @@ impl Term for PosixTerminal {
let (tty_in, is_in_a_tty, tty_out, is_out_a_tty, close_on_drop) =
if behavior == Behavior::PreferTerm {
let tty = OpenOptions::new().read(true).write(true).open("/dev/tty");
if let Ok(tty) = tty {
let fd = tty.into_raw_fd();
let is_a_tty = is_a_tty(fd); // TODO: useless ?
(fd, is_a_tty, fd, is_a_tty, true)
} else {
(
match tty {
Ok(tty) => {
let fd = tty.into_raw_fd();
let is_a_tty = is_a_tty(fd); // TODO: useless ?
(fd, is_a_tty, fd, is_a_tty, true)
}
_ => (
libc::STDIN_FILENO,
is_a_tty(libc::STDIN_FILENO),
libc::STDOUT_FILENO,
is_a_tty(libc::STDOUT_FILENO),
false,
)
),
}
} else {
(
Expand Down Expand Up @@ -1494,15 +1503,20 @@ impl super::ExternalPrinter for ExternalPrinter {
// write directly to stdout/stderr while not in raw mode
if !self.raw_mode.load(Ordering::SeqCst) {
write_all(self.tty_out, msg.as_str())?;
} else if let Ok(mut writer) = self.writer.0.lock() {
self.writer
.1
.send(msg)
.map_err(|_| io::Error::from(ErrorKind::Other))?; // FIXME
writer.write_all(b"m")?;
writer.flush()?;
} else {
return Err(io::Error::from(ErrorKind::Other).into()); // FIXME
match self.writer.0.lock() {
Ok(mut writer) => {
self.writer
.1
.send(msg)
.map_err(|_| io::Error::from(ErrorKind::Other))?; // FIXME
writer.write_all(b"m")?;
writer.flush()?;
}
_ => {
return Err(io::Error::from(ErrorKind::Other).into()); // FIXME
}
}
}
Ok(())
}
Expand Down Expand Up @@ -1655,10 +1669,10 @@ mod test {

#[test]
fn test_unsupported_term() {
std::env::set_var("TERM", "xterm");
unsafe { std::env::set_var("TERM", "xterm") };
assert!(!super::is_unsupported_term());

std::env::set_var("TERM", "dumb");
unsafe { std::env::set_var("TERM", "dumb") };
assert!(super::is_unsupported_term());
}

Expand Down
4 changes: 2 additions & 2 deletions src/undo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,8 @@ impl Changeset {
pub(crate) fn last_insert(&self) -> Option<String> {
for change in self.undos.iter().rev() {
match change {
Change::Insert { ref text, .. } => return Some(text.clone()),
Change::Replace { ref new, .. } => return Some(new.clone()),
&Change::Insert { ref text, .. } => return Some(text.clone()),
&Change::Replace { ref new, .. } => return Some(new.clone()),
Change::End => {
continue;
}
Expand Down
Loading