3 releases (stable)
Uses new Rust 2024
new 1.1.0 | Apr 26, 2025 |
---|---|
1.0.0 | Apr 25, 2025 |
0.1.0 | Apr 25, 2025 |
#458 in Command-line interface
90 downloads per month
20KB
140 lines
ransi - Rust ANSI
Table of Contents
About
ransi
is a simple Rust library to help you make TUIs without going through
the pain of ANSI escape codes.
ransi
provides a simple and easy-to-use API that allows you
to format, color, and style text on the terminal.
Features
- Works in almost all terminals
- Supports every ANSI escape code 1
- True color support
- 256 color support
- 16 color support
- No dependencies
- Lightweight
- Easy to use
Installation
Run this command to install the latest version of ransi
:
cargo add ransi
Or add it to your Cargo.toml
file:
[dependencies]
ransi = "0.1"
Usage
Functions
Function | Description |
---|---|
change_fg(color: &str or (r: u8, g: u8, b: u8)) |
Change the foreground color |
change_bg(color: &str or (r: u8, g: u8, b: u8)) |
Change the background color |
bold(string: &str) |
Make the string be bold if printed |
italic(string: &str) |
Make the string be italic if printed |
blink(string: &str) |
Make the string blink if printed |
mov_cur(x: u16, y: u16) |
Move the cursor to a position |
` |
Traits
ransi::ColorIn
- Color Input. Used by thechange_col
function to support or a tuple of threeu8
s or the color name.
Notes
Supports every ANSI escape code
This isn't completely true, as it misses the 21m escape code, which almost always leads to undefined behavior in different terminals.
Originally, 21m was used to dim text, but no terminal supports it, and the ones that do, double-underline the text and make it bright. Others keep the default behavour
It is pretty confusing, so we don't support it.