17 releases

0.8.3 Nov 8, 2023
0.8.0 Sep 11, 2023
0.7.3 Jan 15, 2023
0.6.0 Dec 25, 2022
0.4.0 Nov 23, 2022

#308 in Command-line interface

Download history 2/week @ 2024-09-22 9/week @ 2024-09-29

70 downloads per month

MIT license

54KB
1.5K SLoC

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();
}

Dependencies

~245–330KB