Ansirs (Like Answers I Guess?)
Simple and probably flawed little library to make simple usage of ansi color codes super easy when working with rust.
I tend to make a lot of shitty little terminal applications and I got sick of googling for ANSI color codes, or installing some huge or unweildy package to handle it, so I decided to make my own stupid and/or unweildy crate!
Usage is as simple as I could make it because I'm pretty dumb and I wanted to make this as easy as possible on future-me.
use ;
let header_style = new
.fg // Set foreground color to (25, 50, 250)
.bg // Set background to white.
.bold // Set (toggle) bolded text.
.underline; // Set (toggle) underlined text.
let body_style = new
.fg
.bg;
let mistake_style = new
.fg
.bg // Most named html colors can be used from Colors
.strike // Set (toggle) strike-through.
.italic; // Set (toggle) italic text.
// Output can be saved (it is just a String)
let header = style_text;
println!;
// Or you can use style_text directly in println.
println!;
// You can also use the Ansi directly, but must remember to reset the style afterwards.
println!;
println!;
styled_print;
style_text can also take a lambda to generate styles on the fly. The lambda should match the function signature Fn() -> Ansi
// Same output as above, but without the locals variables. Keep in mind this makes reusing styles more difficult.
use ;
println!;
println!;
println!;
Main Types
ansirs::Ansi- The main struct that holds styling and formatting informationansirs::Color- Simple color class represented as(u8, u8, u8)ansirs::Colors- Named (html) colors, convertable toColoras well asAnsiansirs::PrettyString- Coming Soon String-interchangeable type holding text as well as formatting
The following information is for library development, see function documentation for library specifics.
Todo
- Make the usage in example
all_colors_256less cumbersome to work with - Add
coverage, lint, and maybe packaging / publishing gh actions- Coverage is super easy now that rust 1.60 (stable) has stabilized llvm-based coverage instrumentation. Currently I'm using the
cargo-llvm-covcrate, coverage can be generated in lcov format by runningcargo llvm-cov --all-features --workspace --lcov --output-path cov/lcov.info, and can be displayed using the Coverage Gutters vscode extension (ryanluker.vscode-coverage-gutters), or an html report can be generated usingcargo llvm-cov --html
- Coverage is super easy now that rust 1.60 (stable) has stabilized llvm-based coverage instrumentation. Currently I'm using the
- Find whatever mistakes that exist in this crate.
- Expand tests
- Expand functionality?
-
Styledtrait for designating default styling for certain types. I'm thinking something along the lines of the std::fmt family of functions, i.e. a user-defined "builder" type function is written which has access to the instance and some sort of default styling. - Along with above, could maybe move into "themes" as well?