- β±οΈ Quickstart
- π Documentation
- π§© Templates
- ποΈ Built with TerimalRtdm
- βοΈ Leave a star!
- β¨οΈ Contributing
- π License
TerimalRtdm
Dependencless, Ideomatic, Rust Terimal Interface Library for quick CUIs when you need a tool ready pronto!
Report a Bug Β· Request a Feature
TerimalRtdm Which stands for: Terminal, Rust, Text, Display Manager.
- Display colored text at absolute positions
- Read keyβpresses easily
- Simple app loop with App, and ideomatic methods
- No heavy dependencies, just ANSI escapes
Quickstart
TerimalRtdm works in Rust binarys, follow these steps to setup a boiler plate, or check out the TerimalRtdm Examples Repository
1.) Add Crate.
cargo add TerimalRtdm
2.) Then use this boiler plate.
use *;
Templates
See the TerimalRtdm Boiler Plate Repository
-> More details documented in the Boiler Plate Repo.
Fast Documentation
TerimalRtdm is an intermediate mode terminal UI framework. This means each update to the interface is triggered by user input. It works in any Rust binary, but requires some light setup and a sequence of steps to initialize properly. That said, the setup process is simpler, and more versatile than most other UI crates.
π±οΈ You can click each instruction to open, and see code changes.
Add our crate to your toml:
cargo add TerimalRtdm
Then declare it's usage:
use *;
use *;
use *;
use *;
use *;
use *;
Text can be moved around the screen with the Pos struct, which moves text around by letter units, where the text should start to be displayed.
If you want to see the length of the text use your_text_var.len() with the variable being a &str type. This returns the length of chars that will be printed with the first one starting at x in Pos.
Optionally: You can change the text's style, position, foreground(color of the text) and background.
new
.foreground // Check Color and style enum's for varient options!
.background
.style
.show; // each x and y is one char and "Hello world".len() returns 11, so we start at 13.
Keep in mind: Text is layered with the bottommost being the highest drawn layer, as your code goes down linearly.
In case you are displaying a text under a key being pressed, you can toggle it's vanishing under other keys.
new
.vanish
.show; // displays on the second line of the screen, as `y` is set to `1`.
KeyType is an enum representing all possible key combinations.
If a key is missing on the crate's end, it will default to: KeyType::Unknown
Key is a struct used for optional parameters, following idiomatic Rust patterns.
use *;
You can also add the no_clear() impl on Key::o() if you spefied text to show only under the specific input, and does not effect that text, which is useful for cursor movement.
if o.no_clear.pressed
use *;
This allows us to check for this input next loop.
use *;
Optional: Enable Escape Sequence Handling
By default, the app does not check for escape sequences (such as function keys and arrow keys).
This is because enabling them requires tracking the Esc key being pressed up to three times,
which can interfere with simple Esc based interactions.
Unless you really need to support function or arrow keys, it's recommended to leave this option disabled, so users can freely press Esc without unintended side effects.
If your app needs arrow or function key support, you can enable this behavior by toggling the relevant bool flag, and untoggle once the user needs to press escape, like in vim.
app.enable_f_row_and_arrow = true;
use *;
You can easily move the cursor using the Mov::cur().dir() method along with key inputs. This snippet shows a typical setup using Key::o() with KeyType directions.
moving the cursor in any direction
if o.no_clear.pressed
if o.no_clear.pressed
if o.no_clear.pressed
if o.no_clear.pressed
You can also change the behavior when moving the cursor as well.
By default it is set to wrap like a normal text editor.
but you can optinal apply the impl block() or freefloat() on Mov::cur().
if o.no_clear.pressed
| Mode | Description |
|---|---|
block |
Stops the user from moving out of the current line even if they reach the end. |
freefloat |
Lets the user move anywhere within the bounds of the screen. |
wrap |
The default; acts like nano or a normal text editor, pushing the cursor to the start of the next line once they reach the end. |
βοΈ Support futher development, with a star!
https://github.com/had2020/TerimalRtdm
Built with TerimalRtdm
Note these projects are outdated, but still demonstrate capabilities of the crate. Both projects were built with verison 0.0.3, which is less ideomatic, and missing a lot of higher level features.
-
For a Nano like text editer Runo
-
For a terimal based web browser. RusosBr
-
Not outdated but, WIP vim clone in Rust. Hadrium
License
This project is licensed under the MIT License.
Copyright Β© Hadrian Lazic
See the LICENSE file for details.