pub struct ApplicationRunner;Expand description
TUI application runner
Encapsulates the lifecycle of running a TUI application: creating the event channel,
constructing the Context, building a Projection inside a Tokio runtime, registering
signal handlers, and calling the application function. Unlike CommandRunner, there is no
presenter — the application owns its own render loop and queries the projection for accumulated
state.
§Examples
// This is what main!() expands to for applications:
ResolvedLeaf::Application { matches, exec } => {
clawless::tui::runner::ApplicationRunner::run(matches, exec)
}Implementations§
Source§impl ApplicationRunner
impl ApplicationRunner
Sourcepub fn run<E, F>(matches: ArgMatches, exec: E) -> Result<(), Box<dyn Error>>where
E: FnOnce(ArgMatches, Context, Projection) -> F,
F: Future<Output = Result<()>> + Send + 'static,
pub fn run<E, F>(matches: ArgMatches, exec: E) -> Result<(), Box<dyn Error>>where
E: FnOnce(ArgMatches, Context, Projection) -> F,
F: Future<Output = Result<()>> + Send + 'static,
Runs a TUI application to completion
Sets up the application lifecycle:
- Creates a
Cancellationtoken for cooperative shutdown - Creates an event channel and builds the
Context - Creates a Tokio runtime
- Inside the runtime, creates a
Projection(which spawns a background drain task) - Spawns the signal handler and calls the application function
The Projection must be created inside the Tokio runtime because its constructor calls
tokio::spawn to start the background event drain.
§Arguments
matches— The parsedArgMatchesfor this application leaf, as resolved by the subcommand tree walk.exec— Executes the application with the given matches, context, and projection. The#[application]macro generates a function for this, and any other callable works. A caller that builds its command tree at run time passes a closure that owns the application it resolved.
§Errors
Returns an error if context construction fails (e.g., the current working directory cannot be determined), if the Tokio runtime cannot be created, or if the application itself fails.