Skip to content
Merged
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
52 changes: 26 additions & 26 deletions src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,40 +184,34 @@ impl DerefMut for PtySession {
}
}

/// Start a process in a tty session, write and read from it
///
/// # Example
///
/// ```
///
/// use rexpect::spawn;
/// # use rexpect::error::Error;
///
/// # fn main() {
/// # || -> Result<(), Error> {
/// let mut s = spawn("cat", Some(1000))?;
/// s.send_line("hello, polly!")?;
/// let line = s.read_line()?;
/// assert_eq!("hello, polly!", line);
/// # Ok(())
/// # }().expect("test failed");
/// # }
/// ```
impl PtySession {
fn new(process: PtyProcess, options: Options) -> Result<Self, Error> {
/// Start a process in a tty session, write and read from it
///
/// # Example
///
/// ```
///
/// use rexpect::spawn;
/// # use rexpect::error::Error;
///
/// # fn main() {
/// # || -> Result<(), Error> {
/// let mut s = spawn("cat", Some(1000))?;
/// s.send_line("hello, polly!")?;
/// let line = s.read_line()?;
/// assert_eq!("hello, polly!", line);
/// # Ok(())
/// # }().expect("test failed");
/// # }
/// ```
pub fn new(process: PtyProcess, options: Options) -> Result<Self, Error> {
let f = process.get_file_handle()?;
let reader = f.try_clone()?;
let stream = StreamSession::new(reader, f, options);
Ok(Self { process, stream })
}
}

/// Turn e.g. "prog arg1 arg2" into ["prog", "arg1", "arg2"]
/// Also takes care of single and double quotes
fn tokenize_command(program: &str) -> Result<Vec<String>, Error> {
comma::parse_command(program).ok_or(Error::BadProgramArguments)
}

/// Start command in background in a pty session (pty fork) and return a struct
/// with writer and buffered reader (for unblocking reads).
///
Expand All @@ -243,6 +237,12 @@ pub fn spawn(program: &str, timeout_ms: Option<u64>) -> Result<PtySession, Error
spawn_command(command, timeout_ms)
}

/// Turn e.g. "prog arg1 arg2" into ["prog", "arg1", "arg2"]
/// Also takes care of single and double quotes
fn tokenize_command(program: &str) -> Result<Vec<String>, Error> {
comma::parse_command(program).ok_or(Error::BadProgramArguments)
}

/// See [`spawn`]
pub fn spawn_command(command: Command, timeout_ms: Option<u64>) -> Result<PtySession, Error> {
spawn_with_options(
Expand Down
Loading