term2d

Crates.ioterm2d
lib.rsterm2d
version0.8.3
sourcesrc
created_at2022-11-05 13:53:58.103288
updated_at2023-11-08 20:19:59.235686
descriptionSimple drawing engine for terminal applications
homepagehttps://github.com/golmman/term2d
repositoryhttps://github.com/golmman/term2d
max_upload_size
id705794
size53,316
(golmman)

documentation

https://docs.rs/term2d

README

term2d

A simple 2d drawing engine for terminal emulators.

Example which draws some text and a red pixel:

use term2d::model::color::Color;
use term2d::model::event::Event;
use term2d::model::key::Key;
use term2d::model::point::Point;
use term2d::model::rgba::Rgba;
use term2d::view::canvas::halfblock::HalfblockCanvas;
use term2d::view::canvas::Canvas;
use term2d::App;
use term2d::AppBuilder;

fn event_fn(_app: &App, _model: &mut (), event: Event) -> bool {
    match event {
        Event::Key(key) => match key {
            Key::Char('q') => return false,
            Key::Ctrl('c') => return false,
            _ => {}
        },
        Event::Resize(_) => {}
        Event::Elapse => {}
    }

    true
}

fn view_fn(app: &App, _model: &(), canvas: &mut HalfblockCanvas) {
    canvas.clear();
    canvas.draw_text(
        &Point::new(2, 0),
        &Color::text(),
        &format!("press 'q' to quit, frame: {}", app.frame_count),
    );
    canvas.draw_pixel(&Point::new(10, 7), &Rgba::red());
    canvas.display();
}

fn main() {
    AppBuilder::new(|_| ())
        .event(event_fn)
        .view(view_fn)
        .fps(20)
        .run();
}
Commit count: 85

cargo fmt