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>where
T: Parser + CommandFactory,
impl<T> Tui<T, CrosstermRuntime>where
T: Parser + CommandFactory,
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a typed app from a derive-based parser.
Examples found in repository?
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
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}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>where
T: Parser + CommandFactory,
impl<T, R: Runtime> Tui<T, R>where
T: Parser + CommandFactory,
Sourcepub fn hide_entrypoint(self, name: impl Into<String>) -> Result<Self, TuiError>
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?
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
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}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}Sourcepub fn with_config(self, config: TuiConfig) -> Self
pub fn with_config(self, config: TuiConfig) -> Self
Apply configuration before the TUI starts.
Sourcepub fn with_runtime<NR: Runtime>(self, runtime: NR) -> Tui<T, NR>
pub fn with_runtime<NR: Runtime>(self, runtime: NR) -> Tui<T, NR>
Replace the default runtime.
Sourcepub fn run(self) -> Result<Option<T>, TuiError>
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?
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
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}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}Sourcepub fn into_untyped(self) -> TuiApp<R>
pub fn into_untyped(self) -> TuiApp<R>
Drop down to the untyped app surface when only argv or ArgMatches execution is needed.
Trait Implementations§
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> 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<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