rusty_textui

Crates.iorusty_textui
lib.rsrusty_textui
version0.2.1
sourcesrc
created_at2023-11-10 21:45:37.356719
updated_at2023-11-21 22:13:12.083355
descriptionLibrary for creating simple text user interfaces, like text arcade games in the terminal
homepagehttps://github.com/CleanCut/rusty_textui
repositoryhttps://github.com/CleanCut/rusty_textui
max_upload_size
id1031477
size14,889
Nathan Stocks (CleanCut)

documentation

README

Rusty Text UI (rusty_textui)

rusty_textui is a simple Text UI engine intended to be used by people who are just beginning to learn Rust. It has a simple interface with enough functionality to easily create a terminal-based game or application. I created it specifically for students of my Ultimate Rust Crash Course to use to for their course projects. You may want to use this together with rusty_audio to produce sound, and rusty_time for timers.

Quick Start

In your terminal, add rusty_textui to your project:

cargo add rusty_textui

In your code:

use rusty_textui::prelude::*; // Bring all the important stuff into scope

fn main() {
    // Create the screen
    let mut screen = Screen::new(80, 25, false);

    // Set up game/application logic
    let mut player_col: usize = 0;

    // Set up a main loop, with a label so it can be exited easily
    'mainloop: loop {
        // Handle user input
        for key_event in screen.get_key_events() {
            match key_event.code {
                KeyCode::Right => player_col = (player_col + 1).clamp(0, 79),
                KeyCode::Left => player_col = player_col.saturating_sub(1),
                KeyCode::Esc => break 'mainloop, // Esc key exits the main loop
                _ => {}
            }
        }

        // Draw the current state of everything
        screen.draw(player_col, 12, "X", Color::Blue);

        // Flip the frames so the one we drew to is visible, and a new blank frame is ready for us
        // to draw the next frame to.
        screen.flip();
    }
}

Contribution

All contributions are assumed to be dual-licensed under MIT/Apache-2.

License

Distributed under the terms of both the MIT license and the Apache License (Version 2.0).

See license/APACHE and license/MIT.

Sponsor

If you like Rusty Audio, please consider sponsoring me on GitHub. 💖

Commit count: 8

cargo fmt