3 unstable releases
0.2.1 | Nov 21, 2023 |
---|---|
0.2.0 | Nov 21, 2023 |
0.1.0 | Nov 10, 2023 |
#2087 in Game dev
29 downloads per month
13KB
201 lines
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. 💖
Dependencies
~0.8–6.5MB
~20K SLoC