gory

Crates.iogory
lib.rsgory
version0.1.14
sourcesrc
created_at2020-12-25 23:40:21.225009
updated_at2020-12-31 18:57:05.768527
descriptionAdd a little color to the task
homepagehttps://github.com/phR0ze/gory
repositoryhttps://github.com/phR0ze/gory
max_upload_size
id327299
size51,338
(phR0ze)

documentation

README

gory

license-badge build codecov crates.io Minimum rustc

Add a little color to the task

gory was created to provide super simple color usage for Linux terminals in a well documented way. gory will automatically detect the abscence of a TTY and disable color output. However color can also be disabled manually via the env variable TERM_COLOR or forced on or off at runtime as needed.

Example:
Display colors

Quick links

Usage

Requires rustc >= 1.30

This minimum rustc requirement is driven by the enhancements made to Rust's std::error::Error handling improvements

  1. Import gory into your project via Cargo.toml
    [dependencies]
    gory = "0.1"
    
  2. Use all of gory as its simple and tiny
    use gory::*;
    
  3. Call functions off the default Colorable types String and &'static str
    use gory::*;
    
    fn main() {
        print!("{}  ", format!("\\e[1;{}m", Color::Red).red());
        print!("{}  ", "red".red());
        println!();
    }
    

Get String

To get the wrapped String out of a ColorString just dereference it.

use gory::*;

fn main() {
  let cstr = String::from("foo").red();
  assert!(String::from("foo"), *cstr);
}

Control use

Color output can be enabled or disabled using the TERM_COLOR varible.

gory will automatically detect whether a terminal is attached and if so and TERM_COLOR is truthy or not set it will automatically use color when specified to do so in the code. If TERM_COLOR is set to something falsy color will not be emitted despited an attached tty or use of color functions in the code.

Additionally however for testing or for other reasons it may be nice to force color to be enabled or disabled regardless of the presence of a tty or the the env var. This can be done at runtime by invoking the function Color::force(val: Option<bool>) and giving it true to force on and false to force off and None to return to automatic control.

use gory::*;

fn main() {
  Color::force(Some(true));
  Color::force(Some(false));
  Color::force(None);
}

Contribute

Pull requests are always welcome. However understand that they will be evaluated purely on whether or not the change fits with my goals/ideals for the project.

Git-Hook

Enable the git hooks to have automatic version increments

cd ~/Projects/gory
git config core.hooksPath .githooks

License

This project is licensed under either of:

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


Backlog

  • Improve documentation
  • Support more pre-defined colors like orange?
  • Support styles like underline?

Changelog

  • 12/30/2020
    • Corrected the minimum rustc badge and added a description
Commit count: 22

cargo fmt