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

  • Handled

    The command was recognized, executed, and the shell should prompt again.

  • Exit

    The user requested to terminate the shell session (e.g., k()).

  • Clear

    The user requested to clear the terminal screen.

  • Compile

    The user requested to rebuild the host project and hot-reload active imports.

  • ToggleDebug

    The 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/list or h list.map).

  • NotCommand

    The 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 bindings and history_entries so introspection commands like :b and :hs can print accurate summaries.
Search Document