Struct Output

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

This struct contains all the methods that the OutputOnly and InputOutput structs have in common. Any method of this struct may be called on either of the other structs.

Implementations§

Source§

impl Output

Source

pub fn println<T>(&self, line: T)
where T: Into<Line>,

Prints a (possibly styled) line of regular output to the screen.

Note: As usual with Output methods, you can pass a Line, a plain String/&str, or a Cow<str> here. See also the liso! macro.

Source

pub fn wrapln<T>(&self, line: T)
where T: Into<Line>,

Prints a (possibly styled) line of regular output to the screen, wrapping it to the width of the terminal. Only available with the “wrap” feature, which is enabled by default.

Note: As usual with Output methods, you can pass a Line, a plain String/&str, or a Cow<str> here. See also the liso! macro.

Source

pub fn echoln<T>(&self, line: T)
where T: Into<Line>,

Prints a (possibly styled) line of regular output to the screen, but only if we are being run interactively. Use this if you want to to echo commands entered by the user, so that echoed commands will not gum up the output when we are outputting to a pipe.

Note: As usual with Output methods, you can pass a Line, a plain String/&str, or a Cow<str> here. See also the liso! macro.

Source

pub fn status<T>(&self, line: Option<T>)
where T: Into<Line>,

Sets the status line to the given (possibly styled) text. This will be displayed above the prompt, but below printed output. (Does nothing in pipe mode.)

Note: status(Some("")) and status(None) will have different results! The former will display a blank status line, while the latter will display no status line.

Note: As usual with Output methods, you can pass a Line, a plain String/&str, or a Cow<str> here. See also the liso! macro.

Source

pub fn remove_status(&self)

Removes the status line. This is equivalent to status(None) but without needing a turbofish.

Source

pub fn notice<T>(&self, line: T, max_duration: Duration)
where T: Into<Line>,

Displays a (possibly styled) notice that temporarily replaces the prompt. The notice will disappear when the allotted time elapses, when the user presses any key, or when another notice is displayed, whichever happens first. (Does nothing in pipe mode.)

You should only use this in direct response to user input; in fact, the only legitimate use may be to complain about an unknown control character. (See Response for an example of this use.)

Note: As usual with Output methods, you can pass a Line, a plain String/&str, or a Cow<str> here. See also the liso! macro.

Source

pub fn prompt<T>(&self, line: T, input_allowed: bool, clear_input: bool)
where T: Into<Line>,

Sets the prompt to the given (possibly styled) text. The prompt is displayed in front of the user’s input, unless we are running in pipe mode.

The default prompt is blank, with input allowed.

  • input_allowed: True if the user should be allowed to write input.
  • clear_input: True if any existing partial input should be cleared when the new prompt is displayed. (If input_allowed is false, this should probably be true.)

Note: If the prompt is styled, whatever style is active at the end of the prompt will be used when displaying the user’s input. This is the only circumstance in which Liso will not automatically reset style information for you at the end of a Line.

Note: When running in pipe mode, input is always allowed, there is no way to clear buffered input, and prompts are never displayed. In short, this function does nothing at all in pipe mode.

Note: As usual with Output methods, you can pass a Line, a plain String/&str, or a Cow<str> here. See also the liso! macro.

Source

pub fn bell(&self)

Get the user’s attention with an audible or visible bell.

Source

pub fn suspend_and_run<F: 'static + FnMut() + Send>(&self, f: F)

Use this when you need to perform some work that outputs directly to stdout/stderr and can’t run it through Liso. Prompt, status, and input in progress will be erased from the screen, and the terminal will be put back into normal mode. When the function returns, Liso will set up the terminal, display the prompt, and continue as normal.

Bear in mind that this will run in a separate thread, possibly after a short delay. If you need to return a value, wait for completion, or otherwise communicate with the main program, you should use the usual inter-thread communication primitives, such as channels or atomics.

Note that you cannot use this to create a subprocess that will read from stdin! Even though output is suspended, Liso will still be reading from stdin in another thread, and thus, will be competing with the subprocess for user input. (On sane UNIXes, this will result in your program being suspended by your shell, and then misbehaving when it resumes.) If you want to create a subprocess that can use stdin and stdout, you’ll have to write your own pipe handling based around Liso. If you want to create a subprocess that can interactively use the terminal—you have to drop the InputOutput instance, and all of the existing Output instances will go dead as a result. Just don’t do it!

Source

pub fn clone_output(&self) -> OutputOnly

Make a new OutputOnly that can also output to the terminal. The clone and the original can be stored in separate places, even in different threads or tasks. All output will go to the same terminal, without any conflict between other threads doing output simultaneously or with user input.

For OutputOnly, this is the same as clone. For InputOutput, you must call this method instead, as this makes it clear that you are not trying to clone the Input half of that InputOutput.

Source

pub fn send_custom<T: Any + Send>(&self, value: T)

Send the given value to the input thread, wrapped in a Response::Custom.

Source

pub fn send_custom_box(&self, value: Box<dyn Any + Send>)

Send the given already-boxed value to the input thread, wrapped in a Response::Custom.

Source

pub fn set_completor(&self, completor: Option<Box<dyn Completor>>)

Provide a new Completor for doing tab completion.

Auto Trait Implementations§

§

impl Freeze for Output

§

impl RefUnwindSafe for Output

§

impl Send for Output

§

impl Sync for Output

§

impl Unpin for Output

§

impl UnwindSafe for Output

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.