Skip to main content

Terminal

Struct Terminal 

Source
pub struct Terminal {
    pub running: Arc<AtomicBool>,
    pub prompt: Arc<Mutex<String>>,
    pub term: Arc<Crossterm>,
    pub handler: Arc<dyn Cli>,
    pub terminate: Arc<AtomicBool>,
    pub pipe_raw: Channel<String>,
    pub pipe_crlf: Channel<String>,
    pub pipe_ctl: DuplexChannel<()>,
    pub para_width: Arc<AtomicUsize>,
    /* private fields */
}
Expand description

Terminal interface

Fields§

§running: Arc<AtomicBool>

Set while a submitted command is being processed by the Cli handler.

§prompt: Arc<Mutex<String>>

The default prompt string rendered before each input line.

§term: Arc<Crossterm>

The underlying platform-specific terminal interface.

§handler: Arc<dyn Cli>

The command-line processor that handles submitted commands.

§terminate: Arc<AtomicBool>

When set, the terminal exits its run loop after the current command.

§pipe_raw: Channel<String>

Pipe for writing raw text (without newline conversion) to the terminal.

§pipe_crlf: Channel<String>

Pipe for writing lines (terminated with CRLF) to the terminal.

§pipe_ctl: DuplexChannel<()>

Duplex control channel used to start and stop the pipe processing task.

§para_width: Arc<AtomicUsize>

Fallback paragraph wrap width (in columns) when the terminal width is unknown.

Implementations§

Source§

impl Terminal

Source

pub fn try_new(handler: Arc<dyn Cli>, prompt: &str) -> Result<Self>

Create a new default terminal instance bound to the supplied command-line processor Cli.

Source

pub fn try_new_with_options( handler: Arc<dyn Cli>, options: Options, ) -> Result<Self>

Create a new terminal instance bound to the supplied command-line processor Cli. Receives options::Options that allow terminal customization.

Source

pub async fn init(self: &Arc<Self>) -> Result<()>

Init the terminal instance

Source

pub fn inner(&self) -> LockResult<MutexGuard<'_, Inner>>

Access to the underlying terminal instance

Source

pub fn history(&self) -> Vec<UnicodeString>

Get terminal command line history list as Vec<String>

Source

pub fn reset_line_buffer(&self)

Clear the current input line buffer and reset the cursor to the start.

Source

pub fn get_prompt(&self) -> String

Get the current terminal prompt string

Source

pub fn prompt(&self)

Render the current prompt in the terminal

Source

pub fn crlf(&self)

Output CRLF sequence

Source

pub fn write<S>(&self, s: S)
where S: ToString,

Write a string

Source

pub fn writeln<S>(&self, s: S)
where S: ToString,

Write a string ending with CRLF sequence

Source

pub fn refresh_prompt(&self)

Refreshes the prompt and the user input buffer. This function is useful when the prompt is handled externally and contains data that should be updated.

Source

pub fn para<S>(&self, text: S)
where S: Into<String>,

Write text to the terminal as a paragraph, word-wrapped to the current terminal width (falling back to Terminal::para_width).

Source

pub fn para_with_options<'a, S, Opt>(&self, width_or_options: Opt, text: S)
where S: Into<String>, Opt: Into<Options<'a>>,

Write text to the terminal as a paragraph, word-wrapped using the supplied width or textwrap::Options.

Source

pub fn help<S: ToString, H: ToString>( &self, list: &[(S, H)], separator: Option<&str>, ) -> Result<()>

Render a formatted, alphabetically-sorted help listing of (command, description) pairs, wrapping descriptions to fit the terminal width. separator (default a single space) is placed between each command and its description.

Source

pub fn term(&self) -> Arc<Interface>

Get a clone of Arc of the underlying terminal instance

Source

pub async fn run(self: &Arc<Self>) -> Result<()>

Execute the async terminal processing loop. Once started, it should be stopped using Terminal::exit

Source

pub async fn exit(self: &Arc<Self>)

Exits the async terminal processing loop (async fn)

Source

pub fn abort(self: &Arc<Self>)

Exits the async terminal processing loop (sync fn)

Source

pub async fn ask( self: &Arc<Terminal>, secret: bool, prompt: &str, ) -> Result<String>

Ask a question (input a string until CRLF). secret argument suppresses echoing of the user input (useful for password entry)

Source

pub async fn kbhit(self: &Arc<Terminal>, prompt: Option<&str>) -> Result<String>

Wait for a single keystroke, optionally displaying prompt first, and return the captured key without echoing it.

Source

pub fn inject_unicode_string(&self, text: UnicodeString) -> Result<()>

Inject a string into the current cursor position

Source

pub fn inject<S: ToString>(&self, text: S) -> Result<()>

Insert text into the current input line at the cursor position.

Source

pub fn inject_char(&self, ch: char) -> Result<()>

Insert a single character into the current input line at the cursor position.

Source

pub fn is_running(&self) -> bool

Indicates that the terminal has received command input and has not yet returned from the processing. This flag is set to true when delivering the user command to the Cli handler and is reset to false when the Cli handler returns.

Source

pub async fn exec<S: ToString>(self: &Arc<Terminal>, cmd: S) -> Result<()>

Submit cmd to the Cli handler for processing, printing any error it returns and then either exiting (if termination was requested) or re-rendering the prompt.

Source

pub fn set_theme(&self, _theme: Theme) -> Result<()>

Apply the supplied color Theme (effective on the WASM/xterm.js target).

Source

pub fn update_theme(&self) -> Result<()>

Re-apply the current theme to the terminal (effective on the WASM/xterm.js target).

Source

pub fn clipboard_copy(&self) -> Result<()>

Copy the current terminal selection to the system clipboard (effective on the WASM/xterm.js target).

Source

pub fn clipboard_paste(&self) -> Result<()>

Paste the system clipboard contents into the terminal (effective on the WASM/xterm.js target).

Source

pub fn increase_font_size(&self) -> Result<Option<f64>>

Increase the terminal font size, returning the new size if applicable.

Source

pub fn decrease_font_size(&self) -> Result<Option<f64>>

Decrease the terminal font size, returning the new size if applicable.

Source

pub fn set_font_size(&self, font_size: f64) -> Result<()>

Set the terminal font size to font_size.

Source

pub fn get_font_size(&self) -> Result<Option<f64>>

Return the current terminal font size, if known.

Source

pub fn cols(&self) -> Option<usize>

Return the terminal width in columns, if known.

Source

pub async fn select<T>( self: &Arc<Terminal>, prompt: &str, list: &[T], ) -> Result<Option<T>>
where T: Display + Clone,

Prompt the user to choose one item from list by its index. Returns None for an empty list, the sole item for a single-element list, and otherwise repeatedly displays the choices until a valid index is entered; pressing enter on an empty line aborts with Error::UserAbort.

Source

pub fn register_event_handler( self: &Arc<Self>, _handler: EventHandlerFn, ) -> Result<()>

Register a handler invoked on terminal Events such as copy and paste (effective on the WASM/xterm.js target).

Register a handler invoked when terminal text matching _regexp is clicked (effective on the WASM/xterm.js target).

Trait Implementations§

Source§

impl Clone for Terminal

Source§

fn clone(&self) -> Terminal

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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> Any for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Source§

fn type_name(&self) -> &'static str

Source§

impl<T> AnySync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more