Crates.io | ruscii |
lib.rs | ruscii |
version | 0.4.0 |
source | src |
created_at | 2019-12-27 10:27:03.561963 |
updated_at | 2023-04-11 08:54:03.347226 |
description | Terminal graphics engine |
homepage | https://github.com/lemunozm/ruscii/ |
repository | https://github.com/lemunozm/ruscii/ |
max_upload_size | |
id | 192615 |
size | 109,797 |
ruscii
An easy-to-use library for writing terminal applications and games in Rust.
The aim of this project is to make text-based game development straightforward and effortless. Any contribution, issue, or pull request would be greatly appreciated!
ruscii
uses it to create transparent key-pressed and key-released events.To compile applications written using ruscii
in Linux, you must have the X11 development libraries installed.
If your system does not have them, you can use the following commands in the terminal to install them according to your specific Linux distribution.
sudo apt install libx11-dev
sudo dnf install xorg-x11-server-devel
Windows and macOS have no special dependencies.
You can find several examples of applications and games written using ruscii
in the examples folder.
To test one out, install ruscii
with the examples flag using the following command.
cargo install ruscii --examples
~/.cargo/bin/<example_name>
After it's installed, run it with:
cargo run --example <example_name> --release
Note: the first
asciimedia
playback might be laggy; playing it a second time fixes this issue.
ruscii
If you have a project using ruscii
and would like it to appear here, open an issue!
Add the following line to the [dependencies]
section in your Cargo.toml
file:
ruscii = "0.4.0"
Copy the following code to your main.rs
file to run the base ruscii
application:
use ruscii::app::{App, State};
use ruscii::terminal::{Window};
use ruscii::drawing::{Pencil};
use ruscii::keyboard::{KeyEvent, Key};
use ruscii::spatial::{Vec2};
use ruscii::gui::{FPSCounter};
fn main() {
let mut fps_counter = FPSCounter::new();
let mut app = App::new();
app.run(|app_state: &mut State, window: &mut Window| {
for key_event in app_state.keyboard().last_key_events() {
match key_event {
KeyEvent::Pressed(Key::Esc) => app_state.stop(),
KeyEvent::Pressed(Key::Q) => app_state.stop(),
_ => (),
}
}
fps_counter.update();
let mut pencil = Pencil::new(window.canvas_mut());
pencil.draw_text(&format!("FPS: {}", fps_counter.count()), Vec2::xy(1, 1));
});
}
Debugging a terminal app is usually difficult because the app output and the backtrace goes to the same terminal view.
ruscii
uses the standard output to render your app and the standard error to log error information.
We recommend that you redirect the standard error to a file to be inspected later.
To run your project with error logs saved to a file, run the following commands:
export RUST_BACKTRACE=1
cargo run 2> my_stderr
All error output will be saved to my_stderr
in the project directory.