Crates.io | milk-tea |
lib.rs | milk-tea |
version | 0.3.0 |
source | src |
created_at | 2024-06-27 02:33:32.908584 |
updated_at | 2024-06-28 23:21:36.283306 |
description | A minimal library for creating TUI apps |
homepage | |
repository | https://github.com/finndotbin/milk-tea |
max_upload_size | |
id | 1285032 |
size | 34,721 |
Milk Tea is a minimal Rust library for creating TUI (terminal user interface) apps. It takes a functional approach to constructing applications inspired by many modern web frameworks.
NOTE: This library has nothing to do with the Go library Bubble Tea. It just happens to also be named around boba tea and just happens to also be an MVU-based TUI library. (I don't know how to Google project names apparently QwQ)
cargo add milk-tea
//! Prints "hello world :3" in magenta and bold to the top left of the screen.
use milk_tea::{
area::Area,
draw_call::{DrawCall, DrawCallKind},
event::{Event, KeyCode, KeyEvent},
pair::Pair,
run,
style::{ContentStyle, Stylize},
text_size::UnicodeSize,
};
fn main() {
run(Model::default(), view, update).unwrap();
}
/// Handles drawing to the screen. An `Area` collects any draw calls we push to it to be rendered
/// later.
fn view(_model: &Model, area: &mut Area) {
area.push_all(vec![
DrawCall::new(
Pair::fill(0),
DrawCallKind::SetStyle(ContentStyle::new().magenta().bold()),
),
DrawCall::new(
Pair::fill(0),
DrawCallKind::PrintLine("hello world! :3".limit_size(area.size())),
),
]);
}
/// Handles events and updates the `Model`.
fn update(event: Event, model: &mut Model) {
if let Event::Key(KeyEvent {
code: KeyCode::Esc, ..
}) = event
{
model.0 = true
}
}
/// Represents the application state.
#[derive(Default, Clone, PartialEq, Eq)]
struct Model(bool);
impl milk_tea::Model for Model {
fn should_exit(&self) -> bool {
self.0
}
}
More examples can be found in the examples
directory. Use cargo run --example example_name
to run an example.