hojicha-core 0.2.2

Core Elm Architecture abstractions for terminal UIs in Rust
Documentation
//! # 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 implement
//! - [`Message`]: Marker trait for your application's message types
//! - [`Cmd`]: Commands for side effects and async operations
//!
//! ## Example
//!
//! ```no_run
//! 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)
//!     }
//! }
//! ```

#![warn(missing_docs)]
#![warn(rustdoc::missing_crate_level_docs)]

// Core TEA abstractions
pub mod async_helpers;
pub mod commands;
pub mod concurrency;
pub mod core;
pub mod debug;
pub mod error;
pub mod event;
pub mod fallible;
pub mod logging;
pub mod optimized_event;

// Testing utilities (only in tests)
// Testing utilities (exported for use in tests and examples)
pub mod testing;

// Re-export core types
pub use core::{Cmd, Message, Model};
pub use error::{Error, ErrorContext, ErrorHandler, Result};
pub use event::{
    Event, Key, KeyEvent, KeyModifiers, MouseButton, MouseEvent, MouseEventKind, WindowSize,
};

// Re-export command constructors
pub use commands::{
    batch, custom, custom_async, custom_fallible, every, noop, quit, sequence, spawn, tick,
};

/// Prelude module for convenient imports
///
/// This module provides the most commonly used types and functions for building
/// Hojicha applications. Import everything with:
///
/// ```
/// use hojicha_core::prelude::*;
/// ```
///
/// ## Included Items
///
/// ### Core Traits
/// - [`Model`] - The main trait your application implements
/// - [`Message`] - Marker trait for messages
/// - [`Cmd`] - Commands for side effects
///
/// ### Events
/// - [`Event`] - All event types (Key, Mouse, User, etc.)
/// - [`Key`], [`KeyEvent`], [`KeyModifiers`] - Keyboard handling
/// - [`MouseEvent`] - Mouse events
///
/// ### Commands
/// - [`none()`] - No-op command
/// - [`batch()`] - Run commands concurrently
/// - [`sequence()`] - Run commands in order
/// - [`tick()`] - Delayed command
/// - [`every()`] - Recurring command
/// - [`quit()`] - Exit the program
///
/// ### Error Handling
/// - [`Result`] - Hojicha's Result type
/// - [`Error`] - Hojicha's Error type
///
/// ### Rendering
/// - String-based rendering with ANSI escape codes
pub mod prelude {
    // Core traits and types
    pub use crate::core::{Cmd, Message, Model};

    // Events
    pub use crate::event::{
        Event, Key, KeyEvent, KeyModifiers, MouseButton, MouseEvent, MouseEventKind, WindowSize,
    };

    // Essential commands
    pub use crate::commands::{
        batch, custom, custom_async, custom_fallible, every, noop, quit, sequence, spawn, tick,
    };

    // Concurrency utilities
    pub use crate::concurrency::{RequestId, RequestTracker, StateMachine};

    // Testing utilities
    pub use crate::testing::{HarnessConfig, ScenarioBuilder, UnifiedTestHarness};

    // Error handling
    pub use crate::error::{Error, Result};

    // String-based rendering for maximum compatibility
}

// Users will directly import hojicha-runtime as a separate crate