# hojicha-runtime
Event loop and async runtime for the Hojicha TUI framework.
## Purpose
This crate provides the runtime engine that powers Hojicha applications:
- Main event loop with priority-based event processing
- Async task management and cancellation
- Terminal handling and panic recovery
- Resource limits and backpressure control
- Stream subscriptions for external events
## Basic Usage
```rust
use hojicha_runtime::Program;
use hojicha_core::Model;
// Assuming you have a Model implementation
struct MyApp { /* ... */ }
impl Model for MyApp { /* ... */ }
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Install panic handler for clean terminal restoration
hojicha_runtime::panic_handler::install();
// Create and run your application
let app = MyApp::new();
let mut program = Program::new(app)?;
program.run().await?;
Ok(())
}
```
## Key Features
### Async Event Handling
- **External events**: Send events from other threads via `init_async_bridge()`
- **Stream subscriptions**: Connect any `futures::Stream` with `subscribe()`
- **Cancellable tasks**: Spawn with automatic cancellation via `spawn_cancellable()`
- **Resource limits**: Prevent resource exhaustion with configurable limits
### Panic Recovery
The runtime includes panic recovery to restore the terminal on application panic.
### Testing Support
Test harness utilities for behavioral testing.
## Documentation
For full documentation and more examples, see the [main Hojicha documentation](https://jgok76.gitea.cloud/femtomc/hojicha).
## License
GPL-3.0 - See LICENSE file for details