@@ -184,40 +184,34 @@ impl DerefMut for PtySession {
184184 }
185185}
186186
187- /// Start a process in a tty session, write and read from it
188- ///
189- /// # Example
190- ///
191- /// ```
192- ///
193- /// use rexpect::spawn;
194- /// # use rexpect::error::Error;
195- ///
196- /// # fn main() {
197- /// # || -> Result<(), Error> {
198- /// let mut s = spawn("cat", Some(1000))?;
199- /// s.send_line("hello, polly!")?;
200- /// let line = s.read_line()?;
201- /// assert_eq!("hello, polly!", line);
202- /// # Ok(())
203- /// # }().expect("test failed");
204- /// # }
205- /// ```
206187impl PtySession {
207- fn new ( process : PtyProcess , options : Options ) -> Result < Self , Error > {
188+ /// Start a process in a tty session, write and read from it
189+ ///
190+ /// # Example
191+ ///
192+ /// ```
193+ ///
194+ /// use rexpect::spawn;
195+ /// # use rexpect::error::Error;
196+ ///
197+ /// # fn main() {
198+ /// # || -> Result<(), Error> {
199+ /// let mut s = spawn("cat", Some(1000))?;
200+ /// s.send_line("hello, polly!")?;
201+ /// let line = s.read_line()?;
202+ /// assert_eq!("hello, polly!", line);
203+ /// # Ok(())
204+ /// # }().expect("test failed");
205+ /// # }
206+ /// ```
207+ pub fn new ( process : PtyProcess , options : Options ) -> Result < Self , Error > {
208208 let f = process. get_file_handle ( ) ?;
209209 let reader = f. try_clone ( ) ?;
210210 let stream = StreamSession :: new ( reader, f, options) ;
211211 Ok ( Self { process, stream } )
212212 }
213213}
214214
215- /// Turn e.g. "prog arg1 arg2" into ["prog", "arg1", "arg2"]
216- /// Also takes care of single and double quotes
217- fn tokenize_command ( program : & str ) -> Result < Vec < String > , Error > {
218- comma:: parse_command ( program) . ok_or ( Error :: BadProgramArguments )
219- }
220-
221215/// Start command in background in a pty session (pty fork) and return a struct
222216/// with writer and buffered reader (for unblocking reads).
223217///
@@ -243,6 +237,12 @@ pub fn spawn(program: &str, timeout_ms: Option<u64>) -> Result<PtySession, Error
243237 spawn_command ( command, timeout_ms)
244238}
245239
240+ /// Turn e.g. "prog arg1 arg2" into ["prog", "arg1", "arg2"]
241+ /// Also takes care of single and double quotes
242+ fn tokenize_command ( program : & str ) -> Result < Vec < String > , Error > {
243+ comma:: parse_command ( program) . ok_or ( Error :: BadProgramArguments )
244+ }
245+
246246/// See [`spawn`]
247247pub fn spawn_command ( command : Command , timeout_ms : Option < u64 > ) -> Result < PtySession , Error > {
248248 spawn_with_options (
0 commit comments