ratatui-action 0.1.0

Experimental semantic action model for Ratatui applications.
Documentation
  • Coverage
  • 100%
    72 out of 72 items documented9 out of 48 items with examples
  • Size
  • Source code size: 28.65 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 2s Average build duration of successful builds.
  • all releases: 2s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • ratatui/ratatui-labs
    13 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • joshka

ratatui-action

Experimental semantic action model for Ratatui applications.

This crate is part of ratatui-labs. It describes application capabilities independently from the UI surfaces that present or invoke them. APIs are experimental and may change or disappear.

The command palette experiment uses this crate for action identity, metadata, availability, inputs, arguments, and invocation requests.

Usage

Declare semantic actions with stable identifiers. Dispatch remains application-owned; UI surfaces return invocation requests instead of running callbacks.

use ratatui_action::{
    id::InputId,
    input::{ActionChoice, ActionInput},
    invocation::{ActionArgs, ActionInvocation, InvocationSource},
    spec::{ActionSpec, Availability},
};

let switch_theme = ActionSpec::new("theme.switch", "Switch theme")
    .with_category("Appearance")
    .with_description("Preview and apply a terminal color theme")
    .with_keywords(["color", "style"])
    .with_input(ActionInput::Choice {
        id: InputId::new("theme"),
        label: "Theme".into(),
        choices: vec![
            ActionChoice::new("catppuccin", "Catppuccin"),
            ActionChoice::new("github-dark", "GitHub Dark"),
        ],
    });

let close_workspace = ActionSpec::new("workspace.close", "Close workspace").with_availability(
    Availability::Disabled {
        reason: "No workspace is open".into(),
    },
);

let mut args = ActionArgs::new();
args.insert("theme", "github-dark");
let invocation =
    ActionInvocation::with_args(switch_theme.id().clone(), args, InvocationSource::Palette);

assert_eq!(invocation.id().as_str(), "theme.switch");
assert_eq!(invocation.args().get(&InputId::new("theme")), Some("github-dark"));
assert!(!close_workspace.is_enabled());

API Notes

  • ActionSpec and ActionInvocation use private fields so the experiment can add validation or change storage without committing to struct literals.
  • ActionSpec stores owned text for now, while accessors expose borrowed text or iterators so the storage can be revisited before publication.
  • ActionInput describes required values, not a specific input widget.
  • ActionArgs stores resolved input values by InputId, so dispatch code can ignore which surface collected them.