Expand description
§Hojicha Core
Core Elm Architecture (TEA) abstractions for building terminal user interfaces in Rust.
This crate provides the fundamental building blocks of The Elm Architecture:
§The Elm Architecture
Hojicha implements The Elm Architecture (TEA), a pattern for building interactive applications with a clear separation of concerns:
- Model: Your application state
- Message: Events that trigger state changes
- Update: Pure functions that handle messages and update state
- View: Pure functions that render your model to the terminal
- Command: Side effects that produce messages
§Core Traits
Model: The main trait your application must implementMessage: Marker trait for your application’s message typesCmd: Commands for side effects and async operations
§Example
use hojicha_core::{Model, Cmd};
struct App {
counter: u32,
}
enum Msg {
Increment,
Decrement,
}
impl Model for App {
type Message = Msg;
fn update(&mut self, event: hojicha_core::Event<Self::Message>) -> Cmd<Self::Message> {
match event {
hojicha_core::Event::User(Msg::Increment) => self.counter += 1,
hojicha_core::Event::User(Msg::Decrement) => self.counter -= 1,
_ => {}
}
Cmd::noop()
}
fn view(&self) -> String {
// Render your UI to a string
format!("Counter: {}", self.counter)
}
}Re-exports§
pub use core::Cmd;pub use core::Message;pub use core::Model;pub use error::Error;pub use error::ErrorContext;pub use error::ErrorHandler;pub use error::Result;pub use event::Event;pub use event::Key;pub use event::KeyEvent;pub use event::MouseEvent;pub use event::WindowSize;pub use commands::batch;pub use commands::custom;pub use commands::custom_async;pub use commands::custom_fallible;pub use commands::every;pub use commands::noop;pub use commands::quit;pub use commands::sequence;pub use commands::spawn;pub use commands::tick;
Modules§
- async_
helpers - High-level async helper commands for common operations
- commands
- Command utilities for handling side effects
- concurrency
- Concurrency safety utilities and patterns
- core
- Core traits and types for the Elm Architecture
- debug
- Debugging and developer ergonomics tools
- error
- Error handling for the hojicha framework
- event
- Event handling for keyboard, mouse, and other terminal events
- fallible
- Fallible model support for error handling in the update cycle
- logging
- Logging utilities for debugging TUI applications
- optimized_
event - Zero-cost Event optimizations with inline storage
- prelude
- Prelude module for convenient imports
- testing
- Testing utilities for hojicha applications
Macros§
- bail
- Helper macro for creating errors with context
- ensure
- Helper macro for ensuring conditions
- key
- Macro for key events
- test_
events - Macro for easily creating test events
- test_
scenario - Convenience macro for creating test scenarios
- test_
with_ paused_ time - Macro for tests with paused time
Structs§
- KeyModifiers
- Represents key modifiers (shift, control, alt, etc.).
Enums§
- Mouse
Button - Represents a mouse button.
- Mouse
Event Kind - A mouse event kind.