Struct workflow_terminal::terminal::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>§prompt: Arc<Mutex<String>>§term: Arc<Crossterm>§handler: Arc<dyn Cli>§terminate: Arc<AtomicBool>§pipe_raw: Channel<String>§pipe_crlf: Channel<String>§pipe_ctl: DuplexChannel<()>§para_width: Arc<AtomicUsize>

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)

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>,

source

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

source

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

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>

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<()>

source

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

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<()>

source

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

source

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

source

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

source

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

source

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

source

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

source

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

source

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

source

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

source

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

source

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

Trait Implementations§

source§

impl Clone for Terminal

source§

fn clone(&self) -> Terminal

Returns a copy of the value. Read more
1.0.0 · 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> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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,

§

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>,

§

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>,

§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more