Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into history_recent_index
Browse files Browse the repository at this point in the history
  • Loading branch information
gwenn committed Aug 18, 2024
2 parents c1fef6b + e4eca97 commit 99c6c31
Show file tree
Hide file tree
Showing 20 changed files with 184 additions and 190 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,16 @@ jobs:
run: cargo check --workspace --no-default-features
env:
RUSTFLAGS: "-D warnings"

direct-minimal-versions:
name: Test min versions
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- uses: hecrj/setup-rust-action@v2
with:
rust-version: nightly
- run: |
cargo update -Z direct-minimal-versions
cargo test --workspace --all-targets
16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ maintenance = { status = "actively-developed" }
members = ["rustyline-derive"]

[dependencies]
bitflags = "2.0"
bitflags = "2.6"
cfg-if = "1.0"
# For file completion
home = { version = "0.5.4", optional = true }
# For History
fd-lock = { version = "4.0.0", optional = true }
rusqlite = { version = "0.31.0", optional = true, default-features = false, features = ["bundled", "backup"] }
libc = "0.2"
log = "0.4"
unicode-width = "0.1"
rusqlite = { version = "0.32.0", optional = true, default-features = false, features = ["bundled", "backup"] }
libc = "0.2.155"
log = "0.4.22"
unicode-width = "0.1.13"
unicode-segmentation = "1.0"
memchr = "2.0"
memchr = "2.7"
# For custom bindings
radix_trie = { version = "0.2", optional = true }
regex = { version = "1.5.5", optional = true }
regex = { version = "1.10", optional = true }
# For derive
rustyline-derive = { version = "0.10.0", optional = true, path = "rustyline-derive" }

Expand All @@ -50,7 +50,7 @@ termios = { version = "0.3.3", optional = true }
buffer-redux = { version = "1.0", optional = true, default-features = false }

[target.'cfg(windows)'.dependencies]
windows-sys = { version = "0.52.0", features = ["Win32_Foundation", "Win32_System_Console", "Win32_Security", "Win32_System_Threading", "Win32_UI_Input_KeyboardAndMouse"] }
windows-sys = { version = "0.59.0", features = ["Win32_Foundation", "Win32_System_Console", "Win32_Security", "Win32_System_Threading", "Win32_UI_Input_KeyboardAndMouse"] }
clipboard-win = "5.0"

[dev-dependencies]
Expand Down
8 changes: 4 additions & 4 deletions examples/diy_hints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ impl Hint for CommandHint {
}

