Skip to content

Commit cd038c5

Browse files
committed
feat(session): Provide constructor for PtyReplSession
1 parent 8a0b761 commit cd038c5

1 file changed

Lines changed: 30 additions & 10 deletions

File tree

src/session.rs

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -273,25 +273,45 @@ 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-
/// The `pty_session` you prepared before (initiating the shell, maybe set a custom prompt, etc.)
277-
///
278-
/// See [`spawn_bash`] for an example
279276
pub pty_session: PtySession,
280-
281-
/// The prompt, used for `wait_for_prompt`, e.g. ">>> " for python
282277
pub prompt: String,
283-
284-
/// If set, then the `quit_command` is called when this object is dropped
285-
/// you need to provide this if the shell you're testing is not killed by just sending
286-
/// SIGTERM
287278
pub quit_command: Option<String>,
279+
pub echo_on: bool,
280+
}
281+
282+
impl PtyReplSession {
283+
/// Start a REPL session
284+
///
285+
/// `prompt`: used for [`Self::wait_for_prompt`], e.g. ">>> " for python
286+
///
287+
/// See [`spawn_bash`] for an example
288+
pub fn new(pty_session: PtySession, prompt: String) -> Self {
289+
Self {
290+
pty_session,
291+
prompt,
292+
quit_command: None,
293+
echo_on: false,
294+
}
295+
}
296+
297+
/// Called when this object is dropped.
298+
///
299+
/// You need to provide this if the shell you're testing is not killed by just sending
300+
/// SIGTERM.
301+
pub fn quit_command(mut self, cmd: Option<String>) -> Self {
302+
self.quit_command = cmd;
303+
self
304+
}
288305

289306
/// Set this to true if the repl has echo on (i.e. sends user input to stdout)
290307
///
291308
/// Although echo is set off at pty fork (see `PtyProcess::new`) a few repls still
292309
/// seem to be able to send output.
293310
/// You may need to try with true first, and if tests fail set this to false.
294-
pub echo_on: bool,
311+
pub fn echo_on(mut self, yes: bool) -> Self {
312+
self.echo_on = yes;
313+
self
314+
}
295315
}
296316

297317
impl PtyReplSession {

0 commit comments

Comments
 (0)