Skip to main content

Crate a3s_tui

Crate a3s_tui 

Source
Expand description

A3S TUI - TEA (The Elm Architecture) framework for terminal user interfaces.

This library provides a declarative way to build terminal applications using The Elm Architecture pattern, with Flexbox layout powered by Taffy and incremental rendering for optimal performance.

§Quick Start

use a3s_tui::{cmd, col, text, Element, ElementModel, ElementProgramBuilder};
use a3s_tui::{Event, KeyCode, TextElement};
use a3s_tui::style::Color;

struct Counter { count: i64 }

enum Msg {
    Increment,
    Decrement,
    Quit,
}

impl From<Event> for Msg {
    fn from(event: Event) -> Self {
        match event {
            Event::Key(key) if key.code == KeyCode::Up => Msg::Increment,
            Event::Key(key) if key.code == KeyCode::Down => Msg::Decrement,
            Event::Key(key) if key.code == KeyCode::Char('q') => Msg::Quit,
            _ => Msg::Increment,
        }
    }
}

impl ElementModel for Counter {
    type Msg = Msg;

    fn update(&mut self, msg: Msg) -> Option<cmd::Cmd<Msg>> {
        match msg {
            Msg::Increment => { self.count += 1; None }
            Msg::Decrement => { self.count -= 1; None }
            Msg::Quit => Some(cmd::quit()),
        }
    }

    fn view(&self) -> Element<Msg> {
        col![
            text!(""),
            Element::Text(
                TextElement::new(format!("Counter: {}", self.count))
                    .bold()
                    .fg(Color::Cyan)
            ),
        ]
    }
}

#[tokio::main]
async fn main() -> std::io::Result<()> {
    ElementProgramBuilder::new(Counter { count: 0 })
        .with_alt_screen()
        .with_fps(30)
        .run()
        .await
}

Re-exports§

pub use animation::Easing;
pub use animation::FrameAnimation;
pub use animation::Transition;
pub use chrome::AgentChrome;
pub use cmd::Cmd;
pub use element::AlignItems;
pub use element::BorderStyle;
pub use element::BoxElement;
pub use element::BoxStyle;
pub use element::Dimension;
pub use element::Edges;
pub use element::Element;
pub use element::FlexDirection;
pub use element::JustifyContent;
pub use element::Overflow;
pub use element::TextElement;
pub use element::TextStyle;
pub use element::TextWrap;
pub use element_program::ElementProgram;
pub use element_program::ElementProgramBuilder;
pub use event::Event;
pub use event::KeyEvent;
pub use event::MouseEvent;
pub use focus::FocusId;
pub use focus::FocusManager;
pub use grid::Cell;
pub use grid::CellStyle;
pub use grid::Grid;
pub use input::InputCapture;
pub use input::InputCaptureMode;
pub use input::InputHelpEntry;
pub use input::InputRoute;
pub use input::InputRouter;
pub use input::InputScope;
pub use input::RoutedInput;
pub use keymap::KeyBinding;
pub use keymap::Keymap;
pub use layout::Constraint;
pub use layout::Direction;
pub use layout::Layout;
pub use model::ElementModel;
pub use model::Model;
pub use program::Program;
pub use program::ProgramBuilder;
pub use style::Align;
pub use style::Border;
pub use style::Color;
pub use style::Style;
pub use terminal_profile::TerminalColorLevel;
pub use terminal_profile::TerminalDisplayMode;
pub use terminal_profile::TerminalFamily;
pub use terminal_profile::TerminalMultiplexer;
pub use terminal_profile::TerminalProfile;
pub use terminal_profile::TerminalSupport;
pub use theme::Theme;

Modules§

animation
Animation system for smooth transitions and timed effects.
chrome
Middleware-style builders for agent terminal chrome.
cmd
Commands for side effects in the TEA update cycle.
components
diff
Incremental diff renderer — only redraws cells that changed between frames.
element
Element tree and styling primitives for declarative UI.
element_program
Element-based program runner with Flexbox layout and incremental rendering.
event
Terminal event types (keyboard, mouse, resize, focus).
focus
Focus management for navigating between interactive components.
grid
Cell grid for terminal rendering.
input
Input routing for global, focused, and captured command scopes.
interaction
Common state traits for interactive components.
key
keymap
Configurable key binding system for mapping keys to actions.
layout
layout_engine
Flexbox layout engine powered by Taffy.
macros
markdown
Markdown-to-terminal renderer.
model
Core model traits for TEA (The Elm Architecture).
paint
Paints an Element tree onto a cell grid using computed layout positions.
prelude
Stable convenience imports for application code.
program
renderer
streaming
Streaming markdown renderer for real-time content (e.g., LLM token output).
style
Color, style, and text formatting utilities.
terminal
terminal_profile
Conservative terminal capability detection.
theme
Theme system for consistent component styling.

Macros§

col
Column layout (flex-direction: column)
row
Row layout (flex-direction: row)
spacer
Spacer shorthand
text
Text element shorthand

Structs§

KeyModifiers
Represents key modifiers (shift, control, alt, etc.).

Enums§

KeyCode
Represents a key.