Thanks to visit codestin.com
Credit goes to lib.rs

3 releases

0.2.2 Oct 18, 2024
0.2.1 Oct 17, 2024
0.2.0 Oct 14, 2024

#6 in #scan-code

Codestin Search App Codestin Search App Codestin Search App Codestin Search App

108 downloads per month
Used in 2 crates

MIT license

66KB
1.5K SLoC

Table of Contents


Crate Badge Docs Badge License Badge

Dreg

A simple text-based user interface library.

Quickstart

use dreg::*;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    Terminal::new().run(MyApp {
        shutdown: false,
    })
}

struct MyApp {
    shutdown: bool,
}

impl Program for MyApp {
    fn render(&mut self, frame: &mut Frame) {
        if self.shutdown {
            frame.should_exit = true;
            return;
        }

        Rectangle {
            area: frame.area(),
            fg: Color::from_rgb(89, 89, 109),
            style: RectangleStyle::Round,
        }.render(frame);

        let text_area = frame.area().inner_centered(13, 1);
        Text::new("Hello, World!")
            .with_position(text_area.x, text_area.y)
            .render(frame);
    }

    fn input(&mut self, input: Input) {
        match input {
            Input::KeyDown(Scancode::Q) => {
                self.shutdown = true;
            }
            _ => {}
        }
    }
}

License

MIT

Dependencies

~2.5MB
~38K SLoC