shell
A lightweight, no_std compatible shell runtime component for building interactive command-line interfaces in Rust.
This crate provides the core Shell struct that orchestrates command execution, input parsing, and terminal management for shell-based applications. It's part of the uRustShell framework.
Features
- Zero-allocation design — uses
heaplessdata structures for embedded/constrained environments - Generic error handling — accepts any error type that implements
Debug - Dual dispatch model — separate handlers for commands and shortcuts
- Automatic terminal management — sets up raw mode for interactive input
- Integration with
shell-input— leverages autocomplete, history, and advanced editing features
Usage
use Shell;
// Define your command and shortcut handlers
// Create and run the shell
let mut shell = new;
shell.run;
Generic Parameters
The Shell type requires several const generic parameters to configure its behavior:
NC— Maximum number of registered commandsFNL— Maximum length of function namesIML— Maximum input line lengthHTC— Total capacity for history storage (in bytes)HME— Maximum number of history entriesERRTYPE— Error type returned by the command dispatcher (must implementDebug)
Constructor Parameters
The Shell::new() constructor accepts the following function pointers:
get_commands— Returns a static slice of(name, signature)tuples for available commandsget_datatypes— Returns a help string describing supported parameter typesget_shortcuts— Returns a help string listing available shortcutsis_shortcut— Predicate to determine if input should be treated as a shortcutcommand_dispatcher— Executes regular commandsshortcut_dispatcher— Executes shortcut commandsprompt— The prompt string to display
Execution Model
The shell runs in a continuous loop, parsing input and dispatching to the appropriate handler:
- User enters input via the integrated
InputParser - Input is checked against the
is_shortcutpredicate - Either
shortcut_dispatcherorcommand_dispatcheris called - Results are displayed with success/error formatting
- Loop continues until the parser signals termination
Error Handling
Both command and shortcut dispatchers can return errors:
- Command errors of type
ERRTYPEare converted to strings for display - Shortcut errors are already strings (constrained by
heapless::String<IML>) - All errors are formatted consistently:
Error: <message> for line '<input>'
Integration with uRustShell
This crate is designed to work within the uRustShell framework, which provides:
- Command registration via
.cfgfiles - Automatic parameter validation and type checking
- Autocomplete and command history
- Advanced line editing capabilities
- Shortcut support with major/minor groups
For a complete working example, see the uRustShell repository.
Dependencies
heapless— Stack-allocated data structuresshell-input— Input parsing and terminal management
Platform Support
This crate is no_std compatible and suitable for embedded systems, though it does require terminal access for raw mode control.
License
See the uRustShell repository for license information.