Expand description
A full-screen interactive shell for command-line apps.
Output fills the top of the terminal and an input box stays pinned to
the bottom: / opens a menu of commands and their flags, a status bar
shows what’s running and any notices, and /help and /settings open
panels in place of the input box. Commands run on a worker thread and
print through out, so they work the same from the command line.
use abalone::{App, CommandInfo, Ctx, NoPanel, Shell, outln};
struct Hello;
impl App for Hello {
type Msg = ();
type Panel = NoPanel;
fn commands(&self) -> Vec<CommandInfo> {
vec![CommandInfo::new("greet", "Say hello").flag("--name", "Who to greet", Some("NAME"))]
}
fn run(&mut self, line: &str, ctx: &mut Ctx<Self>) {
let line = line.to_owned();
ctx.start("Greeting", move || outln!("Hello! You said {line}"));
}
}
Shell::new(Hello).title("Hello").run().unwrap();Every part can be swapped or extended:
- colours:
Theme(or a TOML file, with thetheme-filefeature); - the logo:
Logo, withTextLogo,PixelLogoandhalf_blocksto build one; - the spinner:
Spinner, or anyFn(Duration) -> (Style, String); - the header, menu, input box, status bar and footer:
skin::Skin; - help:
Helptabs of text, the commands, or rows of your own; - settings:
SimpleSettings, orSettingsModelfor settings that lead to one another; - panels of your own:
Panel, built fromwidgets; - full screen or in the terminal’s own scrollback:
Tui, or/tui; /release-notesfrom the app’s changelog:Shell::release_notes.
Around the shell, for any command-line app:
log: a log file per run, for bug reports, andlog::guardformain;files(filesfeature): the data folder and settings in a TOML file;installandupdate(install,updatefeatures): installing itself and updating from GitHub releases, with the install scripts and release workflow (release).
It runs on Windows, macOS and Linux.
Re-exports§
pub use editor::CommandInfo;pub use editor::Completer;pub use editor::FlagInfo;pub use editor::NoCompleter;pub use editor::Suggestion;pub use editor::split_words;pub use help::Help;pub use help::HelpTab;pub use logo::DefaultLogo;pub use logo::Logo;pub use logo::NoLogo;pub use logo::PixelLogo;pub use logo::TextLogo;pub use out::Kind;pub use out::Line;pub use settings::Choice;pub use settings::Field;pub use settings::Loaded;pub use settings::Outcome;pub use settings::Picker;pub use settings::SettingRow;pub use settings::SettingsModel;pub use settings::SimpleSettings;pub use settings::StatusGroups;pub use settings::Value;pub use spinner::Classic;pub use spinner::Frames;pub use spinner::Spinner;pub use status::Notice;pub use status::UpdateNote;
Modules§
- editor
- The line editor behind the input box: the buffer, history, the command menu and key handling. No terminal I/O here, so it is unit-tested.
- files
- Where an app keeps its files, and its settings in a TOML file.
- help
- The
/helppanel: tabs of text and a browsable list of the commands, drawn in place of the input box until Esc. - image
- Pictures in the terminal: an RGBA image drawn in half blocks, each cell one pixel wide and two tall, so a square image looks square.
- install
- An installed copy of the app in
files::default_root(or$<APP>_HOME):%LOCALAPPDATA%\<app>on Windows,~/.local/share/<app>on Linux and~/Library/Application Support/<app>on macOS. - log
- One log file per run, for people to attach to a bug report: the version, what ran, warnings, errors and crashes. The home folder and the user’s name are scrubbed from every line, and only the newest 20 logs are kept. A log stops growing at 10 MB, past which only crashes are written.
- logo
- The logo at the left of the header. It may animate: the shell shows frame 0 at launch and one more every tick, then stays on the last.
- notes
/release-notes: every version’s notes, from the app’s ownCHANGELOG.mdbuilt into it, so they show offline and match the build. The changelog follows Keep a Changelog (## [1.2.0] - 2026-10-21,-entries under### Addedand the like), whichrelease-notes.ps1checks too.- out
- Where command output goes: stdout and stderr, or the shell’s transcript
while the shell runs a command. Commands print through here (or the
outln!anderrln!macros) and work the same from the command line and inside the shell. - release
- The release side of
crate::update: what publishes themanifest.jsonthe updater reads. Copy these into the app’s repo and keep them current with a test, the waycrate::install::InstallScriptdoes forinstall.ps1: - settings
- The
/settingspanel: a Status tab (what the app runs with) and a Config tab (what can be changed), drawn in place of the input box. - skin
- How the shell’s own parts look: the header, transcript lines, the echo of
a sent line, the command menu, the input box, the status bar and the
footer. Each is a method of
Skinwith a default; override one to change that part, and call the free function of the same name to build on the default instead of replacing it: - spinner
- What turns at the left of the status bar while a command runs.
- status
- The status bar above the input box: on the left, what is running (the spinner, its label and the seconds so far) or how far back the output is scrolled; on the right, notices, most important first, as many as fit.
- term
- The terminal: raw mode, the alternate screen, and printing rows.
- update
- Updates from GitHub releases. Each release carries
manifest.json: - widgets
- Building blocks for panels: the frame (rule, title, tabs, body, hint), wrapped paragraphs, labelled fields, bullets, selectable lists, a text field, scrolling, and the keys panels share. The built-in help and settings panels are made of these, and so can yours be.
Macros§
Structs§
- Ctx
- What app callbacks can ask of the shell.
- Frame
- The rows of one frame and where the cursor goes.
- KeyEvent
- Keys, for panels. Represents a key event.
- KeyModifiers
- Keys, for panels. Represents key modifiers (shift, control, alt, etc.).
- Shell
- The shell around an
App. Build it with the methods below, thenShell::run. - Style
- Theme
Enums§
- Color
- The colour type rows are drawn with. Represents a color.
- Item
- One entry in the transcript.
- KeyCode
- Keys, for panels. Represents a key.
- NoPanel
- For an app with no panels of its own:
type Panel = NoPanel;. - Panel
Event - Tui
- How the shell draws;
/tui fullscreenand/tui defaultswitch it.
Traits§
Functions§
- char_
width - Columns
ctakes on screen. - fit_
width - The start of
textthat fits inncolumns. - half_
blocks - Pixel art drawn with half blocks: two pixel rows to a screen row.
Nonepixels are left blank. Rows past the last pair are ignored. - hex
#rrggbb(orrrggbb) as a colour.- highlight
textsplit intobaseandmarkpieces where it matchesquery: the first occurrence, or (words) every word that starts with it.- pad
textpadded with spaces toncolumns.- rgb
- row_
text - The row’s text without styles.
- row_
width - Columns
rowtakes on screen: two for wide characters (CJK, most emoji), none for combining marks and control characters. - set_
theme - Make
tthe active theme, for everything drawn from now on. - text_
width - Columns
texttakes on screen. - theme
- The active theme.
- wrap
- Wrap at spaces into rows of at most
wcolumns, breaking a longer word where it must. Continuation rows keep the line’s indent.
Type Aliases§
- Row
- One screen row as styled pieces.