01_hello_world/
01_hello_world.rs

1//! Prints "hello world :3" in magenta and bold to the top left of the screen.
2
3use milk_tea::{
4    area::Area,
5    draw_call::{DrawCall, DrawCallKind},
6    event::{Event, KeyCode, KeyEvent},
7    pair::Pair,
8    run,
9    style::{ContentStyle, Stylize},
10    text_size::UnicodeSize,
11};
12
13fn main() {
14    run(Model::default(), view, update).unwrap();
15}
16
17/// Handles drawing to the screen. An `Area` collects any draw calls we push to it to be rendered
18/// later.
19fn view(_model: &Model, area: &mut Area) {
20    area.push_all(vec![
21        DrawCall::new(
22            Pair::fill(0),
23            DrawCallKind::SetStyle(ContentStyle::new().magenta().bold()),
24        ),
25        DrawCall::new(
26            Pair::fill(0),
27            DrawCallKind::PrintLine("hello world! :3".limit_size(area.size())),
28        ),
29    ]);
30}
31
32/// Handles events and updates the `Model`.
33fn update(event: Event, model: &mut Model) {
34    if let Event::Key(KeyEvent {
35        code: KeyCode::Esc, ..
36    }) = event
37    {
38        model.0 = true
39    }
40}
41
42/// Represents the application state.
43#[derive(Default, Clone, PartialEq, Eq)]
44struct Model(bool);
45
46impl milk_tea::Model for Model {
47    fn should_exit(&self) -> bool {
48        self.0
49    }
50}