gsh/command/router
The router module intercepts user input to check for built-in shell commands.
Before sending input to the dynamic evaluator (which would try to compile
and execute it as Gleam code), the REPL passes the input here. If it matches
a known command (like :h for help, :cc for hot-reloading, or :c for clearing the screen),
the router flags it for immediate execution and tells the shell to skip evaluation.
Types
Represents the routing signal returned to the main shell loop.
pub type CommandResult {
Handled
Exit
Clear
Compile
ToggleDebug
Help(String)
NotCommand
}
Constructors
-
HandledThe command was recognized, executed, and the shell should prompt again.
-
ExitThe user requested to terminate the shell session (e.g.,
k()). -
ClearThe user requested to clear the terminal screen.
-
CompileThe user requested to rebuild the host project and hot-reload active imports.
-
ToggleDebugThe user requested to toggle verbose AST and evaluator debugging logs.
-
Help(String)The user requested documentation for a specific module or function target (e.g.,
h gleam/listorh list.map). -
NotCommandThe input did not match any built-in commands and should be sent to the standard Gleam evaluator.
Values
pub fn handle(
input: String,
bindings: List(binding.Binding),
history_entries: List(String),
) -> CommandResult
Inspects the raw string input to route it to the appropriate built-in command.
Routing Logic:
- Exact Matches: Checks for fixed command strings like
:h,:q, or:cc. - Prefix Matches: Intercepts commands with dynamic arguments, such as
:h <target>, extracting the target payload for the documentation scraper. - Context Injection: Injects the current
bindingsandhistory_entriesso introspection commands like:band:hscan print accurate summaries.