From eb2035bff3d534f70da49210b6756f6011437021 Mon Sep 17 00:00:00 2001 From: Ryan Lopopolo Date: Sat, 9 Apr 2022 20:38:15 -0700 Subject: [PATCH] Replace `buf_redux` with `BufReader` from `std` `rustyline` depends on `buf_redux` for two calls to `get_len`, but these calls can be replaced with calls to `reader.buffer().len()` using APIs in `std` that have been available since Rust 1.37.0: https://doc.rust-lang.org/std/io/struct.BufReader.html#method.buffer `std::io::BufReader::buffer` does not cause any additional reads to occur and exposes the internal buffered and unread contents of the `BufReader`. Motivation for this commit is reducing dependencies. --- Cargo.toml | 1 - src/tty/unix.rs | 7 +++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3a0be3485..57600ad39 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -45,7 +45,6 @@ regex = { version = "1.5.4", optional = true } nix = "0.23" utf8parse = "0.2" skim = { version = "0.9", optional = true } -buf_redux = { version = "0.8", default-features = false } [target.'cfg(windows)'.dependencies] winapi = { version = "0.3", features = ["consoleapi", "handleapi", "synchapi", "minwindef", "processenv", "std", "winbase", "wincon", "winuser"] } diff --git a/src/tty/unix.rs b/src/tty/unix.rs index 6f1c7034a..05fd4a6e3 100644 --- a/src/tty/unix.rs +++ b/src/tty/unix.rs @@ -2,13 +2,12 @@ use std::cmp; use std::collections::HashMap; use std::fs::{File, OpenOptions}; -use std::io::{self, ErrorKind, Read, Write}; +use std::io::{self, BufReader, ErrorKind, Read, Write}; use std::os::unix::io::{AsRawFd, IntoRawFd, RawFd}; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::mpsc::{self, SyncSender}; use std::sync::{self, Arc, Mutex}; -use buf_redux::BufReader; use log::{debug, warn}; use nix::errno::Errno; use nix::poll::{self, PollFlags}; @@ -657,7 +656,7 @@ impl PosixRawReader { } fn poll(&mut self, timeout_ms: i32) -> ::nix::Result { - let n = self.tty_in.buf_len(); + let n = self.tty_in.buffer().len(); if n > 0 { return Ok(n as i32); } @@ -732,7 +731,7 @@ impl RawReader for PosixRawReader { let mut key = KeyEvent::new(c, M::NONE); if key == E::ESC { - if self.tty_in.buf_len() > 0 { + if !self.tty_in.buffer().is_empty() { debug!(target: "rustyline", "read buffer {:?}", self.tty_in.buffer()); } let timeout_ms = if single_esc_abort && self.timeout_ms == -1 {