Skip to content
Merged
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
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[workspace]
resolver = "2"
resolver = "3"

[workspace.package]
repository = "https://github.com/rust-cli/rexpect"
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.70.0" # MSRV
edition = "2024"
rust-version = "1.85.0" # MSRV
include = [
"build.rs",
"src/**/*",
Expand Down
10 changes: 5 additions & 5 deletions src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

use crate::error::Error;
use nix;
use nix::fcntl::{open, OFlag};
use nix::fcntl::{OFlag, open};
use nix::libc::STDERR_FILENO;
use nix::pty::{grantpt, posix_openpt, unlockpt, PtyMaster};
use nix::pty::{PtyMaster, grantpt, posix_openpt, unlockpt};
pub use nix::sys::{signal, wait};
use nix::sys::{stat, termios};
use nix::unistd::{
close, dup, dup2_stderr, dup2_stdin, dup2_stdout, fork, setsid, ForkResult, Pid,
ForkResult, Pid, close, dup, dup2_stderr, dup2_stdin, dup2_stdout, fork, setsid,
};
use std;
use std::fs::File;
Expand Down Expand Up @@ -68,7 +68,7 @@ use nix::pty::ptsname_r;
/// instead of using a static mutex this calls ioctl with TIOCPTYGNAME directly
/// based on https://blog.tarq.io/ptsname-on-osx-with-rust/
fn ptsname_r(fd: &PtyMaster) -> nix::Result<String> {
use nix::libc::{ioctl, TIOCPTYGNAME};
use nix::libc::{TIOCPTYGNAME, ioctl};
use std::ffi::CStr;

// the buffer size on OSX is 128, defined by sys/ttycom.h
Expand Down Expand Up @@ -207,7 +207,7 @@ impl PtyProcess {
Ok(_) => {}
// process was already killed before -> ignore
Err(nix::errno::Errno::ESRCH) => {
return Ok(wait::WaitStatus::Exited(Pid::from_raw(0), 0))
return Ok(wait::WaitStatus::Exited(Pid::from_raw(0), 0));
}
Err(e) => return Err(Error::from(e)),
}
Expand Down
18 changes: 9 additions & 9 deletions src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::error::Error;
pub use regex::Regex;
use std::io::prelude::*;
use std::io::{self, BufReader};
use std::sync::mpsc::{channel, Receiver};
use std::sync::mpsc::{Receiver, channel};
use std::thread;
use std::{fmt, time};

Expand All @@ -31,13 +31,13 @@ pub enum ReadUntil {
impl fmt::Display for ReadUntil {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let printable = match self {
ReadUntil::String(ref s) if s == "\n" => "\\n (newline)".to_owned(),
ReadUntil::String(ref s) if s == "\r" => "\\r (carriage return)".to_owned(),
ReadUntil::String(ref s) => format!("\"{s}\""),
ReadUntil::Regex(ref r) => format!("Regex: \"{r}\""),
ReadUntil::String(s) if s == "\n" => "\\n (newline)".to_owned(),
ReadUntil::String(s) if s == "\r" => "\\r (carriage return)".to_owned(),
ReadUntil::String(s) => format!("\"{s}\""),
ReadUntil::Regex(r) => format!("Regex: \"{r}\""),
ReadUntil::EOF => "EOF (End of File)".to_owned(),
ReadUntil::NBytes(n) => format!("reading {n} bytes"),
ReadUntil::Any(ref v) => {
ReadUntil::Any(v) => {
let mut res = Vec::new();
for r in v {
res.push(r.to_string());
Expand All @@ -63,8 +63,8 @@ impl fmt::Display for ReadUntil {
/// 2. position after match
pub fn find(needle: &ReadUntil, buffer: &str, eof: bool) -> Option<(usize, usize)> {
match needle {
ReadUntil::String(ref s) => buffer.find(s).map(|pos| (pos, pos + s.len())),
ReadUntil::Regex(ref pattern) => pattern.find(buffer).map(|mat| (mat.start(), mat.end())),
ReadUntil::String(s) => buffer.find(s).map(|pos| (pos, pos + s.len())),
ReadUntil::Regex(pattern) => pattern.find(buffer).map(|mat| (mat.start(), mat.end())),
ReadUntil::EOF => {
if eof {
Some((0, buffer.len()))
Expand All @@ -83,7 +83,7 @@ pub fn find(needle: &ReadUntil, buffer: &str, eof: bool) -> Option<(usize, usize
None
}
}
ReadUntil::Any(ref anys) => anys
ReadUntil::Any(anys) => anys
.iter()
// Filter matching needles
.filter_map(|any| find(any, buffer, eof))
Expand Down
2 changes: 1 addition & 1 deletion src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use crate::process::PtyProcess;
use crate::reader::{NBReader, Regex};
pub use crate::reader::{Options, ReadUntil};
use std::fs::File;
use std::io::prelude::*;
use std::io::LineWriter;
use std::io::prelude::*;
use std::ops::{Deref, DerefMut};
use std::process::Command;
use tempfile;
Expand Down
Loading