Trait term_transcript::traits::SpawnShell

source ·
pub trait SpawnShell: ConfigureCommand {
    type ShellProcess: ShellProcess;
    type Reader: Read + 'static + Send;
    type Writer: Write + 'static + Send;

    // Required method
    fn spawn_shell(&mut self) -> Result<SpawnedShell<Self>>;
}
Expand description

Encapsulates spawning and sending inputs / receiving outputs from the shell.

The crate provides two principal implementations of this trait:

  • Command and StdShell communicate with the spawned process via OS pipes. Because stdin of the child process is not connected to a terminal / TTY, this can lead to the differences in output compared to launching the process in a terminal (no coloring, different formatting, etc.). On the other hand, this is the most widely supported option.
  • PtyCommand (available with the portable-pty crate feature) communicates with the child process via a pseudo-terminal (PTY). This makes the output closer to what it would like in the terminal, at the cost of lesser platform coverage (Unix + newer Windows distributions).

External implementations are possible as well! E.g., for REPL applications written in Rust or packaged as a WASI module, it could be possible to write an implementation that “spawns” the application in the same process.

Required Associated Types§

source

type ShellProcess: ShellProcess

Spawned shell process.

source

type Reader: Read + 'static + Send

Reader of the shell output.

source

type Writer: Write + 'static + Send

Writer to the shell input.

Required Methods§

source

fn spawn_shell(&mut self) -> Result<SpawnedShell<Self>>

Spawns a shell process.

§Errors

Returns an error if the shell process cannot be spawned for whatever reason.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl SpawnShell for Command

Uses pipes to communicate with the spawned process. This has a potential downside that the process output will differ from the case if the process was launched in the shell. See PtyCommand for an alternative that connects the spawned process to a pseudo-terminal (PTY).

§

type ShellProcess = Child

§

type Reader = PipeReader

§

type Writer = ChildStdin

source§

fn spawn_shell(&mut self) -> Result<SpawnedShell<Self>>

Implementors§