Crate simply_colored

Source
Expand description

§simply_colored

This crate is the simplest yet ergonomic way to add color to your terminal:

use simply_colored::*;

println!("{BLUE}{BOLD}Simply colored!")

§Foreground

ColorTypeTo get
Green{GREEN}Simply colored!Green text color in terminal
Yellow{YELLOW}Simply colored!Yellow text color in terminal
Red{RED}Simply colored!Red text color in terminal
Magenta{MAGENTA}Simply colored!Magenta text color in terminal
Blue{BLUE}Simply colored!Blue text color in terminal
Cyan{CYAN}Simply colored!Cyan text color in terminal
White{WHITE}Simply colored!White text color in terminal
Black{BLACK}Simply colored!Black text color in terminal
Dim green{DIM_GREEN}Simply colored!Dim green text color in terminal
Dim yellow{DIM_YELLOW}Simply colored!Dim yellow text color in terminal
Dim red{DIM_RED}Simply colored!Dim red text color in terminal
Dim magenta{DIM_MAGENTA}Simply colored!Dim magenta text color in terminal
Dim blue{DIM_BLUE}Simply colored!Dim blue text color in terminal
Dim cyan{DIM_CYAN}Simply colored!Dim cyan text color in terminal
Dim white{DIM_WHITE}Simply colored!Dim white text color in terminal
Dim black{DIM_BLACK}Simply colored!Dim black text color in terminal

§Background

ColorTypeTo get
Green{BG_GREEN}Simply colored!Green text color in terminal
Yellow{BG_YELLOW}Simply colored!Yellow text color in terminal
Red{BG_RED}Simply colored!Red text color in terminal
Magenta{BG_MAGENTA}Simply colored!Magenta text color in terminal
Blue{BG_BLUE}Simply colored!Blue text color in terminal
Cyan{BG_CYAN}Simply colored!Cyan text color in terminal
White{BG_WHITE}Simply colored!White text color in terminal
Black{BG_BLACK}Simply colored!Black text color in terminal
Dim green{BG_DIM_GREEN}Simply colored!Dim green text color in terminal
Dim yellow{BG_DIM_YELLOW}Simply colored!Dim yellow text color in terminal
Dim red{BG_DIM_RED}Simply colored!Dim red text color in terminal
Dim magenta{BG_DIM_MAGENTA}Simply colored!Dim magenta text color in terminal
Dim blue{BG_DIM_BLUE}Simply colored!Dim blue text color in terminal
Dim cyan{BG_DIM_CYAN}Simply colored!Dim cyan text color in terminal
Dim white{BG_DIM_WHITE}Simply colored!Dim white text color in terminal
Dim black{BG_DIM_BLACK}Simply colored!Dim black text color in terminal

§Effects

EffectType
Italic{ITALIC}Simply colored!
Bold{BOLD}Simply colored!
Underline{UNDERLINE}Simply colored!
Blink{BLINK}Simply colored!
Reverse{REVERSE}Simply colored!
Strikethrough{STRIKETHROUGH}Simply colored!
Dim{DIM}Simply colored!
Hide{HIDE}Simply colored!
Reset all styles{RESET}Simply colored!

All effects can be prefixed with NO_ to disable e.g. NO_BOLD.

§Extra

If you want links in the terminal, all you need is:

fn hyperlink(link: impl core::fmt::Display, text: impl core::fmt::Display) -> String {
    format!("\x1b]8;;{link}\x1b\\{text}\x1b]8;;\x1b\\")
}

Example usage:

println!(
    "Check out simply_colored on {}!",
    hyperlink(
        "https://github.com/nik-rev/simply-colored",
        "GitHub"
    )
);

Constants§

BG_BLACK
Set background of text to black
BG_BLUE
Set background of text to blue
BG_CYAN
Set background of text to cyan
BG_DEFAULT
Set background of text to default
BG_DIM_BLACK
Set background of text to dim black
BG_DIM_BLUE
Set background of text to dim blue
BG_DIM_CYAN
Set background of text to dim cyan
BG_DIM_DEFAULT
Set background of text to default
BG_DIM_GREEN
Set background of text to dim green
BG_DIM_MAGENTA
Set background of text to dim magenta
BG_DIM_RED
Set background of text to dim red
BG_DIM_WHITE
Set background of text to dim white
BG_DIM_YELLOW
Set background of text to dim yellow
BG_GREEN
Set background of text to green
BG_MAGENTA
Set background of text to magenta
BG_RED
Set background of text to red
BG_WHITE
Set background of text to white
BG_YELLOW
Set background of text to yellow
BLACK
Set color of text to black
BLINK
Following text will be blinking
BLUE
Set color of text to blue
BOLD
Following text will be bold
CYAN
Set color of text to cyan
DEFAULT
Set color of text to default
DIM
Following text will be dim
DIM_BLACK
Set color of text to dim black
DIM_BLUE
Set color of text to dim blue
DIM_CYAN
Set color of text to dim cyan
DIM_DEFAULT
Set color of text to default
DIM_GREEN
Set color of text to dim green
DIM_MAGENTA
Set color of text to dim magenta
DIM_RED
Set color of text to dim red
DIM_WHITE
Set color of text to dim white
DIM_YELLOW
Set color of text to dim yellow
GREEN
Set color of text to green
HIDE
Following text will be invisible
ITALIC
Following text will be italic
MAGENTA
Set color of text to magenta
NO_BLINK
Following text will NOT be blinking
NO_BOLD
Following text will NOT be bold
NO_DIM
Following text will NOT be dim
NO_HIDE
Following text will be visible
NO_ITALIC
Following text will NOT be italic
NO_REVERSE
Foreground and background for the following text will NOT be reversed
NO_STRIKETHROUGH
Following text will NOT be crossed out
NO_UNDERLINE
Following text will NOT be underlined
RED
Set color of text to red
RESET
Reset styling
REVERSE
Foreground and background for the following text will be reversed
STRIKETHROUGH
Following text will be crossed out
UNDERLINE
Following text will be underlined
WHITE
Set color of text to white
YELLOW
Set color of text to yellow