Expand description
§tui-world
A state and event management library for TUIs built with ratatui.
§Core Concepts
World- A container that holds application stateKeybindings- Key binding registry with built-in help displayFocus- Tracks which widget currently has keyboard focusPointer- Tracks widget areas and handles mouse click/drag/up eventsInputEvent- 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§
Macros§
- keys
- Helper macro to create
Keys.
Structs§
- Area
- A rectangular area defined by position and dimensions.
- Display
Info - 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.
- Widget
Id - A unique identifier for a widget in the application.
- World
- A type-safe container for storing and retrieving resources by their type.
Enums§
- Input
Event - An input event that can be handled by the application.