Skip to main content

Tui

Struct Tui 

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

TUI application entry points. Direct typed TUI execution for a derive-based clap parser.

Tui::<T>::run() is the primary explicit integration surface for applications that define their own Command::Tui dispatch branch and want the selected command value back as T.

Implementations§

Source§

impl<T> Tui<T, CrosstermRuntime>

Source

pub fn new() -> Self

Create a typed app from a derive-based parser.

Examples found in repository?
examples/showcase.rs (line 142)
139fn main() -> Result<(), clap_tui::TuiError> {
140    match Command::parse() {
141        Command::Tui => {
142            if let Some(command) = Tui::<Command>::new().hide_entrypoint("tui")?.run()? {
143                dispatch(command);
144            }
145        }
146        command => dispatch(command),
147    }
148
149    Ok(())
150}
More examples
Hide additional examples
examples/simple.rs (line 46)
43fn main() -> Result<(), clap_tui::TuiError> {
44    match Command::parse() {
45        Command::Tui => {
46            if let Some(command) = Tui::<Command>::new().hide_entrypoint("tui")?.run()? {
47                dispatch(command);
48            }
49        }
50        command => dispatch(command),
51    }
52
53    Ok(())
54}
examples/subcommands.rs (line 42)
39fn main() -> Result<(), clap_tui::TuiError> {
40    match Command::parse() {
41        Command::Tui => {
42            if let Some(command) = Tui::<Command>::new().hide_entrypoint("tui")?.run()? {
43                dispatch(command);
44            }
45        }
46        command => dispatch(command),
47    }
48
49    Ok(())
50}
Source§

impl<T, R: Runtime> Tui<T, R>

Source

pub fn hide_entrypoint(self, name: impl Into<String>) -> Result<Self, TuiError>

Hide a matching top-level entrypoint subcommand from the rendered TUI.

This only changes the command tree used to build the TUI. Typed reparsing after submit still uses the original clap parser type T.

§Errors

Returns TuiError::UnknownEntrypoint when name does not match a canonical top-level subcommand name on the render command.

Examples found in repository?
examples/showcase.rs (line 142)
139fn main() -> Result<(), clap_tui::TuiError> {
140    match Command::parse() {
141        Command::Tui => {
142            if let Some(command) = Tui::<Command>::new().hide_entrypoint("tui")?.run()? {
143                dispatch(command);
144            }
145        }
146        command => dispatch(command),
147    }
148
149    Ok(())
150}
More examples
Hide additional examples
examples/simple.rs (line 46)
43fn main() -> Result<(), clap_tui::TuiError> {
44    match Command::parse() {
45        Command::Tui => {
46            if let Some(command) = Tui::<Command>::new().hide_entrypoint("tui")?.run()? {
47                dispatch(command);
48            }
49        }
50        command => dispatch(command),
51    }
52
53    Ok(())
54}
examples/subcommands.rs (line 42)
39fn main() -> Result<(), clap_tui::TuiError> {
40    match Command::parse() {
41        Command::Tui => {
42            if let Some(command) = Tui::<Command>::new().hide_entrypoint("tui")?.run()? {
43                dispatch(command);
44            }
45        }
46        command => dispatch(command),
47    }
48
49    Ok(())
50}
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) -> Tui<T, NR>

Replace the default runtime.

Source

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

Run the TUI and parse the submitted command into the bound parser type.

Returns Ok(Some(parsed)) when the user submits a valid command and Ok(None) when the user exits without submitting. If clap reparsing produces help, version, or parse-display behavior, this method returns Err(TuiError::Clap(_)) without printing automatically or calling std::process::exit.

§Errors

Returns an error when terminal setup, rendering, runtime integration, or clap reparsing fails.

Examples found in repository?
examples/showcase.rs (line 142)
139fn main() -> Result<(), clap_tui::TuiError> {
140    match Command::parse() {
141        Command::Tui => {
142            if let Some(command) = Tui::<Command>::new().hide_entrypoint("tui")?.run()? {
143                dispatch(command);
144            }
145        }
146        command => dispatch(command),
147    }
148
149    Ok(())
150}
More examples
Hide additional examples
examples/simple.rs (line 46)
43fn main() -> Result<(), clap_tui::TuiError> {
44    match Command::parse() {
45        Command::Tui => {
46            if let Some(command) = Tui::<Command>::new().hide_entrypoint("tui")?.run()? {
47                dispatch(command);
48            }
49        }
50        command => dispatch(command),
51    }
52
53    Ok(())
54}
examples/subcommands.rs (line 42)
39fn main() -> Result<(), clap_tui::TuiError> {
40    match Command::parse() {
41        Command::Tui => {
42            if let Some(command) = Tui::<Command>::new().hide_entrypoint("tui")?.run()? {
43                dispatch(command);
44            }
45        }
46        command => dispatch(command),
47    }
48
49    Ok(())
50}
Source

pub fn into_untyped(self) -> TuiApp<R>

Drop down to the untyped app surface when only argv or ArgMatches execution is needed.

Trait Implementations§

Source§

impl<T> Default for Tui<T, CrosstermRuntime>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T, R> Freeze for Tui<T, R>
where R: Freeze,

§

impl<T, R = CrosstermRuntime> !RefUnwindSafe for Tui<T, R>

§

impl<T, R> Send for Tui<T, R>
where R: Send,

§

impl<T, R> Sync for Tui<T, R>
where R: Sync,

§

impl<T, R> Unpin for Tui<T, R>
where R: Unpin,

§

impl<T, R> UnsafeUnpin for Tui<T, R>
where R: UnsafeUnpin,

§

impl<T, R = CrosstermRuntime> !UnwindSafe for Tui<T, 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.