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
impl Terminal
Sourcepub fn try_new(handler: Arc<dyn Cli>, prompt: &str) -> Result<Terminal, Error>
pub fn try_new(handler: Arc<dyn Cli>, prompt: &str) -> Result<Terminal, Error>
Create a new default terminal instance bound to the supplied command-line processor Cli
.
Sourcepub fn try_new_with_options(
handler: Arc<dyn Cli>,
options: Options,
) -> Result<Terminal, Error>
pub fn try_new_with_options( handler: Arc<dyn Cli>, options: Options, ) -> Result<Terminal, Error>
Create a new terminal instance bound to the supplied command-line processor Cli
.
Receives options::Options
that allow terminal customization.
Sourcepub fn inner(
&self,
) -> Result<MutexGuard<'_, Inner>, PoisonError<MutexGuard<'_, Inner>>>
pub fn inner( &self, ) -> Result<MutexGuard<'_, Inner>, PoisonError<MutexGuard<'_, Inner>>>
Access to the underlying terminal instance
Sourcepub fn history(&self) -> Vec<UnicodeString>
pub fn history(&self) -> Vec<UnicodeString>
Get terminal command line history list as Vec<String>
pub fn reset_line_buffer(&self)
Sourcepub fn get_prompt(&self) -> String
pub fn get_prompt(&self) -> String
Get the current terminal prompt string
Sourcepub fn refresh_prompt(&self)
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.
pub fn para<S>(&self, text: S)
pub fn para_with_options<'a, S, Opt>(&self, width_or_options: Opt, text: S)
pub fn help<S, H>( &self, list: &[(S, H)], separator: Option<&str>, ) -> Result<(), Error>
Sourcepub async fn run(self: &Arc<Terminal>) -> Result<(), Error>
pub async fn run(self: &Arc<Terminal>) -> Result<(), Error>
Execute the async terminal processing loop.
Once started, it should be stopped using
Terminal::exit
Sourcepub async fn ask(
self: &Arc<Terminal>,
secret: bool,
prompt: &str,
) -> Result<String, Error>
pub async fn ask( self: &Arc<Terminal>, secret: bool, prompt: &str, ) -> Result<String, Error>
Ask a question (input a string until CRLF).
secret
argument suppresses echoing of the
user input (useful for password entry)
pub async fn kbhit( self: &Arc<Terminal>, prompt: Option<&str>, ) -> Result<String, Error>
Sourcepub fn inject_unicode_string(&self, text: UnicodeString) -> Result<(), Error>
pub fn inject_unicode_string(&self, text: UnicodeString) -> Result<(), Error>
Inject a string into the current cursor position
pub fn inject<S>(&self, text: S) -> Result<(), Error>where
S: ToString,
pub fn inject_char(&self, ch: char) -> Result<(), Error>
Sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
pub async fn exec<S>(self: &Arc<Terminal>, cmd: S) -> Result<(), Error>where
S: ToString,
pub fn set_theme(&self, _theme: Theme) -> Result<(), Error>
pub fn update_theme(&self) -> Result<(), Error>
pub fn clipboard_copy(&self) -> Result<(), Error>
pub fn clipboard_paste(&self) -> Result<(), Error>
pub fn increase_font_size(&self) -> Result<Option<f64>, Error>
pub fn decrease_font_size(&self) -> Result<Option<f64>, Error>
pub fn set_font_size(&self, font_size: f64) -> Result<(), Error>
pub fn get_font_size(&self) -> Result<Option<f64>, Error>
pub fn cols(&self) -> Option<usize>
pub async fn select<T>( self: &Arc<Terminal>, prompt: &str, list: &[T], ) -> Result<Option<T>, Error>
pub fn register_event_handler( self: &Arc<Terminal>, _handler: Arc<Box<dyn Fn(Event)>>, ) -> Result<(), Error>
pub fn register_link_matcher( &self, _regexp: &RegExp, _handler: Arc<Box<dyn Fn(Modifiers, &str)>>, ) -> Result<(), Error>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Terminal
impl !RefUnwindSafe for Terminal
impl Send for Terminal
impl Sync for Terminal
impl !Unpin for Terminal
impl !UnwindSafe for Terminal
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<S> CastArc for Swhere
S: CastFromSync + ?Sized,
impl<S> CastArc for Swhere
S: CastFromSync + ?Sized,
Source§impl<T> CastFrom for Twhere
T: Any + 'static,
impl<T> CastFrom for Twhere
T: Any + 'static,
Source§fn ref_any(&self) -> &(dyn Any + 'static)
fn ref_any(&self) -> &(dyn Any + 'static)
Any
, which is backed by the type implementing this trait.Source§fn mut_any(&mut self) -> &mut (dyn Any + 'static)
fn mut_any(&mut self) -> &mut (dyn Any + 'static)
Any
, which is backed by the type implementing this trait.Source§impl<T> CastFromSync for T
impl<T> CastFromSync for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more