simple/
simple.rs

1use std::io;
2use teng::components::Component;
3use teng::rendering::pixel::Pixel;
4use teng::rendering::render::Render;
5use teng::rendering::renderer::Renderer;
6use teng::{install_panic_handler, terminal_cleanup, terminal_setup, Game, SharedState};
7
8struct MyComponent;
9
10impl Component for MyComponent {
11    fn render(&self, renderer: &mut dyn Renderer, shared_state: &SharedState, depth_base: i32) {
12        let width = shared_state.display_info.width();
13        let height = shared_state.display_info.height();
14        let x = width / 2;
15        let y = height / 2;
16        let pixel = Pixel::new('█').with_color([0, 255, 0]);
17        renderer.render_pixel(x, y, pixel, depth_base);
18
19        "Hello World"
20            .with_bg_color([255, 0, 0])
21            .render(renderer, x, y + 1, depth_base);
22    }
23}
24
25fn main() -> io::Result<()> {
26    terminal_setup()?;
27    install_panic_handler();
28
29    let mut game = Game::new_with_custom_buf_writer();
30    // If you don't install the recommended components, you will need to have your own
31    // component that exits the process, since Ctrl-C does not work in raw mode.
32    game.install_recommended_components();
33    game.add_component(Box::new(MyComponent));
34    game.run()?;
35
36    terminal_cleanup()?;
37
38    Ok(())
39}