Crates.io | lliw |
lib.rs | lliw |
version | 0.2.0 |
source | src |
created_at | 2021-02-25 18:36:26.331961 |
updated_at | 2021-09-01 12:20:32.474219 |
description | Text colours and styles for your terminal with no additional dependencies |
homepage | |
repository | https://github.com/curlpipe/lliw |
max_upload_size | |
id | 360617 |
size | 13,540 |
Roughly pronounced khlew, it is "colour" in Welsh
Lliw provides colours for your terminal, with no additional dependencies.
#![no_std]
environmentsIf you have cargo-edit
installed, it's as easy as:
cargo add lliw
if you don't have cargo-edit
you can add the following to your Cargo.toml
file
[dependencies]
lliw = "0"
use lliw::{Fg, Bg, Style, Reset};
fn main() {
// Prints "Blue" in a blue colour
println!("{}Blue{}", Fg::Blue, Fg::Reset);
// Prints "Bold" in bold
println!("{}Bold{}", Style::Bold, Style::NoBold);
// Prints "Green" with a green background
println!("{}Green{}", Bg::Green, Bg::Reset);
// You can even use it in more complicated ways
println!(
"{}{}Attention!{}{} You have {}{}1{}{} new message",
Style::Underline, Fg::Yellow,
Style::NoUnderline, Fg::Reset,
Bg::White, Fg::Black,
Bg::Reset, Fg::Reset,
);
// You can make them go over the top of each other too
println!(
"{}Hello{} Wor{}ld! My{} Name{} {}Is{} Lliw{}",
Style::Italic, Fg::LightPurple,
Bg::Black, Fg::Reset, Style::NoItalic,
Style::Underline, Bg::Reset, Reset
);
// Don't like these long formatting macros? You can use it like this too!
print!("{}", Fg::LightRed);
print!("Hello\nThere!");
print!("{}\n", Reset);
// You can also use an RGB value if you want 24-bit colours
println!(
"{}R{}a{}i{}n{}b{}o{}w{}",
Fg::Rgb(255, 0, 0),
Fg::Rgb(255, 128, 0),
Fg::Rgb(255, 255, 0),
Fg::Rgb(0, 255, 0),
Fg::Rgb(0, 255, 255),
Fg::Rgb(128, 0, 255),
Fg::Rgb(255, 0, 128),
Fg::Reset,
);
}
There are 3 enums provided with lliw, Fg
, Bg
and Style
.
There is also 1 struct, Reset
.
Fg
- Control the text colour
Reset
variant.Bg
- Control the text background colour
Reset
variant.Style
- Control the text styles
NoBold
NoUnderline
NoItalic
NoInverse
NoFaint
NoStrike
Reset
- This is a full reset struct that resets foreground, background and style when used.Be sure to check out the docs over at https://docs.rs/lliw
License: MIT