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 or clear to wipe the screen), the router executes it immediately and tells the shell loop to skip evaluation.

Types

Represents the routing signal returned to the main shell loop.

pub type CommandResult {
  Handled
  Exit
  Clear
  Compile
  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 recompile the surrounding Mix/Gleam project.

  • 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.

It requires access to the current bindings and history_entries state so that commands like l() (list bindings) and history() have the necessary context to print accurate summaries.

Search Document