Skip to main content

dispatch_forward

Function dispatch_forward 

Source
pub async fn dispatch_forward(
    app: &mut ReplApp,
    line: String,
    engine: &dyn TuiEngine,
    tx: &UnboundedSender<ReplEvent>,
) -> Result<bool>
Expand description

The Route::Forward half of the dispatch pipeline: resolve a picker or call engine.handle_input.

Why: the actual integration point a product’s event-loop wiring calls after draining a Route::Forward line from crate::app::ReplApp::pending_submit — composes resolve_forward (the routing decision) with the two possible effects (open a picker on app, or await the engine call) in one place, so callers don’t have to re-derive the “which one am I supposed to do” branch themselves. What: on Forward::OpenPicker, stages the picker on app (via crate::app::ReplApp::open_picker), clears crate::app::ReplApp::busy, and returns Ok(true) — the engine is never touched. Clearing busy here (not in crate::app::ReplApp::submit_line) matters: submit_line unconditionally sets busy = true for every Route::Forward line because it can’t know in advance whether this function will end up opening a picker instead of actually calling handle_input — this arm is the one place that knows the round-trip to the engine never happened. Leaving busy set would strand the input composer’s busy spinner for as long as the picker stays open (nothing else clears it — busy is only ever reset by an AssistantOutput event, which never arrives on this path) and would spuriously gate apply_up’s busy-triggered pending_cancel (crate::app::reduce::apply_up), firing an unwanted engine.cancel_session() the next time a picker-open Up arrow is drained. On Forward::ToEngine, forwards verbatim to engine.handle_input, returning its Result<bool> unchanged (per TuiEngine::handle_input’s own contract: Ok(false) means quit) — busy is left as submit_line set it, since the engine call is the thing busy is meant to track. Test: tests::dispatch_forward_opens_picker_without_calling_engine, tests::dispatch_forward_calls_engine_when_no_picker_matches, tests::dispatch_forward_clears_busy_set_by_submit_line_when_opening_picker.