TerimalRtdm
Lightwight, Simple, Easy to read, Ideomatic Rust Terimal Interface Library for CUIs
⭐️ Show support by leaving a star. Check out Github for up to date docs
https://github.com/had2020/TerimalRtdm
👉 Why use it
This framework provides many usful functions that abstract ACSI escape keys, allowing for easy implementation for a Terimal Interface.
- 🔢 Many features like key_press(), allows you to check a key without halting for a check.
- ⏱️ You can write Terimal GUIs much faster!
- 🖼️ Lots of functions allowing for more customizability, while keeping code readable and ideomatic.
📝 Example app
This is an example of using the framework, involving two key checks that don't halt the program twice.
clear; // clear any debug logs
let mut app = new; // store the variables relating to the terimal app
raw_line; // displays on a new line
raw_line; // use only for startup text, relay on line method
raw_mode; // for propper input enable
// app loop
loop
raw_mode; // disable to release the user terimal
🧮 Core functions
App Struct
- Used to automatically hold variables outside the app loop.
- Holds the key buffer, from input and the key pressed for input checking in app. loop.
let mut app = new;
clear()
- Used to clear the screen.
- Tip: follow the structure in the later section of the Docs.
clear;
cursor_state()
- Used to toggle on and off the Cursor
cursor_state;
raw_mode()
- Used to enable raw input, which is required for most Terimal apps.
- Tip: Should toggled true before app loop, and toggled false after, to free the user.
raw_mode
raw_line()
- displays on a new line before app loop
- Use only for startup text, relay on line method
raw_line;
halt_press_check()
- Halts the program until the user has pressed a key
- will not be recored into app variable.
- So input will only be used for this if statement.
if halt_press_check
Position Struct
- Used as argument in many functions.
- Holds x and y position in the Terimal.
- X number of spaced words to the right
- Y number pf spaced workds Down
- Tip: You can use the position! macro to easly make a Position Structed
position!
collect_presses()
- collects the current press in a single halt, and stores it in App variable.
- Later inout statements refer to this value, to prevent unneeded halts, within the main loop for app.
- Used after clear, before any input if statements.
collect_presses;
key_press()
- You must have one collect_presses() before at the start of the loop!
- Returns true if &str equals the last &str of input.
if key_press
key_press_not_case_sen()
- Refer to key_press(), for usage.
- Its the same, just not case sensitive.
if key_press
How it works
🎨 Color Map
| Color | ANSI Code | Emoji |
|---|---|---|
| red | \x1B[31m |
🟥 |
| green | \x1B[32m |
🟩 |
| yellow | \x1B[33m |
🟨 |
| blue | \x1B[34m |
🟦 |
| magenta | \x1B[35m |
🟪 |
| cyan | \x1B[36m |
🟦 |
| white | \x1B[37m |
⬜️ |
| _ (fallback default) | \x1B[0m |
⬛️ |
⌨️ Key Map
Most are directly named, q is q, and Q is Q
- Refer to
find_key_pressed(), for more keys.
🏛️ Structure
- clear, old text < optional
clear() - setup app struct with new()
let mut app = App::new(); - Tip: this is a good place for raw lines to display exits or shortcut keys
- set raw mode to true, with raw_mode()
raw_mode(true); loop {}- loops for each new input- Inside clear, for old text < optional
clear() - collect_presses(), to store the current key pressed in app
collect_presses(&mut app); - any if statements, like key_press() and code process
if key_press(&app, "w") - Outside the loop
- set raw mode to false, for exiting the app
raw_mode(false);
👉 Major Usage in another projects!
-
For a Nano like text editer https://github.com/had2020/Runo
-
For a terimal based web browser. https://github.com/had2020/RusosBr