Struct TtySpawn

Source
pub struct TtySpawn { /* private fields */ }
Expand description

Lets you spawn processes with a TTY connected.

Implementations§

Source§

impl TtySpawn

Source

pub fn new<S: AsRef<OsStr>>(cmd: S) -> TtySpawn

Creates a new TtySpawn for a given command.

Source

pub fn new_cmdline<S: AsRef<OsStr>, I: Iterator<Item = S>>(cmdline: I) -> Self

Alternative way to construct a TtySpawn.

Takes an iterator of command and arguments. If the iterator is empty this panicks.

§Panicks

If the iterator is empty, this panics.

Source

pub fn arg<S: AsRef<OsStr>>(&mut self, arg: S) -> &mut Self

Adds a new argument to the command.

Source

pub fn args<S: AsRef<OsStr>, I: Iterator<Item = S>>( &mut self, args: I, ) -> &mut Self

Adds multiple arguments from an iterator.

Source

pub fn stdin_file(&mut self, f: File) -> &mut Self

Sets an input file for stdin.

It’s recommended that this is a named pipe and as a general recommendation this file should be opened with O_NONBLOCK.

§Platform Specifics

While we will never write into the file it’s strongly recommended to ensure that the file is opened writable too. The reason for this is that on Linux, if the last writer (temporarily) disconnects from a FIFO polling primitives such as the one used by tty-spawn will keep reporting that the file is ready while there not actually being any more data coming in. The solution to this problem is to ensure that there is at least always one writer open which can be ensured by also opening this file for writing.

Source

pub fn stdin_path<P: AsRef<Path>>( &mut self, path: P, ) -> Result<&mut Self, Error>

Sets a path as input file for stdin.

Source

pub fn stdout_file(&mut self, f: File) -> &mut Self

Sets an output file for stdout.

Source

pub fn stdout_path<P: AsRef<Path>>( &mut self, path: P, truncate: bool, ) -> Result<&mut Self, Error>

Sets a path as output file for stdout.

If the truncate flag is set to true the file will be truncated first, otherwise it will be appended to.

Source

pub fn script_mode(&mut self, yes: bool) -> &mut Self

Enables script mode.

In script mode stdout/stderr are retained as separate streams, the terminal is not opened in raw mode. Additionally some output processing is disabled so usually you will find LF retained and not converted to CLRF. This will also attempt to disable pagers and turn off ECHO intelligently in some cases.

Source

pub fn flush(&mut self, yes: bool) -> &mut Self

Can be used to turn flushing off.

By default output is flushed constantly.

Source

pub fn echo(&mut self, yes: bool) -> &mut Self

Can be used to turn echo off.

By default echo is turned on.

Source

pub fn pager(&mut self, yes: bool) -> &mut Self

Tries to use cat as pager.

When this is enabled then processes are instructed to use cat as pager. This is useful when raw terminals are disabled in which case most pagers will break.

Source

pub fn raw(&mut self, yes: bool) -> &mut Self

Can be used to turn raw terminal mode off.

By default the terminal is in raw mode but in some cases you might want to turn this off. If raw mode is disabled then pagers will not work and so will most input operations.

Source

pub fn spawn(&mut self) -> Result<i32, Error>

Spawns the application in the TTY.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.