dreg_core/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//! Dreg Core Functionality


pub mod buffer;
pub mod context;
pub mod primitives;
pub mod style;

pub mod prelude {
    pub use anyhow::Result;
    pub use crate::{
        buffer::{Buffer, Cell},
        primitives::Rect,
        style::{Color, ColorMode, Modifier, Style},
        context::{Context, Input, Scancode},
        Frame,
        Platform,
        Program,
        run_program,
    };
}

use prelude::*;



pub fn run_program(program: impl Program, platform: impl Platform) -> Result<()> {
    platform.run(program)?;
    Ok(())
}



pub trait Program {
    fn update(&mut self, frame: Frame);
    fn should_exit(&self) -> bool;
}

pub trait Platform {
    fn run(self, program: impl Program) -> Result<()>;
}

pub struct Frame<'a> {
    pub context: &'a mut Context,
    pub area: Rect,
    pub buffer: &'a mut Buffer,
}