colored-str
Coloring terminal by parsing string content
This crate is an extension to the colored crate that enables terminal coloring. It provides a trait and a macro to parse a given string that incorporates style flags.
Main features
- Translate colored features into string templating
- Multiple styles and substyles in one same string
- Macros to replace
format!andprintln!with colored strings
Usage
This crate is on crates.io and can be used by adding colored-str to your dependencies in your project's Cargo.toml.
[]
= "0.1.8"
How to use
Styles must be written within <...> opening flag and </> closing flag.
Style variations must be written within <+...> opening flag and <-> closing flag.
See below examples.
Limitations
Blocks cannot be overlapped
Such code <red> ... <blue> ... </> ... </> will not work properly.
This is true as well for variations : <red><+blue> ... <+bold> ... <-><-></> will not work properly.
A style cannot be removed
With <red+bold> ... here I want to keep red only => impossible </>.
The workaround is as follows: <red> <+bold> ... <-> here I have red only </>
Examples
use coloredln;
coloredln!;
coloredln!;
coloredln!;
coloredln!;
coloredln!;
coloredln!;
coloredln!;
You can add variables as per println!
use coloredln;
let message = "this is red";
coloredln!;
coloredln!;
You can add styles adjustments in a block
use coloredln;
coloredln!;
coloredln!;
You can also use it as a trait
use Colored;
let s: String = "<red>this is red</>".colored.to_string;
println!;
List of styles
Colors
blackredgreenyellowbluemagentapurplecyanwhite
All can be used as backgound using on_ prefix.
Light/Bright Colors
lblacklredlgreenlyellowlbluelmagentalpurplelcyanlwhite
All can be used as backgound using on_ prefix.
Decorations
boldunderlineitalicdimmedreversereversedblinkhiddenstrikethrough
True colors
#RRGGBBon_#RRGGBB
Dependencies
Issues
Contributions, issues and feature requests are welcome!
I am quite new to rust, so I guess many things can be improved. I mainly test on linux also, so tests on other platforms are welcome.
Feel free to check issues page. You can also contact me.
License
Copyright (C) 2023 Sebastien Guerri
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.
Contributors
- Sébastien Guerri: @sguerri