Skip to main content

TuiApp

Struct TuiApp 

Source
pub struct TuiApp<R: Runtime = CrosstermRuntime> { /* private fields */ }
Expand description

TUI application entry points. Build and run a TUI from a hand-built clap::Command.

Use crate::Tui for derive-based CLIs that want typed results. Use TuiApp when you are already building a clap::Command by hand, or when you want the untyped surface that returns argv or ArgMatches.

Implementations§

Source§

impl TuiApp<CrosstermRuntime>

Source

pub fn from_command(command: Command) -> Self

Create a TUI from a hand-built clap::Command.

Examples found in repository?
examples/clap_features.rs (line 351)
350fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
351    let app = TuiApp::from_command(build_command());
352    app.run_with_matches::<_, std::io::Error>(|matches| {
353        println!("{matches:#?}");
354        Ok(())
355    })?;
356    Ok(())
357}
Source§

impl<R: Runtime> TuiApp<R>

Source

pub fn with_config(self, config: TuiConfig) -> Self

Apply configuration before the TUI starts.

Source

pub fn with_runtime<NR: Runtime>(self, runtime: NR) -> TuiApp<NR>

Replace the default runtime.

Source

pub fn run(self) -> Result<Option<Vec<OsString>>, TuiError>

Run the TUI and return the selected canonical argv.

The returned argv is the executable token sequence. Preview and clipboard text are rendered separately from these tokens, using POSIX shell quoting on Unix platforms and PowerShell quoting on Windows.

Returns Ok(Some(argv)) when the user runs a valid command and Ok(None) when the user exits without running. Validation stays inside the TUI flow, so invalid form state is surfaced in-app rather than returned as a clap error from this method.

§Errors

Returns an error when terminal setup or event handling fails.

Source

pub fn run_with_matches<F, E>(self, runner: F) -> Result<(), TuiError>
where F: FnOnce(ArgMatches) -> Result<(), E>, E: StdError + Send + Sync + 'static,

Run the TUI and execute a custom handler with ArgMatches.

Returns Ok(()) when the user exits without running. When the user does run, this method reparses the selected argv with the original clap::Command before calling the handler.

§Errors

Returns an error when terminal setup or event handling fails, when reparsing the selected argv with clap fails, or when the runner callback fails.

Examples found in repository?
examples/clap_features.rs (lines 352-355)
350fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
351    let app = TuiApp::from_command(build_command());
352    app.run_with_matches::<_, std::io::Error>(|matches| {
353        println!("{matches:#?}");
354        Ok(())
355    })?;
356    Ok(())
357}

Auto Trait Implementations§

§

impl<R> Freeze for TuiApp<R>
where R: Freeze,

§

impl<R = CrosstermRuntime> !RefUnwindSafe for TuiApp<R>

§

impl<R> Send for TuiApp<R>
where R: Send,

§

impl<R> Sync for TuiApp<R>
where R: Sync,

§

impl<R> Unpin for TuiApp<R>
where R: Unpin,

§

impl<R> UnsafeUnpin for TuiApp<R>
where R: UnsafeUnpin,

§

impl<R = CrosstermRuntime> !UnwindSafe for TuiApp<R>

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
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.