Crates.io | rusty_textui |
lib.rs | rusty_textui |
version | 0.2.1 |
source | src |
created_at | 2023-11-10 21:45:37.356719 |
updated_at | 2023-11-21 22:13:12.083355 |
description | Library for creating simple text user interfaces, like text arcade games in the terminal |
homepage | https://github.com/CleanCut/rusty_textui |
repository | https://github.com/CleanCut/rusty_textui |
max_upload_size | |
id | 1031477 |
size | 14,889 |
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.
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();
}
}
All contributions are assumed to be dual-licensed under MIT/Apache-2.
Distributed under the terms of both the MIT license and the Apache License (Version 2.0).
See license/APACHE and license/MIT.
If you like Rusty Audio, please consider sponsoring me on GitHub. 💖