Skip to main content

Crate tui_world

Crate tui_world 

Source
Expand description

§tui-world

A state and event management library for TUIs built with ratatui.

§Core Concepts

  • World - A container that holds application state
  • Keybindings - Key binding registry with built-in help display
  • Focus - Tracks which widget currently has keyboard focus
  • Pointer - Tracks widget areas and handles mouse click/drag/up events
  • InputEvent - Unified input event handling for keyboard and mouse

§Example

ⓘ
use tui_world::prelude::*;
use crossterm::event::KeyCode;

const WIDGET_ID: WidgetId = WidgetId("MyWidget");

let mut world = World::default();

// Store state in world
world.insert(MyAppState::default());

// Register keybindings
world.get_mut::<Keybindings>().bind(WIDGET_ID, KeyCode::Enter, "Select", |world| {
    world.get_mut::<MyAppState>().select();
});

// Check focus
if world.get::<Focus>().is_focused(WIDGET_ID) {
    // widget has focus
}

// Handle key events
InputEvent::Key(key).handle(&mut world, &[WIDGET_ID]);

Modules§

prelude

Macros§

keys
Helper macro to create Keys.

Structs§

Area
A rectangular area defined by position and dimensions.
DisplayInfo
Information about keybindings for display purposes.
Focus
Tracks which widget currently has keyboard focus.
KeyBinding
Represents a keyboard shortcut consisting of a key code and optional modifiers.
Keybindings
A registry of keyboard shortcuts mapped to actions for different widgets.
Keys
A collection of keybindings for use with Keybindings::bind_many.
Pointer
Manages mouse/pointer interactions for widgets.
WidgetId
A unique identifier for a widget in the application.
World
A type-safe container for storing and retrieving resources by their type.

Enums§

InputEvent
An input event that can be handled by the application.