rush / docs

Advanced features

Rush is a shell, but its interactive editor is also a terminal application. It speaks modern terminal protocols when they are available, falls back when they are not, and exposes useful state back to normal Rush scripts.

The goal is not a separate configuration language. The interesting parts of the terminal become shell variables and builtins, so the same language that runs commands can also shape the prompt, completions, and editor UI.

Adaptive UI theme

Rush can theme completion menus, autosuggestions, history matches, and diagnostics with rush_style_* variables. Those variables are read once at the start of each prompt and cached for rendering, so the editor does not re-run shell code for every frame.

rush_style() {
  if test "$rush_color_scheme" = light; then
    muted=black
  else
    muted=bright-black
  fi

  rush_style_completion_selected="fg=${rush_color_cyan-#00ffff},bold"
  rush_style_completion_directory="fg=$(color dim "${rush_color_blue-#0000ff}" 15)"
  rush_style_completion_description="fg=$muted,dim"
  rush_style_history_match='fg=yellow,bold'
}

rush_style runs once during interactive startup, and again when the terminal reports that its color scheme or palette changed. Before calling it for a scheme change, Rush sets rush_color_scheme to dark, light, or unknown.

Before the normal capability query batch, Rush asks the terminal for the current foreground, background, and ANSI palette colors 0 through 7. When reports arrive, Rush sets variables such as rush_color_foreground, rush_color_background, rush_color_blue, and rush_color_cyan to #rrggbb values. If a terminal does not report them, Rush does not invent defaults; configs can use normal shell fallback syntax like ${rush_color_blue-#0000ff}.

On terminals that support color-scheme notifications, Rush subscribes to those updates. When the terminal switches between light and dark, Rush re-queries the palette, requests device attributes again, updates Rush-owned variables, reruns rush_style, and repaints the editor.

Color utilities

The color builtin turns reported terminal colors into derived colors that compose in command substitution.

color dim '#204080' 25
#183060

color blend '#000000' '#ffffff' 50
#808080

color dim COLOR PERCENT blends a #rrggbb color toward black. color blend COLOR COLOR PERCENT blends the first color toward the second. Invalid input exits with status 2, writes a diagnostic to stderr, and writes nothing to stdout. If that produces an invalid rush_style_* value, the host-side style parser ignores it and falls back to the default style for that role.

Parser-aware completion

Rush completions are Rush scripts, but they are driven by the shell parser rather than by splitting the current line on whitespace. Completion code can see command position, option position, assignment context, redirections, command substitutions, and whether a word is being completed as a path or as a command.

That lets completions stay shell-like in edge cases: abbreviations expand before completion, directory candidates display only the part that should be inserted, and command-specific scripts can mix static candidates with dynamic shell logic.

See Writing completions for the reference API.

Editor feedback

The line editor provides small pieces of immediate feedback without committing to a full-screen UI. Completion misses briefly flash the word being completed. Ctrl-C clears the current prompt when there is text, and otherwise leaves an empty prompt alone. Completion entries use role-specific styles so files, directories, options, variables, functions, descriptions, and the selected row can all be distinct while still following the terminal theme.

Terminal protocols

Rush probes terminal capabilities instead of assuming them. It can use modern keyboard protocols, bracketed paste, in-band resize information, color-scheme reports, palette reports, and other device responses when supported. Unsupported or unanswered queries simply time out or remain unknown, and the editor continues with conservative behavior.

This is why advanced features are incremental: a capable terminal gets adaptive colors and richer input, while older terminals still get a working shell.