impl CommandHint {
fn new(text: &str, complete_up_to: &str) -> CommandHint {
fn new(text: &str, complete_up_to: &str) -> Self {
assert!(text.starts_with(complete_up_to));
CommandHint {
Self {
display: text.into(),
complete_up_to: complete_up_to.len(),
}
}

fn suffix(&self, strip_chars: usize) -> CommandHint {
CommandHint {
fn suffix(&self, strip_chars: usize) -> Self {
Self {
display: self.display[strip_chars..].to_owned(),
complete_up_to: self.complete_up_to.saturating_sub(strip_chars),
}
Expand Down
6 changes: 3 additions & 3 deletions rustyline-derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ maintenance = { status = "actively-developed" }
proc-macro = true

[dependencies]
syn = { version = "2.0", default-features = false, features = ["derive", "parsing", "printing", "proc-macro"] }
quote = { version = "1.0", default-features = false }
proc-macro2 = { version = "1.0", default-features = false }
syn = { version = "2.0.72", default-features = false, features = ["derive", "parsing", "printing", "proc-macro"] }
quote = { version = "1.0.36", default-features = false }
proc-macro2 = { version = "1.0.86", default-features = false }
20 changes: 10 additions & 10 deletions src/binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub enum Event {
impl Event {
/// See [`KeyEvent::normalize`]
pub(crate) fn normalize(mut self) -> Self {
if let Event::KeySeq(ref mut keys) = self {
if let Self::KeySeq(ref mut keys) = self {
for key in keys.iter_mut() {
*key = KeyEvent::normalize(*key);
}
Expand All @@ -32,7 +32,7 @@ impl Event {
/// Return `i`th key event
#[must_use]
pub fn get(&self, i: usize) -> Option<&KeyEvent> {
if let Event::KeySeq(ref ks) = self {
if let Self::KeySeq(ref ks) = self {
ks.get(i)
} else {
None
Expand All @@ -41,8 +41,8 @@ impl Event {
}

impl From<KeyEvent> for Event {
fn from(k: KeyEvent) -> Event {
Event::KeySeq(vec![k])
fn from(k: KeyEvent) -> Self {
Self::KeySeq(vec![k])
}
}

Expand Down Expand Up @@ -107,15 +107,15 @@ impl KeyEvent {
impl TrieKey for Event {
fn encode_bytes(&self) -> Vec<u8> {
match self {
Event::Any => ANY.to_be_bytes().to_vec(),
Event::KeySeq(keys) => {
Self::Any => ANY.to_be_bytes().to_vec(),
Self::KeySeq(keys) => {
let mut dst = Vec::with_capacity(keys.len() * 4);
for key in keys {
dst.extend_from_slice(&key.encode().to_be_bytes());
}
dst
}
Event::Mouse() => MOUSE.to_be_bytes().to_vec(),
Self::Mouse() => MOUSE.to_be_bytes().to_vec(),
}
}
}
Expand All @@ -132,8 +132,8 @@ pub enum EventHandler {
}

impl From<Cmd> for EventHandler {
fn from(c: Cmd) -> EventHandler {
EventHandler::Simple(c)
fn from(c: Cmd) -> Self {
Self::Simple(c)
}
}

Expand All @@ -147,7 +147,7 @@ pub struct EventContext<'r> {

impl<'r> EventContext<'r> {
pub(crate) fn new(is: &InputState, wrt: &'r dyn Refresher) -> Self {
EventContext {
Self {
mode: is.mode,
input_mode: is.input_mode,
wrt,
Expand Down
12 changes: 4 additions & 8 deletions src/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,7 @@ impl Completer for FilenameCompleter {
/// Remove escape char
#[must_use]
pub fn unescape(input: &str, esc_char: Option<char>) -> Cow<'_, str> {
let esc_char = if let Some(c) = esc_char {
c
} else {
let Some(esc_char) = esc_char else {
return Borrowed(input);
};
if !input.chars().any(|c| c == esc_char) {
Expand Down Expand Up @@ -310,9 +308,7 @@ pub fn escape(
if n == 0 {
return input; // no need to escape
}
let esc_char = if let Some(c) = esc_char {
c
} else {
let Some(esc_char) = esc_char else {
if cfg!(windows) && quote == Quote::None {
input.insert(0, '"'); // force double quote
return input;
Expand Down Expand Up @@ -375,7 +371,7 @@ fn filename_complete(
dir_path.to_path_buf()
};

let mut entries: Vec<Pair> = Vec::new();
let mut entries: Vec<Pair> = vec![];

// if dir doesn't exist, then don't offer any completions
if !dir.exists() {
Expand Down Expand Up @@ -617,7 +613,7 @@ mod tests {
assert_eq!(Some(s), lcp);
}

let c3 = String::from("");
let c3 = String::new();
candidates.push(c3);
{
let lcp = super::longest_common_prefix(&candidates);
Expand Down
4 changes: 2 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,12 @@ pub enum BellStyle {
impl Default for BellStyle {
#[cfg(any(windows, target_arch = "wasm32"))]
fn default() -> Self {
BellStyle::None
Self::None
}

#[cfg(unix)]
fn default() -> Self {
BellStyle::Audible
Self::Audible
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ impl<'out, 'prompt, H: Helper> State<'out, 'prompt, H> {
prompt: &'prompt str,
helper: Option<&'out H>,
ctx: Context<'out>,
) -> State<'out, 'prompt, H> {
) -> Self {
let prompt_size = out.calculate_position(prompt, Position::default());
State {
Self {
out,
prompt,
prompt_size,
Expand Down
52 changes: 26 additions & 26 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub enum ReadlineError {
/// Unix Error from syscall
#[cfg(unix)]
Errno(nix::Error),
/// Error generated on WINDOW_BUFFER_SIZE_EVENT / SIGWINCH signal
/// Error generated on `WINDOW_BUFFER_SIZE_EVENT` / `SIGWINCH` signal
WindowResized,
/// Like Utf8Error on unix
#[cfg(windows)]
Expand All @@ -37,37 +37,37 @@ pub enum ReadlineError {
impl fmt::Display for ReadlineError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
ReadlineError::Io(ref err) => err.fmt(f),
ReadlineError::Eof => write!(f, "EOF"),
ReadlineError::Interrupted => write!(f, "Interrupted"),
Self::Io(ref err) => err.fmt(f),
Self::Eof => write!(f, "EOF"),
Self::Interrupted => write!(f, "Interrupted"),
#[cfg(unix)]
ReadlineError::Errno(ref err) => err.fmt(f),
ReadlineError::WindowResized => write!(f, "WindowResized"),
Self::Errno(ref err) => err.fmt(f),
Self::WindowResized => write!(f, "WindowResized"),
#[cfg(windows)]
ReadlineError::Decode(ref err) => err.fmt(f),
Self::Decode(ref err) => err.fmt(f),
#[cfg(windows)]
ReadlineError::SystemError(ref err) => err.fmt(f),
Self::SystemError(ref err) => err.fmt(f),
#[cfg(feature = "with-sqlite-history")]
ReadlineError::SQLiteError(ref err) => err.fmt(f),
Self::SQLiteError(ref err) => err.fmt(f),
}
}
}

impl Error for ReadlineError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match *self {
ReadlineError::Io(ref err) => Some(err),
ReadlineError::Eof => None,
ReadlineError::Interrupted => None,
Self::Io(ref err) => Some(err),
Self::Eof => None,
Self::Interrupted => None,
#[cfg(unix)]
ReadlineError::Errno(ref err) => Some(err),
ReadlineError::WindowResized => None,
Self::Errno(ref err) => Some(err),
Self::WindowResized => None,
#[cfg(windows)]
ReadlineError::Decode(ref err) => Some(err),
Self::Decode(ref err) => Some(err),
#[cfg(windows)]
ReadlineError::SystemError(_) => None,
Self::SystemError(_) => None,
#[cfg(feature = "with-sqlite-history")]
ReadlineError::SQLiteError(ref err) => Some(err),
Self::SQLiteError(ref err) => Some(err),
}
}
}
Expand All @@ -90,58 +90,58 @@ impl From<io::Error> for ReadlineError {
if err.kind() == io::ErrorKind::Interrupted {
if let Some(e) = err.get_ref() {
if e.downcast_ref::<WindowResizedError>().is_some() {
return ReadlineError::WindowResized;
return Self::WindowResized;
}
}
}
ReadlineError::Io(err)
Self::Io(err)
}
}

impl From<io::ErrorKind> for ReadlineError {
fn from(kind: io::ErrorKind) -> Self {
ReadlineError::Io(io::Error::from(kind))
Self::Io(io::Error::from(kind))
}
}

#[cfg(unix)]
impl From<nix::Error> for ReadlineError {
fn from(err: nix::Error) -> Self {
ReadlineError::Errno(err)
Self::Errno(err)
}
}

#[cfg(windows)]
impl From<char::DecodeUtf16Error> for ReadlineError {
fn from(err: char::DecodeUtf16Error) -> Self {
ReadlineError::Io(io::Error::new(io::ErrorKind::InvalidData, err))
Self::Io(io::Error::new(io::ErrorKind::InvalidData, err))
}
}

#[cfg(windows)]
impl From<std::string::FromUtf8Error> for ReadlineError {
fn from(err: std::string::FromUtf8Error) -> Self {
ReadlineError::Io(io::Error::new(io::ErrorKind::InvalidData, err))
Self::Io(io::Error::new(io::ErrorKind::InvalidData, err))
}
}

#[cfg(unix)]
impl From<fmt::Error> for ReadlineError {
fn from(err: fmt::Error) -> Self {
ReadlineError::Io(io::Error::new(io::ErrorKind::Other, err))
Self::Io(io::Error::new(io::ErrorKind::Other, err))
}
}

#[cfg(windows)]
impl From<clipboard_win::ErrorCode> for ReadlineError {
fn from(err: clipboard_win::ErrorCode) -> Self {
ReadlineError::SystemError(err)
Self::SystemError(err)
}
}

#[cfg(feature = "with-sqlite-history")]
impl From<rusqlite::Error> for ReadlineError {
fn from(err: rusqlite::Error) -> Self {
ReadlineError::SQLiteError(err)
Self::SQLiteError(err)
}
}
4 changes: 2 additions & 2 deletions src/hint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ pub struct HistoryHinter {}

impl HistoryHinter {
/// Create a new `HistoryHinter`
pub fn new() -> HistoryHinter {
HistoryHinter::default()
pub fn new() -> Self {
Self::default()
}
}

Expand Down
Loading

0 comments on commit 99c6c31

Please sign in to comment.