Skip to content

Commit 029796a

Browse files
committed
fix(session)!: Make PtyReplSession fields private
1 parent 22a230d commit 029796a

2 files changed

Lines changed: 7 additions & 12 deletions

File tree

examples/repl.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,15 @@ use rexpect::session::PtyReplSession;
55
use rexpect::spawn;
66

77
fn ed_session() -> Result<PtyReplSession, Error> {
8-
let mut ed = PtyReplSession {
8+
let mut ed = PtyReplSession::new(spawn("/bin/ed -p '> '", Some(2000))?, "> ".to_owned())
99
// for `echo_on` you need to figure that out by trial and error.
1010
// For bash and python repl it is false
11-
echo_on: false,
12-
13-
// used for `wait_for_prompt()`
14-
prompt: "> ".to_owned(),
15-
pty_session: spawn("/bin/ed -p '> '", Some(2000))?,
11+
.echo_on(false)
1612
// command which is sent when the instance of this struct is dropped
1713
// in the below example this is not needed, but if you don't explicitly
1814
// exit a REPL then rexpect tries to send a SIGTERM and depending on the repl
1915
// this does not end the repl and would end up in an error
20-
quit_command: Some("Q".to_owned()),
21-
};
16+
.quit_command(Some("Q".to_owned()));
2217
ed.wait_for_prompt()?;
2318
Ok(ed)
2419
}

src/session.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,10 @@ pub fn spawn_with_options(command: Command, options: Options) -> Result<PtySessi
273273
/// You have a prompt where a user inputs commands and the shell
274274
/// executes it and writes some output
275275
pub struct PtyReplSession {
276-
pub pty_session: PtySession,
277-
pub prompt: String,
278-
pub quit_command: Option<String>,
279-
pub echo_on: bool,
276+
pty_session: PtySession,
277+
prompt: String,
278+
quit_command: Option<String>,
279+
echo_on: bool,
280280
}
281281

282282
impl PtyReplSession {

0 commit comments

Comments
 (0)