Crates.io | grux |
lib.rs | grux |
version | 0.2.0 |
source | src |
created_at | 2023-01-04 19:34:08.568458 |
updated_at | 2023-01-05 01:45:20.727705 |
description | A library for drawing grid-based user interfaces using ASCII characters |
homepage | |
repository | https://github.com/matanlurey/grux |
max_upload_size | |
id | 751070 |
size | 34,858 |
A library for drawing grid-based user interfaces using ASCII characters.
// Provides a uniform interface for drawing to a 2D grid.
use grux::GridWriter;
// Create a 3x3 2D array.
// Alternatives provided by `grux`: `Vec<Vec<T>>` and `String`.
let mut grid = [[' '; 3]; 3];
// Draw some random stuff. In practice, you'd probably use the `Sprite` trait.
grid.set((0, 0), '╔');
grid.set((1, 0), '═');
grid.set((2, 0), '╗');
grid.set((0, 1), '║');
grid.set((2, 1), '║');
grid.set((0, 2), '╚');
grid.set((1, 2), '═');
grid.set((2, 2), '╝');
// Provides a uniform interface for displaying a 2D grid.
use grux::DisplayGrid;
// ╔═╗
// ║ ║
// ╚═╝
println!("{}", grid.to_string().unwrap());
See the examples directory for more, including built-in sprites.
There are plenty of existing libraries for terminal-based user interfaces, but none of them are quite what I wanted. I wanted a library that would let me draw a grid of cells, each of which could contain a single character.
Importantly, Grux isn't a UI framework.
It doesn't handle input or even output. It just lets you draw to a grid-like structure, which could be:
Vec<Vec<T>>
String
[[T; 10]; 10]
)GridWriter
and/or DisplayGrid
)tl;dr: Draw to whatever you want, and build on top of it (or replace it).