Skip to content

Commit

Permalink
Rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
gwenn committed Nov 27, 2024
1 parent 28b1646 commit ab6598c
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 60 deletions.
34 changes: 20 additions & 14 deletions src/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,21 +334,27 @@ fn filename_complete(
if let Ok(read_dir) = dir.read_dir() {
let file_name = normalize(file_name);
for entry in read_dir.flatten() {
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
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
}
}
} _ => {}}
_ => {}
}
}
}
entries
Expand Down
34 changes: 20 additions & 14 deletions src/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,25 +229,31 @@ impl MemHistory {
.skip(self.len() - 1 - start)
.enumerate()
{
match test(entry) { Some(cursor) => {
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() {
match test(entry) { Some(cursor) => {
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
15 changes: 9 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -707,13 +707,16 @@ 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() {
match s.move_cursor_at_leftmost(&mut rdr) { Err(e) => {
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
66 changes: 40 additions & 26 deletions src/tty/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -757,14 +757,22 @@ 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 { 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));
} _ => {}}
} _ => {}}}
} 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,19 +1312,20 @@ 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");
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)
} _ => {
(
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 {
(
libc::STDIN_FILENO,
Expand Down Expand Up @@ -1494,16 +1503,21 @@ 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 { 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
}}}
} else {
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

0 comments on commit ab6598c

Please sign in to comment.