hojicha-core

Crates.iohojicha-core
lib.rshojicha-core
version0.2.2
created_at2025-08-11 19:17:05.883217+00
updated_at2025-08-29 17:12:42.373565+00
descriptionCore Elm Architecture abstractions for terminal UIs in Rust
homepagehttps://jgok76.gitea.cloud/femtomc/hojicha
repositoryhttps://jgok76.gitea.cloud/femtomc/hojicha
max_upload_size
id1790704
size404,407
McCoy R. Becker (femtomc)

documentation

https://docs.rs/hojicha-core

README

hojicha-core

Core abstractions and types for the Hojicha TUI framework implementing The Elm Architecture.

Purpose

This crate provides the fundamental building blocks for Hojicha applications:

  • Model trait for application state management
  • Cmd type for side effects and asynchronous operations
  • Event enum for all possible events in the system
  • Command builders for common operations

Basic Usage

use hojicha_core::{Model, Cmd, Event};

#[derive(Debug, Clone)]
enum MyMessage {
    Increment,
    Decrement,
}

struct MyApp {
    counter: i32,
}

impl Model for MyApp {
    type Message = MyMessage;

    fn init(&mut self) -> Cmd<Self::Message> {
        Cmd::noop()
    }

    fn update(&mut self, event: Event<Self::Message>) -> Cmd<Self::Message> {
        match event {
            Event::User(MyMessage::Increment) => {
                self.counter += 1;
                Cmd::noop()
            }
            Event::User(MyMessage::Decrement) => {
                self.counter -= 1;
                Cmd::noop()
            }
            _ => Cmd::noop()
        }
    }

    fn view(&self) -> String {
        format!("Counter: {}", self.counter)
    }
}

Key Types and Traits

  • Model: The core trait that all Hojicha applications must implement
  • Cmd<M>: Represents side effects and commands to be executed
  • Event<M>: All possible events (keyboard, mouse, user messages, etc.)

Documentation

For full documentation and more examples, see the main Hojicha documentation.

License

GPL-3.0 - See LICENSE file for details

Commit count: 0

cargo fmt