Skip to main content

Crate abalone

Crate abalone 

Source
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:

Around the shell, for any command-line app:

  • log: a log file per run, for bug reports, and log::guard for main;
  • files (files feature): the data folder and settings in a TOML file;
  • install and update (install, update features): 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 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 /help panel: 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 own CHANGELOG.md built into it, so they show offline and match the build. The changelog follows Keep a Changelog (## [1.2.0] - 2026-10-21, - entries under ### Added and the like), which release-notes.ps1 checks 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! and errln! macros) and work the same from the command line and inside the shell.
release
The release side of crate::update: what publishes the manifest.json the updater reads. Copy these into the app’s repo and keep them current with a test, the way crate::install::InstallScript does for install.ps1:
settings
The /settings panel: 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 Skin with 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§

errln
eprintln!, or a warning line in the shell.
outln
println!, or a transcript line in the shell.

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, then Shell::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;.
PanelEvent
Tui
How the shell draws; /tui fullscreen and /tui default switch it.

Traits§

App
What the app tells the shell.
Panel
What a full-screen (or bottom) panel the app opens does.

Functions§

char_width
Columns c takes on screen.
fit_row
row cut to w columns, ending in … when anything was cut.
fit_width
The start of text that fits in n columns.
for_light
c darkened until text in it reads on white. Named colours are left to the terminal’s palette.
half_blocks
Pixel art drawn with half blocks: two pixel rows to a screen row. None pixels are left blank. Rows past the last pair are ignored.
hex
#rrggbb (or rrggbb) as a colour.
highlight
text split into base and mark pieces where it matches query: the first occurrence, or (words) every word that starts with it.
light_background
Whether the terminal’s background is light: as set with set_light_background, else as the terminal says (COLORFGBG, or the console’s colours on Windows). Terminals that say nothing, Windows Terminal among them, count as dark.
pad
text padded with spaces to n columns.
readable
c, darkened on a light background until it reads there. For colours an app draws with itself: Style::fg(abalone::readable(MY_GREEN)).
rgb
row_text
The row’s text without styles.
row_width
Columns row takes on screen: two for wide characters (CJK, most emoji), none for combining marks and control characters.
set_light_background
Say whether the background is light, for terminals that can’t tell (from a setting of the app’s, say). Colours picked after this follow it: call it before Theme::for_terminal and readable.
set_theme
Make t the active theme, for everything drawn from now on.
text_width
Columns text takes on screen.
theme
The active theme.
wrap
Wrap at spaces into rows of at most w columns, breaking a longer word where it must. Continuation rows keep the line’s indent.

Type Aliases§

Row
One screen row as styled pieces.