Skip to main content

Crate modalx

Crate modalx 

Source
Expand description

§modalx

A responsive, declarative, box-encapsulated Terminal User Interface (TUI) and modal dialog engine for Rust.

§Highlights

  • Airtight Dynamic Box Framing: All visual components are strictly encapsulated within dynamic Unicode box borders (╭─╮, │ │, ├─┤, ╰─╯).
  • Responsive Sizing & Terminal Protection: Automatically detects narrow windows (< 60 cols × 14 rows), rendering a clean, centered “TERMINAL TOO SMALL” warning card that resumes execution upon window resize.
  • Flow Layout & Field Reflow: Delimited metadata (e.g. Branch: main | Target: Release | Status: Ready) reflows greedily across multiple lines when terminal width is narrow, avoiding unsightly ellipsis truncation.
  • Composable Sections: Build interfaces declaratively using TitleSection, FieldSection, TextSection, MenuSection, and FooterSection.
  • Batteries-Included Modals:
    • SelectModal: Searchable, paginated keyboard-driven menus with hotkeys and vim navigation.
    • InputModal: Full readline text editing, cursor navigation, password masking, and real-time validators.
    • ConfirmModal: Two-button affirmative/negative prompts with danger styling and hotkey toggling.
    • InfoModal: Scrollable text and alert dialogs.
    • WaitingModal: In-place progress monitors with smooth animated braille spinners.
    • TableModal: Multi-column tabular data displays with column alignments and row selection.
  • Panic Safety: Automatic terminal cleanup hook ensuring raw mode is disabled and cursor unhidden if an unexpected panic occurs.

§Quickstart

use modalx::prelude::*;

fn main() -> modalx::Result<()> {
    let mut selected = 0;
    let modal = SelectModal::new()
        .with_title("WORKSPACE CONTROLLER", false)
        .with_raw_fields("Project: nexus | Target: Release | Status: Ready", " | ")
        .item("1", "Run Build Pipeline")
        .item("2", "Interactive Test Runner")
        .item("3", "Deploy & Release");

    match modal.run(&mut selected)? {
        SelectOutcome::Selected(idx) => println!("Selected item {}", idx),
        SelectOutcome::Cancelled => println!("User pressed Escape"),
        _ => {}
    }

    Ok(())
}

Re-exports§

pub use error::Result;
pub use error::TuiError;
pub use frame::render_too_small;
pub use frame::BoxFrame;
pub use frame::FrameLine;
pub use input::TextInput;
pub use input::TextInputAction;
pub use keys::KeyAction;
pub use keys::KeyHelpMode;
pub use keys::KeyMap;
pub use nav::box_breadcrumbs;
pub use nav::clear_root_breadcrumbs;
pub use nav::format_breadcrumbs;
pub use nav::get_breadcrumbs;
pub use nav::set_root_breadcrumbs;
pub use nav::NavGuard;
pub use section::FieldSection;
pub use section::FooterSection;
pub use section::MenuEntry;
pub use section::MenuSection;
pub use section::ModalSection;
pub use section::SelectItem;
pub use section::TextSection;
pub use section::TitleSection;
pub use shortcuts::Shortcut;
pub use shortcuts::ShortcutBar;
pub use shortcuts::Shortcuts;
pub use terminal::clean_exit;
pub use terminal::get_content_width;
pub use terminal::get_terminal_size;
pub use terminal::init_terminal_panic_hook;
pub use terminal::is_terminal_too_small;
pub use terminal::restore_terminal;
pub use terminal::wait_for_constraints;
pub use terminal::wait_for_valid_size;
pub use terminal::AltScreenGuard;
pub use terminal::TerminalConstraints;
pub use terminal::TerminalGuard;
pub use terminal::MIN_TERM_HEIGHT;
pub use terminal::MIN_TERM_WIDTH;
pub use text_flow::truncate_ansi;
pub use text_flow::truncate_ellipsis;
pub use text_flow::truncate_str;
pub use text_flow::wrap_button_items;
pub use text_flow::wrap_delimited_string;
pub use text_flow::wrap_fields;
pub use text_flow::wrap_words;
pub use theme::box_bottom;
pub use theme::box_divider;
pub use theme::box_line;
pub use theme::box_title;
pub use theme::box_title_simple;
pub use theme::box_top;
pub use theme::is_utf8_supported;
pub use theme::strip_ansi;
pub use theme::visible_len;
pub use modals::*;

Modules§

error
frame
input
keys
modals
nav
prelude
Convenient prelude module re-exporting all primary traits, structs, and functions.
section
shortcuts
High-level shortcut abstraction and dynamic footer bar builder for TUI frames and modals.
terminal
text_flow
theme