colorful-0.2.2/.cargo_vcs_info.json0000644000000001360000000000100126620ustar { "git": { "sha1": "ec495217cebae8528184c330ca334c25ec434129" }, "path_in_vcs": "" }colorful-0.2.2/.gitignore000064400000000000000000000005231046102023000134420ustar 00000000000000# Generated by Cargo # will have compiled files and executables /target/ # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html Cargo.lock # These are backup files generated by rustfmt **/*.rs.bk .DS_Store /.idea/ colorful-0.2.2/.travis.yml000064400000000000000000000022021046102023000135570ustar 00000000000000language: rust sudo: true dist: trusty matrix: fast_finish: true include: - rust: stable env: FEATURES="--no-default-features" cache: cargo: true directories: - $HOME/.m2/repository - $HOME/.sonar addons: apt: packages: - binutils-dev - libcurl4-openssl-dev - zlib1g-dev - libdw-dev - libiberty-dev - oracle-java8-installer script: - cargo build $FEATURES - cargo test after_success: - 'TARGET=$HOME/kcov && mkdir $TARGET && export PATH=$TARGET/bin:$PATH && wget https://github.com/SimonKagstrom/kcov/archive/master.tar.gz && tar xzf master.tar.gz && mkdir kcov-master/build && cd kcov-master/build && cmake .. -DCMAKE_INSTALL_PREFIX:PATH=$TARGET && make && make install && cd ../.. && ls target/debug && ls $TARGET/bin && echo $PATH' - 'for file in target/debug/*; do if [[ -x $file && -f $file ]]; then mkdir -p "target/cov/$(basename $file)"; kcov --exclude-pattern=/.cargo,/usr/lib --verify "target/cov/$(basename $file)" "$file"; fi; done' - 'kcov --coveralls-id=$TRAVIS_JOB_ID --merge target/cov target/cov/*' env: global: - RUST_BACKTRACE=1 colorful-0.2.2/Cargo.lock0000644000000002300000000000100106300ustar # This file is automatically @generated by Cargo. # It is not intended for manual editing. version = 3 [[package]] name = "colorful" version = "0.2.2" colorful-0.2.2/Cargo.toml0000644000000016260000000000100106650ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] name = "colorful" version = "0.2.2" authors = ["da2018 "] exclude = [ "images/*", "examples", ] description = "Make your terminal output colorful" homepage = "https://github.com/mellite/colorful" readme = "README.md" keywords = [ "cli", "colors", "terminal", ] categories = [ "cli", "colors", "terminal", ] license = "MIT" repository = "https://github.com/mellite/colorful" [dependencies] colorful-0.2.2/Cargo.toml.orig000064400000000000000000000006261046102023000143450ustar 00000000000000[package] name = "colorful" version = "0.2.2" authors = ["da2018 "] description = "Make your terminal output colorful" license = "MIT" homepage = "https://github.com/mellite/colorful" readme = "README.md" keywords = ["cli","colors","terminal"] categories = ["cli","colors","terminal"] repository = "https://github.com/mellite/colorful" exclude = ["images/*","examples"] [dependencies] colorful-0.2.2/CodeOfConduct.md000064400000000000000000000062221046102023000144550ustar 00000000000000# Contributor Covenant Code of Conduct ## Our Pledge In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. ## Our Standards Examples of behaviour that contributes to creating a positive environment include: - Using welcoming and inclusive language - Being respectful of differing viewpoints and experiences - Gracefully accepting constructive criticism - Focusing on what is best for the community - Showing empathy towards other community members Examples of unacceptable behaviour by participants include: - The use of sexualised language or imagery and unwelcome sexual attention or advances - Trolling, insulting/derogatory comments, and personal or political attacks - Public or private harassment - Publishing others’ private information, such as a physical or electronic address, without explicit permission - Other conduct which could reasonably be considered inappropriate in a professional setting ## Our Responsibilities Project maintainers are responsible for clarifying the standards of acceptable behaviour and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behaviour. Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviours that they deem inappropriate, threatening, offensive, or harmful. ## Scope This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. ## Enforcement Instances of abusive, harassing, or otherwise unacceptable behaviour may be reported by contacting the project team at tituswormer@gmail.com. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project’s leadership. ## Attribution This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at . [homepage]: https://www.contributor-covenant.org colorful-0.2.2/README.md000064400000000000000000000301641046102023000127350ustar 00000000000000

Colorful

[![Build Status](https://travis-ci.org/rocketsman/colorful.svg?branch=master)](https://travis-ci.org/rocketsman/colorful) [![Coverage Status](https://coveralls.io/repos/github/rocketsman/colorful/badge.svg?branch=master)](https://coveralls.io/github/rocketsman/colorful?branch=master) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/37a45510f41445eea0168f0f07e8f7cb)](https://app.codacy.com/app/rocketsman/colorful_2?utm_source=github.com&utm_medium=referral&utm_content=rocketsman/colorful&utm_campaign=Badge_Grade_Dashboard) ## Usage ### Basic Usage ```Rust extern crate colorful; use colorful::Color; use colorful::Colorful; //use colorful::HSL; //use colorful::RGB; fn main() { let s = "Hello world"; println!("{}", s.color(Color::Blue).bg_color(Color::Yellow).bold()); // println!("{}", s.color(HSL::new(1.0, 1.0, 0.5)).bold()); // println!("{}", s.color(RGB::new(255, 0, 0)).bold()); println!("{}", s.blue().bg_yellow()); } ``` ### Gradient ```Rust extern crate colorful; use colorful::Color; use colorful::Colorful; fn main() { println!("{}", "This code is editable and runnable!".gradient(Color::Red)); println!("{}", "¡Este código es editable y ejecutable!".gradient(Color::Green)); println!("{}", "Ce code est modifiable et exécutable !".gradient(Color::Yellow)); println!("{}", "Questo codice è modificabile ed eseguibile!".gradient(Color::Blue)); println!("{}", "このコードは編集して実行出来ます!".gradient(Color::Magenta)); println!("{}", "여기에서 코드를 수정하고 실행할 수 있습니다!".gradient(Color::Cyan)); println!("{}", "Ten kod można edytować oraz uruchomić!".gradient(Color::LightGray)); println!("{}", "Este código é editável e executável!".gradient(Color::DarkGray)); println!("{}", "Этот код можно отредактировать и запустить!".gradient(Color::LightRed)); println!("{}", "Bạn có thể edit và run code trực tiếp!".gradient(Color::LightGreen)); println!("{}", "这段代码是可以编辑并且能够运行的!".gradient(Color::LightYellow)); println!("{}", "Dieser Code kann bearbeitet und ausgeführt werden!".gradient(Color::LightBlue)); println!("{}", "Den här koden kan redigeras och köras!".gradient(Color::LightMagenta)); println!("{}", "Tento kód můžete upravit a spustit".gradient(Color::LightCyan)); println!("{}", "این کد قابلیت ویرایش و اجرا دارد!".gradient(Color::White)); println!("{}", "โค้ดนี้สามารถแก้ไขได้และรันได้".gradient(Color::Grey0)); } ```
### Gradient with style ```Rust extern crate colorful; use colorful::Colorful; fn main() { println!("{}", "言葉にできず 凍えたままで 人前ではやさしく生きていた しわよせで こんなふうに雑に 雨の夜にきみを 抱きしめてた".gradient_with_color(HSL::new(0.0, 1.0, 0.5), HSL::new(0.833, 1.0, 0.5)).underlined()); } ```
### Bar chart ```Rust extern crate colorful; use colorful::Colorful; use colorful::HSL; fn main() { let s = "█"; println!("{}\n", "Most Loved, Dreaded, and Wanted Languages".red()); let values = vec![78.9, 75.1, 68.0, 67.0, 65.6, 65.1, 61.9, 60.4]; let languages = vec!["Rust", "Kotlin", "Python", "TypeScript", "Go", "Swift", "JavaScript", "C#"]; let c = languages.iter().max_by_key(|x| x.len()).unwrap(); for (i, value) in values.iter().enumerate() { let h = (*value as f32 * 15.0 % 360.0) / 360.0; let length = (value - 30.0) as usize; println!("{: ### Animation #### Rainbow ```Rust extern crate colorful; use colorful::Colorful; fn main() { let text = format!("{:^50}\n{}\r\n{}", "岳飞 小重山", "昨夜寒蛩不住鸣 惊回千里梦 已三更 起身独自绕阶行 人悄悄 帘外月胧明", "白首为功名 旧山松竹老 阻归程 欲将心事付瑶琴 知音少 弦断有谁听"); text.rainbow(); } ``` Output
#### Neon ```Rust extern crate colorful; use colorful::Colorful; fn main() { let text = format!("{:^28}\n{}", "WARNING", "BIG BROTHER IS WATCHING YOU!!!"); text.neon(RGB::new(226, 14, 14), RGB::new(158, 158, 158)); // or you can use text.warn(); } ``` Output
## Terminals compatibility
Terminal Formatting Color
BoldDimUnderlinedBlinkInvertHidden 81688256
aTerm ~
Eterm ~ ~
GNOME Terminal
Guake
Konsole
Nautilus Terminal
rxvt ~
Terminator
Tilda
XFCE4 Terminal
XTerm
xvt
Linux TTY ~
VTE Terminal
~: Supported in a special way by the terminal. ## Todo - [x] Basic 16 color - [ ] Extra 240 color - [x] HSL support - [x] RGB support - [x] Gradient mode - [x] Rainbow mode - [x] Animation mode - [ ] Document - [x] Terminals compatibility ## License [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fda2018%2Fcolorful.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fda2018%2Fcolorful?ref=badge_large) colorful-0.2.2/license000064400000000000000000000020661046102023000130230ustar 00000000000000MIT License Copyright (c) da2018 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. colorful-0.2.2/rustfmt.toml000064400000000000000000000001711046102023000140520ustar 00000000000000max_width = 89 reorder_imports = true #wrap_comments = true fn_args_density = "Compressed" #use_small_heuristics = false colorful-0.2.2/src/core/color_string.rs000064400000000000000000000102351046102023000162440ustar 00000000000000use std::fmt::Display; use std::fmt::Formatter; use std::fmt::Result as FmtResult; use core::ColorInterface; use core::colors::Colorado; use core::colors::ColorMode; use core::StrMarker; use core::symbols::Symbol; use Style; // Support multiple style #[derive(Clone)] pub struct CString { text: String, fg_color: Option, bg_color: Option, styles: Option>, } impl StrMarker for CString { fn to_str(&self) -> String { self.text.to_owned() } fn get_fg_color(&self) -> Option { self.fg_color.clone() } fn get_bg_color(&self) -> Option { self.bg_color.clone() } fn get_style(&self) -> Option> { self.styles.clone() } } impl CString { pub fn new(cs: S) -> CString { CString { text: cs.to_str(), fg_color: cs.get_fg_color(), bg_color: cs.get_bg_color(), styles: cs.get_style(), } } pub fn create_by_text(cs: S, t: String) -> CString { CString { text: t, ..CString::new(cs) } } pub fn create_by_fg(cs: S, color: C) -> CString { CString { fg_color: Some(Colorado::new(color)), ..CString::new(cs) } } pub fn create_by_bg(cs: S, color: C) -> CString { CString { bg_color: Some(Colorado::new(color)), ..CString::new(cs) } } pub fn create_by_style(cs: S, style: Style) -> CString { CString { text: cs.to_str(), styles: match cs.get_style() { Some(mut v) => { v.push(style); Some(v) } _ => { Some(vec![style]) } }, fg_color: cs.get_fg_color(), bg_color: cs.get_bg_color(), } } } impl Display for CString { fn fmt(&self, f: &mut Formatter) -> FmtResult { let mut is_colored = false; if self.bg_color.is_none() && self.fg_color.is_none() && self.styles.is_none() { write!(f, "{}", self.text)?; Ok(()) } else { match &self.fg_color { Some(v) => { is_colored = true; match v.get_mode() { ColorMode::SIMPLE => { f.write_str(Symbol::Simple256Foreground.to_str())?; } ColorMode::RGB => { f.write_str(Symbol::RgbForeground.to_str())?; } _ => {} } write!(f, "{}", v.get_color())?; } _ => {} } match &self.bg_color { Some(v) => { if is_colored { f.write_str(Symbol::Mode.to_str())?; } else { is_colored = true; } match v.get_mode() { ColorMode::SIMPLE => { f.write_str(Symbol::Simple256Background.to_str())?; } ColorMode::RGB => { f.write_str(Symbol::RgbBackground.to_str())?; } _ => {} } write!(f, "{}", v.get_color())?; } _ => {} } match &self.styles { Some(v) => { if !is_colored { // pure style without color write!(f, "{}{}", Symbol::Esc, Symbol::LeftBrackets)?; } else { f.write_str(Symbol::Semicolon.to_str())?; } let t: Vec = v.into_iter().map(|x| x.to_string()).collect(); f.write_str(&t.join(";")[..])?; } _ => {} } f.write_str(Symbol::Mode.to_str())?; write!(f, "{}", self.text)?; f.write_str(Symbol::Reset.to_str())?; Ok(()) } } } colorful-0.2.2/src/core/colors.rs000064400000000000000000001124751046102023000150520ustar 00000000000000use std::slice::Iter; use core::ColorInterface; use HSL; #[derive(Copy, Clone, PartialEq, Eq, Debug)] pub enum Color { Black, Red, Green, Yellow, Blue, Magenta, Cyan, LightGray, DarkGray, LightRed, LightGreen, LightYellow, LightBlue, LightMagenta, LightCyan, White, Grey0, NavyBlue, DarkBlue, Blue3a, Blue3b, Blue1, DarkGreen, DeepSkyBlue4a, DeepSkyBlue4b, DeepSkyBlue4c, DodgerBlue3, DodgerBlue2, Green4, SpringGreen4, Turquoise4, DeepSkyBlue3a, DeepSkyBlue3b, DodgerBlue1, Green3a, SpringGreen3a, DarkCyan, LightSeaGreen, DeepSkyBlue2, DeepSkyBlue1, Green3b, SpringGreen3b, SpringGreen2a, Cyan3, DarkTurquoise, Turquoise2, Green1, SpringGreen2b, SpringGreen1, MediumSpringGreen, Cyan2, Cyan1, DarkRed1, DeepPink4a, Purple4a, Purple4b, Purple3, BlueViolet, Orange4a, Grey37, MediumPurple4, SlateBlue3a, SlateBlue3b, RoyalBlue1, Chartreuse4, DarkSeaGreen4a, PaleTurquoise4, SteelBlue, SteelBlue3, CornflowerBlue, Chartreuse3a, DarkSeaGreen4b, CadetBlue2, CadetBlue1, SkyBlue3, SteelBlue1a, Chartreuse3b, PaleGreen3a, SeaGreen3, Aquamarine3, MediumTurquoise, SteelBlue1b, Chartreuse2a, SeaGreen2, SeaGreen1a, SeaGreen1b, Aquamarine1a, DarkSlateGray2, DarkRed2, DeepPink4b, DarkMagenta1, DarkMagenta2, DarkViolet1a, Purple1a, Orange4b, LightPink4, Plum4, MediumPurple3a, MediumPurple3b, SlateBlue1, Yellow4a, Wheat4, Grey53, LightSlateGrey, MediumPurple, LightSlateBlue, Yellow4b, DarkOliveGreen3a, DarkGreenSea, LightSkyBlue3a, LightSkyBlue3b, SkyBlue2, Chartreuse2b, DarkOliveGreen3b, PaleGreen3b, DarkSeaGreen3a, DarkSlateGray3, SkyBlue1, Chartreuse1, LightGreen2, LightGreen3, PaleGreen1a, Aquamarine1b, DarkSlateGray1, Red3a, DeepPink4c, MediumVioletRed, Magenta3a, DarkViolet1b, Purple1b, DarkOrange3a, IndianRed1a, HotPink3a, MediumOrchid3, MediumOrchid, MediumPurple2a, DarkGoldenrod, LightSalmon3a, RosyBrown, Grey63, MediumPurple2b, MediumPurple1, Gold3a, DarkKhaki, NavajoWhite3, Grey69, LightSteelBlue3, LightSteelBlue, Yellow3a, DarkOliveGreen3, DarkSeaGreen3b, DarkSeaGreen2, LightCyan3, LightSkyBlue1, GreenYellow, DarkOliveGreen2, PaleGreen1b, DarkSeaGreen5b, DarkSeaGreen5a, PaleTurquoise1, Red3b, DeepPink3a, DeepPink3b, Magenta3b, Magenta3c, Magenta2a, DarkOrange3b, IndianRed1b, HotPink3b, HotPink2, Orchid, MediumOrchid1a, Orange3, LightSalmon3b, LightPink3, Pink3, Plum3, Violet, Gold3b, LightGoldenrod3, Tan, MistyRose3, Thistle3, Plum2, Yellow3b, Khaki3, LightGoldenrod2a, LightYellow3, Grey84, LightSteelBlue1, Yellow2, DarkOliveGreen1a, DarkOliveGreen1b, DarkSeaGreen1, Honeydew2, LightCyan1, Red1, DeepPink2, DeepPink1a, DeepPink1b, Magenta2b, Magenta1, OrangeRed1, IndianRed1c, IndianRed1d, HotPink1a, HotPink1b, MediumOrchid1b, DarkOrange, Salmon1, LightCoral, PaleVioletRed1, Orchid2, Orchid1, Orange1, SandyBrown, LightSalmon1, LightPink1, Pink1, Plum1, Gold1, LightGoldenrod2b, LightGoldenrod2c, NavajoWhite1, MistyRose1, Thistle1, Yellow1, LightGoldenrod1, Khaki1, Wheat1, CornSilk1, Grey100, Grey3, Grey7, Grey11, Grey15, Grey19, Grey23, Grey27, Grey30, Grey35, Grey39, Grey42, Grey46, Grey50, Grey54, Grey58, Grey62, Grey66, Grey70, Grey74, Grey78, Grey82, Grey85, Grey89, Grey93, } impl ColorInterface for Color { fn to_color_str(&self) -> String { format!("{}", match self { Color::Black => "0", Color::Red => "1", Color::Green => "2", Color::Yellow => "3", Color::Blue => "4", Color::Magenta => "5", Color::Cyan => "6", Color::LightGray => "7", Color::DarkGray => "8", Color::LightRed => "9", Color::LightGreen => "10", Color::LightYellow => "11", Color::LightBlue => "12", Color::LightMagenta => "13", Color::LightCyan => "14", Color::White => "15", Color::Grey0 => "16", Color::NavyBlue => "17", Color::DarkBlue => "18", Color::Blue3a => "19", Color::Blue3b => "20", Color::Blue1 => "21", Color::DarkGreen => "22", Color::DeepSkyBlue4a => "23", Color::DeepSkyBlue4b => "24", Color::DeepSkyBlue4c => "25", Color::DodgerBlue3 => "26", Color::DodgerBlue2 => "27", Color::Green4 => "28", Color::SpringGreen4 => "29", Color::Turquoise4 => "30", Color::DeepSkyBlue3a => "31", Color::DeepSkyBlue3b => "32", Color::DodgerBlue1 => "33", Color::Green3a => "34", Color::SpringGreen3a => "35", Color::DarkCyan => "36", Color::LightSeaGreen => "37", Color::DeepSkyBlue2 => "38", Color::DeepSkyBlue1 => "39", Color::Green3b => "40", Color::SpringGreen3b => "41", Color::SpringGreen2a => "42", Color::Cyan3 => "43", Color::DarkTurquoise => "44", Color::Turquoise2 => "45", Color::Green1 => "46", Color::SpringGreen2b => "47", Color::SpringGreen1 => "48", Color::MediumSpringGreen => "49", Color::Cyan2 => "50", Color::Cyan1 => "51", Color::DarkRed1 => "52", Color::DeepPink4a => "53", Color::Purple4a => "54", Color::Purple4b => "55", Color::Purple3 => "56", Color::BlueViolet => "57", Color::Orange4a => "58", Color::Grey37 => "59", Color::MediumPurple4 => "60", Color::SlateBlue3a => "61", Color::SlateBlue3b => "62", Color::RoyalBlue1 => "63", Color::Chartreuse4 => "64", Color::DarkSeaGreen4a => "65", Color::PaleTurquoise4 => "66", Color::SteelBlue => "67", Color::SteelBlue3 => "68", Color::CornflowerBlue => "69", Color::Chartreuse3a => "70", Color::DarkSeaGreen4b => "71", Color::CadetBlue2 => "72", Color::CadetBlue1 => "73", Color::SkyBlue3 => "74", Color::SteelBlue1a => "75", Color::Chartreuse3b => "76", Color::PaleGreen3a => "77", Color::SeaGreen3 => "78", Color::Aquamarine3 => "79", Color::MediumTurquoise => "80", Color::SteelBlue1b => "81", Color::Chartreuse2a => "82", Color::SeaGreen2 => "83", Color::SeaGreen1a => "84", Color::SeaGreen1b => "85", Color::Aquamarine1a => "86", Color::DarkSlateGray2 => "87", Color::DarkRed2 => "88", Color::DeepPink4b => "89", Color::DarkMagenta1 => "90", Color::DarkMagenta2 => "91", Color::DarkViolet1a => "92", Color::Purple1a => "93", Color::Orange4b => "94", Color::LightPink4 => "95", Color::Plum4 => "96", Color::MediumPurple3a => "97", Color::MediumPurple3b => "98", Color::SlateBlue1 => "99", Color::Yellow4a => "100", Color::Wheat4 => "101", Color::Grey53 => "102", Color::LightSlateGrey => "103", Color::MediumPurple => "104", Color::LightSlateBlue => "105", Color::Yellow4b => "106", Color::DarkOliveGreen3a => "107", Color::DarkGreenSea => "108", Color::LightSkyBlue3a => "109", Color::LightSkyBlue3b => "110", Color::SkyBlue2 => "111", Color::Chartreuse2b => "112", Color::DarkOliveGreen3b => "113", Color::PaleGreen3b => "114", Color::DarkSeaGreen3a => "115", Color::DarkSlateGray3 => "116", Color::SkyBlue1 => "117", Color::Chartreuse1 => "118", Color::LightGreen2 => "119", Color::LightGreen3 => "120", Color::PaleGreen1a => "121", Color::Aquamarine1b => "122", Color::DarkSlateGray1 => "123", Color::Red3a => "124", Color::DeepPink4c => "125", Color::MediumVioletRed => "126", Color::Magenta3a => "127", Color::DarkViolet1b => "128", Color::Purple1b => "129", Color::DarkOrange3a => "130", Color::IndianRed1a => "131", Color::HotPink3a => "132", Color::MediumOrchid3 => "133", Color::MediumOrchid => "134", Color::MediumPurple2a => "135", Color::DarkGoldenrod => "136", Color::LightSalmon3a => "137", Color::RosyBrown => "138", Color::Grey63 => "139", Color::MediumPurple2b => "140", Color::MediumPurple1 => "141", Color::Gold3a => "142", Color::DarkKhaki => "143", Color::NavajoWhite3 => "144", Color::Grey69 => "145", Color::LightSteelBlue3 => "146", Color::LightSteelBlue => "147", Color::Yellow3a => "148", Color::DarkOliveGreen3 => "149", Color::DarkSeaGreen3b => "150", Color::DarkSeaGreen2 => "151", Color::LightCyan3 => "152", Color::LightSkyBlue1 => "153", Color::GreenYellow => "154", Color::DarkOliveGreen2 => "155", Color::PaleGreen1b => "156", Color::DarkSeaGreen5b => "157", Color::DarkSeaGreen5a => "158", Color::PaleTurquoise1 => "159", Color::Red3b => "160", Color::DeepPink3a => "161", Color::DeepPink3b => "162", Color::Magenta3b => "163", Color::Magenta3c => "164", Color::Magenta2a => "165", Color::DarkOrange3b => "166", Color::IndianRed1b => "167", Color::HotPink3b => "168", Color::HotPink2 => "169", Color::Orchid => "170", Color::MediumOrchid1a => "171", Color::Orange3 => "172", Color::LightSalmon3b => "173", Color::LightPink3 => "174", Color::Pink3 => "175", Color::Plum3 => "176", Color::Violet => "177", Color::Gold3b => "178", Color::LightGoldenrod3 => "179", Color::Tan => "180", Color::MistyRose3 => "181", Color::Thistle3 => "182", Color::Plum2 => "183", Color::Yellow3b => "184", Color::Khaki3 => "185", Color::LightGoldenrod2a => "186", Color::LightYellow3 => "187", Color::Grey84 => "188", Color::LightSteelBlue1 => "189", Color::Yellow2 => "190", Color::DarkOliveGreen1a => "191", Color::DarkOliveGreen1b => "192", Color::DarkSeaGreen1 => "193", Color::Honeydew2 => "194", Color::LightCyan1 => "195", Color::Red1 => "196", Color::DeepPink2 => "197", Color::DeepPink1a => "198", Color::DeepPink1b => "199", Color::Magenta2b => "200", Color::Magenta1 => "201", Color::OrangeRed1 => "202", Color::IndianRed1c => "203", Color::IndianRed1d => "204", Color::HotPink1a => "205", Color::HotPink1b => "206", Color::MediumOrchid1b => "207", Color::DarkOrange => "208", Color::Salmon1 => "209", Color::LightCoral => "210", Color::PaleVioletRed1 => "211", Color::Orchid2 => "212", Color::Orchid1 => "213", Color::Orange1 => "214", Color::SandyBrown => "215", Color::LightSalmon1 => "216", Color::LightPink1 => "217", Color::Pink1 => "218", Color::Plum1 => "219", Color::Gold1 => "220", Color::LightGoldenrod2b => "221", Color::LightGoldenrod2c => "222", Color::NavajoWhite1 => "223", Color::MistyRose1 => "224", Color::Thistle1 => "225", Color::Yellow1 => "226", Color::LightGoldenrod1 => "227", Color::Khaki1 => "228", Color::Wheat1 => "229", Color::CornSilk1 => "230", Color::Grey100 => "231", Color::Grey3 => "232", Color::Grey7 => "233", Color::Grey11 => "234", Color::Grey15 => "235", Color::Grey19 => "236", Color::Grey23 => "237", Color::Grey27 => "238", Color::Grey30 => "239", Color::Grey35 => "240", Color::Grey39 => "241", Color::Grey42 => "242", Color::Grey46 => "243", Color::Grey50 => "244", Color::Grey54 => "245", Color::Grey58 => "246", Color::Grey62 => "247", Color::Grey66 => "248", Color::Grey70 => "249", Color::Grey74 => "250", Color::Grey78 => "251", Color::Grey82 => "252", Color::Grey85 => "253", Color::Grey89 => "254", Color::Grey93 => "255", } ) } fn to_hsl(&self) -> HSL { match self { Color::Black => HSL::new(0.0, 0.0, 0.0), Color::Red => HSL::new(0.0, 1.0, 0.25), Color::Green => HSL::new(0.3333333333333333, 1.0, 0.25), Color::Yellow => HSL::new(0.16666666666666666, 1.0, 0.25), Color::Blue => HSL::new(0.6666666666666666, 1.0, 0.25), Color::Magenta => HSL::new(0.8333333333333334, 1.0, 0.25), Color::Cyan => HSL::new(0.5, 1.0, 0.25), Color::LightGray => HSL::new(0.0, 0.0, 0.75), Color::DarkGray => HSL::new(0.0, 0.0, 0.5), Color::LightRed => HSL::new(0.0, 1.0, 0.5), Color::LightGreen => HSL::new(0.3333333333333333, 1.0, 0.5), Color::LightYellow => HSL::new(0.16666666666666666, 1.0, 0.5), Color::LightBlue => HSL::new(0.6666666666666666, 1.0, 0.5), Color::LightMagenta => HSL::new(0.8333333333333334, 1.0, 0.5), Color::LightCyan => HSL::new(0.5, 1.0, 0.5), Color::White => HSL::new(0.0, 0.0, 1.0), Color::Grey0 => HSL::new(0.0, 0.0, 0.0), Color::NavyBlue => HSL::new(0.6666666666666666, 1.0, 0.18), Color::DarkBlue => HSL::new(0.6666666666666666, 1.0, 0.26), Color::Blue3a => HSL::new(0.6666666666666666, 1.0, 0.34), Color::Blue3b => HSL::new(0.6666666666666666, 1.0, 0.42), Color::Blue1 => HSL::new(0.6666666666666666, 1.0, 0.5), Color::DarkGreen => HSL::new(0.3333333333333333, 1.0, 0.18), Color::DeepSkyBlue4a => HSL::new(0.5, 1.0, 0.18), Color::DeepSkyBlue4b => HSL::new(0.5493827160493834, 1.0, 0.26), Color::DeepSkyBlue4c => HSL::new(0.5761904761904749, 1.0, 0.34), Color::DodgerBlue3 => HSL::new(0.5930232558139528, 1.0, 0.42), Color::DodgerBlue2 => HSL::new(0.6045751633986917, 1.0, 0.5), Color::Green4 => HSL::new(0.3333333333333333, 1.0, 0.26), Color::SpringGreen4 => HSL::new(0.4506172839506167, 1.0, 0.26), Color::Turquoise4 => HSL::new(0.5, 1.0, 0.26), Color::DeepSkyBlue3a => HSL::new(0.538095238095239, 1.0, 0.34), Color::DeepSkyBlue3b => HSL::new(0.5620155038759694, 1.0, 0.42), Color::DodgerBlue1 => HSL::new(0.5784313725490194, 1.0, 0.5), Color::Green3a => HSL::new(0.3333333333333333, 1.0, 0.34), Color::SpringGreen3a => HSL::new(0.423809523809525, 1.0, 0.34), Color::DarkCyan => HSL::new(0.4619047619047611, 1.0, 0.34), Color::LightSeaGreen => HSL::new(0.5, 1.0, 0.34), Color::DeepSkyBlue2 => HSL::new(0.5310077519379833, 1.0, 0.42), Color::DeepSkyBlue1 => HSL::new(0.5522875816993472, 1.0, 0.5), Color::Green3b => HSL::new(0.3333333333333333, 1.0, 0.42), Color::SpringGreen3b => HSL::new(0.40697674418604723, 1.0, 0.42), Color::SpringGreen2a => HSL::new(0.43798449612403056, 1.0, 0.42), Color::Cyan3 => HSL::new(0.4689922480620166, 1.0, 0.42), Color::DarkTurquoise => HSL::new(0.5, 1.0, 0.42), Color::Turquoise2 => HSL::new(0.5261437908496722, 1.0, 0.5), Color::Green1 => HSL::new(0.3333333333333333, 1.0, 0.5), Color::SpringGreen2b => HSL::new(0.39542483660130834, 1.0, 0.5), Color::SpringGreen1 => HSL::new(0.4215686274509806, 1.0, 0.5), Color::MediumSpringGreen => HSL::new(0.4477124183006528, 1.0, 0.5), Color::Cyan2 => HSL::new(0.4738562091503278, 1.0, 0.5), Color::Cyan1 => HSL::new(0.5, 1.0, 0.5), Color::DarkRed1 => HSL::new(0.0, 1.0, 0.18), Color::DeepPink4a => HSL::new(0.8333333333333334, 1.0, 0.18), Color::Purple4a => HSL::new(0.78395061728395, 1.0, 0.26), Color::Purple4b => HSL::new(0.7571428571428583, 1.0, 0.34), Color::Purple3 => HSL::new(0.7403100775193806, 1.0, 0.42), Color::BlueViolet => HSL::new(0.7287581699346417, 1.0, 0.5), Color::Orange4a => HSL::new(0.16666666666666666, 1.0, 0.18), Color::Grey37 => HSL::new(0.0, 0.0, 0.37), Color::MediumPurple4 => HSL::new(0.6666666666666666, 0.17, 0.45), Color::SlateBlue3a => HSL::new(0.6666666666666666, 0.33, 0.52), Color::SlateBlue3b => HSL::new(0.6666666666666666, 0.6, 0.6), Color::RoyalBlue1 => HSL::new(0.6666666666666666, 1.0, 0.68), Color::Chartreuse4 => HSL::new(0.21604938271604945, 1.0, 0.26), Color::DarkSeaGreen4a => HSL::new(0.3333333333333333, 0.17, 0.45), Color::PaleTurquoise4 => HSL::new(0.5, 0.17, 0.45), Color::SteelBlue => HSL::new(0.5833333333333334, 0.33, 0.52), Color::SteelBlue3 => HSL::new(0.6111111111111112, 0.6, 0.6), Color::CornflowerBlue => HSL::new(0.625, 1.0, 0.68), Color::Chartreuse3a => HSL::new(0.24285714285714277, 1.0, 0.34), Color::DarkSeaGreen4b => HSL::new(0.3333333333333333, 0.33, 0.52), Color::CadetBlue2 => HSL::new(0.4166666666666667, 0.33, 0.52), Color::CadetBlue1 => HSL::new(0.5, 0.33, 0.52), Color::SkyBlue3 => HSL::new(0.5555555555555556, 0.6, 0.6), Color::SteelBlue1a => HSL::new(0.5833333333333334, 1.0, 0.68), Color::Chartreuse3b => HSL::new(0.2596899224806203, 1.0, 0.42), Color::PaleGreen3a => HSL::new(0.3333333333333333, 0.6, 0.6), Color::SeaGreen3 => HSL::new(0.3888888888888889, 0.6, 0.6), Color::Aquamarine3 => HSL::new(0.4444444444444444, 0.6, 0.6), Color::MediumTurquoise => HSL::new(0.5, 0.6, 0.6), Color::SteelBlue1b => HSL::new(0.5416666666666666, 1.0, 0.68), Color::Chartreuse2a => HSL::new(0.27124183006535946, 1.0, 0.5), Color::SeaGreen2 => HSL::new(0.3333333333333333, 1.0, 0.68), Color::SeaGreen1a => HSL::new(0.375, 1.0, 0.68), Color::SeaGreen1b => HSL::new(0.4166666666666667, 1.0, 0.68), Color::Aquamarine1a => HSL::new(0.4583333333333333, 1.0, 0.68), Color::DarkSlateGray2 => HSL::new(0.5, 1.0, 0.68), Color::DarkRed2 => HSL::new(0.0, 1.0, 0.26), Color::DeepPink4b => HSL::new(0.8827160493827166, 1.0, 0.26), Color::DarkMagenta1 => HSL::new(0.8333333333333334, 1.0, 0.26), Color::DarkMagenta2 => HSL::new(0.7952380952380944, 1.0, 0.34), Color::DarkViolet1a => HSL::new(0.7713178294573639, 1.0, 0.42), Color::Purple1a => HSL::new(0.7549019607843138, 1.0, 0.5), Color::Orange4b => HSL::new(0.11728395061728389, 1.0, 0.26), Color::LightPink4 => HSL::new(0.0, 0.17, 0.45), Color::Plum4 => HSL::new(0.8333333333333334, 0.17, 0.45), Color::MediumPurple3a => HSL::new(0.75, 0.33, 0.52), Color::MediumPurple3b => HSL::new(0.7222222222222222, 0.6, 0.6), Color::SlateBlue1 => HSL::new(0.7083333333333334, 1.0, 0.68), Color::Yellow4a => HSL::new(0.16666666666666666, 1.0, 0.26), Color::Wheat4 => HSL::new(0.16666666666666666, 0.17, 0.45), Color::Grey53 => HSL::new(0.0, 0.0, 0.52), Color::LightSlateGrey => HSL::new(0.6666666666666666, 0.2, 0.6), Color::MediumPurple => HSL::new(0.6666666666666666, 0.5, 0.68), Color::LightSlateBlue => HSL::new(0.6666666666666666, 1.0, 0.76), Color::Yellow4b => HSL::new(0.2047619047619047, 1.0, 0.34), Color::DarkOliveGreen3a => HSL::new(0.25, 0.33, 0.52), Color::DarkGreenSea => HSL::new(0.3333333333333333, 0.2, 0.6), Color::LightSkyBlue3a => HSL::new(0.5, 0.2, 0.6), Color::LightSkyBlue3b => HSL::new(0.5833333333333334, 0.5, 0.68), Color::SkyBlue2 => HSL::new(0.6111111111111112, 1.0, 0.76), Color::Chartreuse2b => HSL::new(0.22868217054263557, 1.0, 0.42), Color::DarkOliveGreen3b => HSL::new(0.2777777777777778, 0.6, 0.6), Color::PaleGreen3b => HSL::new(0.3333333333333333, 0.5, 0.68), Color::DarkSeaGreen3a => HSL::new(0.4166666666666667, 0.5, 0.68), Color::DarkSlateGray3 => HSL::new(0.5, 0.5, 0.68), Color::SkyBlue1 => HSL::new(0.5555555555555556, 1.0, 0.76), Color::Chartreuse1 => HSL::new(0.2450980392156864, 1.0, 0.5), Color::LightGreen2 => HSL::new(0.2916666666666667, 1.0, 0.68), Color::LightGreen3 => HSL::new(0.3333333333333333, 1.0, 0.76), Color::PaleGreen1a => HSL::new(0.3888888888888889, 1.0, 0.76), Color::Aquamarine1b => HSL::new(0.4444444444444444, 1.0, 0.76), Color::DarkSlateGray1 => HSL::new(0.5, 1.0, 0.76), Color::Red3a => HSL::new(0.0, 1.0, 0.34), Color::DeepPink4c => HSL::new(0.9095238095238083, 1.0, 0.34), Color::MediumVioletRed => HSL::new(0.8714285714285722, 1.0, 0.34), Color::Magenta3a => HSL::new(0.8333333333333334, 1.0, 0.34), Color::DarkViolet1b => HSL::new(0.80232558139535, 1.0, 0.42), Color::Purple1b => HSL::new(0.7810457516339862, 1.0, 0.5), Color::DarkOrange3a => HSL::new(0.09047619047619054, 1.0, 0.34), Color::IndianRed1a => HSL::new(0.0, 0.33, 0.52), Color::HotPink3a => HSL::new(0.9166666666666666, 0.33, 0.52), Color::MediumOrchid3 => HSL::new(0.8333333333333334, 0.33, 0.52), Color::MediumOrchid => HSL::new(0.7777777777777778, 0.6, 0.6), Color::MediumPurple2a => HSL::new(0.75, 1.0, 0.68), Color::DarkGoldenrod => HSL::new(0.12857142857142861, 1.0, 0.34), Color::LightSalmon3a => HSL::new(0.08333333333333333, 0.33, 0.52), Color::RosyBrown => HSL::new(0.0, 0.2, 0.6), Color::Grey63 => HSL::new(0.8333333333333334, 0.2, 0.6), Color::MediumPurple2b => HSL::new(0.75, 0.5, 0.68), Color::MediumPurple1 => HSL::new(0.7222222222222222, 1.0, 0.76), Color::Gold3a => HSL::new(0.16666666666666666, 1.0, 0.34), Color::DarkKhaki => HSL::new(0.16666666666666666, 0.33, 0.52), Color::NavajoWhite3 => HSL::new(0.16666666666666666, 0.2, 0.6), Color::Grey69 => HSL::new(0.0, 0.0, 0.68), Color::LightSteelBlue3 => HSL::new(0.6666666666666666, 0.33, 0.76), Color::LightSteelBlue => HSL::new(0.6666666666666666, 1.0, 0.84), Color::Yellow3a => HSL::new(0.1976744186046511, 1.0, 0.42), Color::DarkOliveGreen3 => HSL::new(0.2222222222222222, 0.6, 0.6), Color::DarkSeaGreen3b => HSL::new(0.25, 0.5, 0.68), Color::DarkSeaGreen2 => HSL::new(0.3333333333333333, 0.33, 0.76), Color::LightCyan3 => HSL::new(0.5, 0.33, 0.76), Color::LightSkyBlue1 => HSL::new(0.5833333333333334, 1.0, 0.84), Color::GreenYellow => HSL::new(0.21895424836601304, 1.0, 0.5), Color::DarkOliveGreen2 => HSL::new(0.25, 1.0, 0.68), Color::PaleGreen1b => HSL::new(0.2777777777777778, 1.0, 0.76), Color::DarkSeaGreen5b => HSL::new(0.3333333333333333, 1.0, 0.84), Color::DarkSeaGreen5a => HSL::new(0.4166666666666667, 1.0, 0.84), Color::PaleTurquoise1 => HSL::new(0.5, 1.0, 0.84), Color::Red3b => HSL::new(0.0, 1.0, 0.42), Color::DeepPink3a => HSL::new(0.926356589147286, 1.0, 0.42), Color::DeepPink3b => HSL::new(0.8953488372093028, 1.0, 0.42), Color::Magenta3b => HSL::new(0.8643410852713166, 1.0, 0.42), Color::Magenta3c => HSL::new(0.8333333333333334, 1.0, 0.42), Color::Magenta2a => HSL::new(0.8071895424836611, 1.0, 0.5), Color::DarkOrange3b => HSL::new(0.07364341085271306, 1.0, 0.42), Color::IndianRed1b => HSL::new(0.0, 0.6, 0.6), Color::HotPink3b => HSL::new(0.9444444444444444, 0.6, 0.6), Color::HotPink2 => HSL::new(0.8888888888888888, 0.6, 0.6), Color::Orchid => HSL::new(0.8333333333333334, 0.6, 0.6), Color::MediumOrchid1a => HSL::new(0.7916666666666666, 1.0, 0.68), Color::Orange3 => HSL::new(0.10465116279069778, 1.0, 0.42), Color::LightSalmon3b => HSL::new(0.05555555555555555, 0.6, 0.6), Color::LightPink3 => HSL::new(0.0, 0.5, 0.68), Color::Pink3 => HSL::new(0.9166666666666666, 0.5, 0.68), Color::Plum3 => HSL::new(0.8333333333333334, 0.5, 0.68), Color::Violet => HSL::new(0.7777777777777778, 1.0, 0.76), Color::Gold3b => HSL::new(0.13565891472868222, 1.0, 0.42), Color::LightGoldenrod3 => HSL::new(0.1111111111111111, 0.6, 0.6), Color::Tan => HSL::new(0.08333333333333333, 0.5, 0.68), Color::MistyRose3 => HSL::new(0.0, 0.33, 0.76), Color::Thistle3 => HSL::new(0.8333333333333334, 0.33, 0.76), Color::Plum2 => HSL::new(0.75, 1.0, 0.84), Color::Yellow3b => HSL::new(0.16666666666666666, 1.0, 0.42), Color::Khaki3 => HSL::new(0.16666666666666666, 0.6, 0.6), Color::LightGoldenrod2a => HSL::new(0.16666666666666666, 0.5, 0.68), Color::LightYellow3 => HSL::new(0.16666666666666666, 0.33, 0.76), Color::Grey84 => HSL::new(0.0, 0.0, 0.84), Color::LightSteelBlue1 => HSL::new(0.6666666666666666, 1.0, 0.92), Color::Yellow2 => HSL::new(0.19281045751633974, 1.0, 0.5), Color::DarkOliveGreen1a => HSL::new(0.20833333333333334, 1.0, 0.68), Color::DarkOliveGreen1b => HSL::new(0.2222222222222222, 1.0, 0.76), Color::DarkSeaGreen1 => HSL::new(0.25, 1.0, 0.84), Color::Honeydew2 => HSL::new(0.3333333333333333, 1.0, 0.92), Color::LightCyan1 => HSL::new(0.5, 1.0, 0.92), Color::Red1 => HSL::new(0.0, 1.0, 0.5), Color::DeepPink2 => HSL::new(0.937908496732025, 1.0, 0.5), Color::DeepPink1a => HSL::new(0.9117647058823528, 1.0, 0.5), Color::DeepPink1b => HSL::new(0.8856209150326805, 1.0, 0.5), Color::Magenta2b => HSL::new(0.8594771241830055, 1.0, 0.5), Color::Magenta1 => HSL::new(0.8333333333333334, 1.0, 0.5), Color::OrangeRed1 => HSL::new(0.06209150326797389, 1.0, 0.5), Color::IndianRed1c => HSL::new(0.0, 1.0, 0.68), Color::IndianRed1d => HSL::new(0.9583333333333334, 1.0, 0.68), Color::HotPink1a => HSL::new(0.9166666666666666, 1.0, 0.68), Color::HotPink1b => HSL::new(0.875, 1.0, 0.68), Color::MediumOrchid1b => HSL::new(0.8333333333333334, 1.0, 0.68), Color::DarkOrange => HSL::new(0.08823529411764694, 1.0, 0.5), Color::Salmon1 => HSL::new(0.041666666666666664, 1.0, 0.68), Color::LightCoral => HSL::new(0.0, 1.0, 0.76), Color::PaleVioletRed1 => HSL::new(0.9444444444444444, 1.0, 0.76), Color::Orchid2 => HSL::new(0.8888888888888888, 1.0, 0.76), Color::Orchid1 => HSL::new(0.8333333333333334, 1.0, 0.76), Color::Orange1 => HSL::new(0.11437908496732027, 1.0, 0.5), Color::SandyBrown => HSL::new(0.08333333333333333, 1.0, 0.68), Color::LightSalmon1 => HSL::new(0.05555555555555555, 1.0, 0.76), Color::LightPink1 => HSL::new(0.0, 1.0, 0.84), Color::Pink1 => HSL::new(0.9166666666666666, 1.0, 0.84), Color::Plum1 => HSL::new(0.8333333333333334, 1.0, 0.84), Color::Gold1 => HSL::new(0.14052287581699335, 1.0, 0.5), Color::LightGoldenrod2b => HSL::new(0.125, 1.0, 0.68), Color::LightGoldenrod2c => HSL::new(0.1111111111111111, 1.0, 0.76), Color::NavajoWhite1 => HSL::new(0.08333333333333333, 1.0, 0.84), Color::MistyRose1 => HSL::new(0.0, 1.0, 0.92), Color::Thistle1 => HSL::new(0.8333333333333334, 1.0, 0.92), Color::Yellow1 => HSL::new(0.16666666666666666, 1.0, 0.5), Color::LightGoldenrod1 => HSL::new(0.16666666666666666, 1.0, 0.68), Color::Khaki1 => HSL::new(0.16666666666666666, 1.0, 0.76), Color::Wheat1 => HSL::new(0.16666666666666666, 1.0, 0.84), Color::CornSilk1 => HSL::new(0.16666666666666666, 1.0, 0.92), Color::Grey100 => HSL::new(0.0, 0.0, 1.0), Color::Grey3 => HSL::new(0.0, 0.0, 0.03), Color::Grey7 => HSL::new(0.0, 0.0, 0.07), Color::Grey11 => HSL::new(0.0, 0.0, 0.1), Color::Grey15 => HSL::new(0.0, 0.0, 0.14), Color::Grey19 => HSL::new(0.0, 0.0, 0.18), Color::Grey23 => HSL::new(0.0, 0.0, 0.22), Color::Grey27 => HSL::new(0.0, 0.0, 0.26), Color::Grey30 => HSL::new(0.0, 0.0, 0.3), Color::Grey35 => HSL::new(0.0, 0.0, 0.34), Color::Grey39 => HSL::new(0.0, 0.0, 0.37), Color::Grey42 => HSL::new(0.0, 0.0, 0.4), Color::Grey46 => HSL::new(0.0, 0.0, 0.46), Color::Grey50 => HSL::new(0.0, 0.0, 0.5), Color::Grey54 => HSL::new(0.0, 0.0, 0.54), Color::Grey58 => HSL::new(0.0, 0.0, 0.58), Color::Grey62 => HSL::new(0.0, 0.0, 0.61), Color::Grey66 => HSL::new(0.0, 0.0, 0.65), Color::Grey70 => HSL::new(0.0, 0.0, 0.69), Color::Grey74 => HSL::new(0.0, 0.0, 0.73), Color::Grey78 => HSL::new(0.0, 0.0, 0.77), Color::Grey82 => HSL::new(0.0, 0.0, 0.81), Color::Grey85 => HSL::new(0.0, 0.0, 0.85), Color::Grey89 => HSL::new(0.0, 0.0, 0.89), Color::Grey93 => HSL::new(0.0, 0.0, 0.93), } } } impl Color { pub fn iterator() -> Iter<'static, Color> { use Color::*; static ITEMS: [Color; 256] = [Black, Red, Green, Yellow, Blue, Magenta, Cyan, LightGray, DarkGray, LightRed, LightGreen, LightYellow, LightBlue, LightMagenta, LightCyan, White, Grey0, NavyBlue, DarkBlue, Blue3a, Blue3b, Blue1, DarkGreen, DeepSkyBlue4a, DeepSkyBlue4b, DeepSkyBlue4c, DodgerBlue3, DodgerBlue2, Green4, SpringGreen4, Turquoise4, DeepSkyBlue3a, DeepSkyBlue3b, DodgerBlue1, Green3a, SpringGreen3a, DarkCyan, LightSeaGreen, DeepSkyBlue2, DeepSkyBlue1, Green3b, SpringGreen3b, SpringGreen2a, Cyan3, DarkTurquoise, Turquoise2, Green1, SpringGreen2b, SpringGreen1, MediumSpringGreen, Cyan2, Cyan1, DarkRed1, DeepPink4a, Purple4a, Purple4b, Purple3, BlueViolet, Orange4a, Grey37, MediumPurple4, SlateBlue3a, SlateBlue3b, RoyalBlue1, Chartreuse4, DarkSeaGreen4a, PaleTurquoise4, SteelBlue, SteelBlue3, CornflowerBlue, Chartreuse3a, DarkSeaGreen4b, CadetBlue2, CadetBlue1, SkyBlue3, SteelBlue1a, Chartreuse3b, PaleGreen3a, SeaGreen3, Aquamarine3, MediumTurquoise, SteelBlue1b, Chartreuse2a, SeaGreen2, SeaGreen1a, SeaGreen1b, Aquamarine1a, DarkSlateGray2, DarkRed2, DeepPink4b, DarkMagenta1, DarkMagenta2, DarkViolet1a, Purple1a, Orange4b, LightPink4, Plum4, MediumPurple3a, MediumPurple3b, SlateBlue1, Yellow4a, Wheat4, Grey53, LightSlateGrey, MediumPurple, LightSlateBlue, Yellow4b, DarkOliveGreen3a, DarkGreenSea, LightSkyBlue3a, LightSkyBlue3b, SkyBlue2, Chartreuse2b, DarkOliveGreen3b, PaleGreen3b, DarkSeaGreen3a, DarkSlateGray3, SkyBlue1, Chartreuse1, LightGreen2, LightGreen3, PaleGreen1a, Aquamarine1b, DarkSlateGray1, Red3a, DeepPink4c, MediumVioletRed, Magenta3a, DarkViolet1b, Purple1b, DarkOrange3a, IndianRed1a, HotPink3a, MediumOrchid3, MediumOrchid, MediumPurple2a, DarkGoldenrod, LightSalmon3a, RosyBrown, Grey63, MediumPurple2b, MediumPurple1, Gold3a, DarkKhaki, NavajoWhite3, Grey69, LightSteelBlue3, LightSteelBlue, Yellow3a, DarkOliveGreen3, DarkSeaGreen3b, DarkSeaGreen2, LightCyan3, LightSkyBlue1, GreenYellow, DarkOliveGreen2, PaleGreen1b, DarkSeaGreen5b, DarkSeaGreen5a, PaleTurquoise1, Red3b, DeepPink3a, DeepPink3b, Magenta3b, Magenta3c, Magenta2a, DarkOrange3b, IndianRed1b, HotPink3b, HotPink2, Orchid, MediumOrchid1a, Orange3, LightSalmon3b, LightPink3, Pink3, Plum3, Violet, Gold3b, LightGoldenrod3, Tan, MistyRose3, Thistle3, Plum2, Yellow3b, Khaki3, LightGoldenrod2a, LightYellow3, Grey84, LightSteelBlue1, Yellow2, DarkOliveGreen1a, DarkOliveGreen1b, DarkSeaGreen1, Honeydew2, LightCyan1, Red1, DeepPink2, DeepPink1a, DeepPink1b, Magenta2b, Magenta1, OrangeRed1, IndianRed1c, IndianRed1d, HotPink1a, HotPink1b, MediumOrchid1b, DarkOrange, Salmon1, LightCoral, PaleVioletRed1, Orchid2, Orchid1, Orange1, SandyBrown, LightSalmon1, LightPink1, Pink1, Plum1, Gold1, LightGoldenrod2b, LightGoldenrod2c, NavajoWhite1, MistyRose1, Thistle1, Yellow1, LightGoldenrod1, Khaki1, Wheat1, CornSilk1, Grey100, Grey3, Grey7, Grey11, Grey15, Grey19, Grey23, Grey27, Grey30, Grey35, Grey39, Grey42, Grey46, Grey50, Grey54, Grey58, Grey62, Grey66, Grey70, Grey74, Grey78, Grey82, Grey85, Grey89, Grey93]; ITEMS.iter() } } #[derive(Copy, Clone)] pub enum ColorMode { SIMPLE, RGB, HSL, } #[derive(Clone)] pub struct Colorado { mode: ColorMode, color: String, } impl Default for Colorado { fn default() -> Colorado { Colorado { mode: ColorMode::SIMPLE, color: String::default(), } } } impl Colorado { pub fn new(color: C) -> Colorado { let c = format!("{}", color.to_color_str()); Colorado { color: c.clone(), mode: if c.contains(";") { ColorMode::RGB } else { ColorMode::SIMPLE }, } } pub fn get_color(&self) -> String { self.color.clone() } pub fn get_mode(&self) -> ColorMode { self.mode } } #[cfg(test)] mod tests { use super::*; #[test] fn test_rgb_iterator() { for _ in Color::iterator() {} } }colorful-0.2.2/src/core/hsl.rs000064400000000000000000000046041046102023000143310ustar 00000000000000use core::ColorInterface; use core::rgb::RGB; #[derive(Debug, Copy, Clone, PartialEq)] pub struct HSL { // range 0 ≤ H < 1.0, 0 ≤ S ≤ 1.0 and 0 ≤ L ≤ 1.0: pub h: f32, s: f32, l: f32, } impl HSL { pub fn new(h: f32, s: f32, l: f32) -> HSL { HSL { h: _round(h), s: _round(s), l: _round(l) } } pub fn hsl_to_rgb(&self) -> RGB { let red: f32; let green: f32; let blue: f32; let var_1: f32; let var_2: f32; if self.s == 0.0 { let tmp = self.l * 255.0; red = tmp; green = tmp; blue = tmp; } else { if self.l < 0.5 { var_2 = self.l * (1.0 + self.s); } else { var_2 = (self.l + self.s) - (self.s * self.l); } var_1 = 2.0 * self.l - var_2; red = 255.0 * hue_2_rgb(var_1, var_2, &mut (self.h + (1.0 / 3.0))); green = 255.0 * hue_2_rgb(var_1, var_2, &mut self.h.clone()); blue = 255.0 * hue_2_rgb(var_1, var_2, &mut (self.h - (1.0 / 3.0))); } RGB::new(red.round() as u8, green.round() as u8, blue.round() as u8) } } impl ColorInterface for HSL { fn to_color_str(&self) -> String { self.hsl_to_rgb().to_color_str() } fn to_hsl(&self) -> HSL { *self } } fn hue_2_rgb(v1: f32, v2: f32, vh: &mut f32) -> f32 { if *vh < 0.0 { *vh += 1.0; } if *vh > 1.0 { *vh -= 1.0; } if 6.0 * *vh < 1.0 { return v1 + (v2 - v1) * 6.0 * *vh; } if 2.0 * *vh < 1.0 { return v2; } if 3.0 * *vh < 2.0 { return v1 + (v2 - v1) * (2.0 / 3.0 - *vh) * 6.0; } v1 } fn _round(value: f32) -> f32 { if value < 0.0 { 0.0 } else if value >= 1.0 { 1.0 } else { value } } #[cfg(test)] mod tests { use super::*; #[test] fn test_hsl_2_rgb_1() { let hsl = HSL::new(0.7, 0.50, 0.60); let rgb = RGB::new(122, 102, 204); assert_eq!(rgb, hsl.hsl_to_rgb()); } #[test] fn test_hsl_2_rgb_2() { let hsl = HSL::new(0.7, 0.0, 0.60); let rgb = RGB::new(153, 153, 153); assert_eq!(rgb, hsl.hsl_to_rgb()); } #[test] fn test_hsl_2_rgb_3() { let hsl = HSL::new(0.7, 0.50, 0.30); let rgb = RGB::new(54, 38, 115); assert_eq!(rgb, hsl.hsl_to_rgb()); } }colorful-0.2.2/src/core/mod.rs000064400000000000000000000014201046102023000143130ustar 00000000000000use core::colors::Colorado; use core::style::Style; use HSL; pub mod colors; pub mod symbols; pub mod style; pub mod color_string; pub mod rgb; pub mod hsl; pub trait StrMarker { fn to_str(&self) -> String; fn get_fg_color(&self) -> Option { None } fn get_bg_color(&self) -> Option { None } fn get_style(&self) -> Option> { None } } impl<'a> StrMarker for &'a str { fn to_str(&self) -> String { String::from(*self) } } impl StrMarker for String { fn to_str(&self) -> String { self.clone() } } /// `ColorInterface` is for basic trait for `Colorful`, `RGB`, `HSL` and `Color` implement this trait. pub trait ColorInterface: Clone { fn to_color_str(&self) -> String; fn to_hsl(&self) -> HSL; } colorful-0.2.2/src/core/rgb.rs000064400000000000000000000040451046102023000143140ustar 00000000000000use core::ColorInterface; use HSL; #[derive(Debug, Copy, Clone, PartialEq)] pub struct RGB { // range 0 -255 r: u8, g: u8, b: u8, } impl RGB { pub fn new(r: u8, g: u8, b: u8) -> RGB { RGB { r, g, b } } pub fn unpack(&self) -> (u8, u8, u8) { (self.r, self.g, self.b) } pub fn rgb_to_hsl(&self) -> HSL { let (r, g, b) = self.unpack(); let r = r as f32 / 255.0; let g = g as f32 / 255.0; let b = b as f32 / 255.0; let max = r.max(g).max(b); let min = r.min(g).min(b); let mut h: f32 = 0.0; let mut s: f32 = 0.0; let l = (max + min) / 2.0; if max != min { let d = max - min; s = if l > 0.5 { d / (2.0 - max - min) } else { d / (max + min) }; if max == r { h = (g - b) / d + (if g < b { 6.0 } else { 0.0 }); } else if max == g { h = (b - r) / d + 2.0; } else { h = (r - g) / d + 4.0; } h /= 6.0; } return HSL::new(h, s, l); } } impl ColorInterface for RGB { fn to_color_str(&self) -> String { format!("{};{};{}", self.r, self.g, self.b) } fn to_hsl(&self) -> HSL { self.rgb_to_hsl() } } #[cfg(test)] mod tests { use super::*; #[test] fn test_rgb_2_hsl_1() { let hsl = HSL::new(0.69934636, 0.49999997, 0.60); let rgb = RGB::new(122, 102, 204); assert_eq!(hsl, rgb.rgb_to_hsl()); } #[test] fn test_rgb_2_hsl_2() { let hsl = HSL::new(0.0, 0.0, 0.60); let rgb = RGB::new(153, 153, 153); assert_eq!(hsl, rgb.rgb_to_hsl()); } #[test] fn test_rgb_2_hsl_3() { let hsl = HSL::new(0.7012987, 0.50326794, 0.30); let rgb = RGB::new(54, 38, 115); assert_eq!(hsl, rgb.rgb_to_hsl()); } #[test] fn test_rgb_2_hsl_4() { let hsl = HSL::new(0.08333334, 1.0, 0.6862745); let rgb = RGB::new(255, 175, 95); assert_eq!(hsl, rgb.rgb_to_hsl()); } }colorful-0.2.2/src/core/style.rs000064400000000000000000000011221046102023000146730ustar 00000000000000#[derive(Copy, Clone, PartialEq, Eq, Debug)] pub enum Style { Bold, Dim, Underlined, Blink, // invert the foreground and background colors Reverse, // useful for passwords Hidden, } impl Style { pub fn to_string(&self) -> String { match self { Style::Bold => String::from("1"), Style::Dim => String::from("2"), Style::Underlined => String::from("4"), Style::Blink => String::from("5"), Style::Reverse => String::from("7"), Style::Hidden => String::from("8"), } } } colorful-0.2.2/src/core/symbols.rs000064400000000000000000000030461046102023000152320ustar 00000000000000use std::fmt::Display; use std::fmt::Formatter; use std::fmt::Result as FmtResult; pub enum Symbol { Mode, Semicolon, LeftBrackets, Esc, Reset, Simple256Foreground, Simple256Background, RgbForeground, RgbBackground, ResetStyle, ResetForeground, ResetBackground, ClearScreenFromCursorToEnd, ClearScreenUpToCursor, ClearEntireScreen, ClearLineFromCursorToEnd, ClearLineUpToCursor, ClearEntireLine } impl Symbol { pub fn to_str<'a>(&self) -> &'a str { match self { Symbol::Mode => "m", Symbol::Semicolon => ";", Symbol::LeftBrackets => "[", Symbol::Esc => "\x1B", Symbol::Reset => "\x1B[0m", Symbol::Simple256Foreground => "\x1B[38;5;", Symbol::Simple256Background => "\x1B[48;5;", Symbol::RgbForeground => "\x1B[38;2;", Symbol::RgbBackground => "\x1B[48;2;", Symbol::ResetStyle => "\x1B[20m", Symbol::ResetForeground => "\x1B[39m", Symbol::ResetBackground => "\x1B[49m", Symbol::ClearScreenFromCursorToEnd => "\x1B[0J", Symbol::ClearScreenUpToCursor => "\x1B[1J", Symbol::ClearEntireScreen => "\x1B[2J", Symbol::ClearLineFromCursorToEnd => "\x1B[0K", Symbol::ClearLineUpToCursor => "\x1B[1K", Symbol::ClearEntireLine => "\x1B[2K", } } } impl Display for Symbol { fn fmt(&self, f: &mut Formatter) -> FmtResult { write!(f, "{}", self.to_str()) } }colorful-0.2.2/src/lib.rs000064400000000000000000000337251046102023000133670ustar 00000000000000//! Colored your terminal. //! You can use this package to make your string colorful in terminal. //! Platform support: //! - Linux //! - macOS //! /// It is recommended to use `Color` enum item to set foreground color not literal string. /// Literal string makes program uncontrollable, you can use `Color` `RGB::new(1,1,1)` or `HSL::new(0.5,0.5,0.5)` /// to create color and pass the variable to method. /// # Examples /// ``` /// extern crate colorful; /// /// use colorful::Colorful; /// use colorful::Color; /// /// fn main(){ /// let s = "Hello world"; /// println!("{}",s.color(Color::Red).bg_color(Color::Yellow).bold().to_string()); /// } /// ``` use std::{thread, time}; use core::color_string::CString; use core::ColorInterface; pub use core::colors::Color; pub use core::hsl::HSL; pub use core::rgb::RGB; use core::StrMarker; pub use core::style::Style; pub mod core; /// Support `&str` and `String`, you can use `"text".red()` and `s.red()` for s:String pub trait Colorful { /// Set foreground color. Support Color enum and HSL, RGB mode. /// ```Rust /// extern crate colorful; /// /// use colorful::Colorful; /// use colorful::Color; /// /// fn main() { /// let a = "Hello world"; /// println!("{}", a.color(Color::Red)); /// println!("{}", a.blue()); /// let b = String::from("Hello world"); /// println!("{}", b.blue()); /// } /// ``` fn color(self, color: C) -> CString; fn black(self) -> CString; fn red(self) -> CString; fn green(self) -> CString; fn yellow(self) -> CString; fn blue(self) -> CString; fn magenta(self) -> CString; fn cyan(self) -> CString; fn light_gray(self) -> CString; fn dark_gray(self) -> CString; fn light_red(self) -> CString; fn light_green(self) -> CString; fn light_yellow(self) -> CString; fn light_blue(self) -> CString; fn light_magenta(self) -> CString; fn light_cyan(self) -> CString; fn white(self) -> CString; /// Set background color. Support Color enum and HSL, RGB mode. /// ```Rust /// extern crate colorful; /// /// use colorful::Colorful; /// use colorful::Color; /// /// fn main() { /// let a = "Hello world"; /// println!("{}", a.bg_color(Color::Red)); /// } /// ``` fn bg_color(self, color: C) -> CString; fn bg_black(self) -> CString; fn bg_red(self) -> CString; fn bg_green(self) -> CString; fn bg_yellow(self) -> CString; fn bg_blue(self) -> CString; fn bg_magenta(self) -> CString; fn bg_cyan(self) -> CString; fn bg_light_gray(self) -> CString; fn bg_dark_gray(self) -> CString; fn bg_light_red(self) -> CString; fn bg_light_green(self) -> CString; fn bg_light_yellow(self) -> CString; fn bg_light_blue(self) -> CString; fn bg_light_magenta(self) -> CString; fn bg_light_cyan(self) -> CString; fn bg_white(self) -> CString; /// Support RGB color and HSL mode /// ```Rust /// extern crate colorful; /// /// use colorful::Colorful; /// /// fn main() { /// let a = "Hello world"; /// println!("{}", a.rgb(100, 100, 100).bg_rgb(100, 100, 100); /// println!("{}", a.hsl(0.5, 0.5, 0.5)).bg_hsl(0.5, 0.5, 0.5)); /// } /// ``` fn rgb(self, r: u8, g: u8, b: u8) -> CString; fn bg_rgb(self, r: u8, g: u8, b: u8) -> CString; fn hsl(self, h: f32, s: f32, l: f32) -> CString; fn bg_hsl(self, h: f32, s: f32, l: f32) -> CString; /// Terminal effect /// See [ANSI escape code](https://en.wikipedia.org/wiki/ANSI_escape_code) /// For terminals compatibility, check [Terminals compatibility](https://github.com/rocketsman/colorful#terminals-compatibility) fn style(self, style: Style) -> CString; /// Turn bold mode on. fn bold(self) -> CString; /// Turn blinking mode on. Blink doesn't work in many terminal emulators ,and it will still work on the console. fn blink(self) -> CString; /// Turn low intensity mode on. fn dim(self) -> CString; /// Turn underline mode on. fn underlined(self) -> CString; /// Turn reverse mode on (invert the foreground and background colors). fn reverse(self) -> CString; /// Turn invisible text mode on (useful for passwords). fn hidden(self) -> CString; /// Apply gradient color to sentences, support multiple lines. /// You can use `use colorful::Color;` or `use colorful::HSL;` or `use colorful::RGB;` /// to import colors and create gradient string. /// ```Rust /// extern crate colorful; /// /// use colorful::Color; /// use colorful::Colorful; /// /// fn main() { /// println!("{}", "This code is editable and runnable!".gradient(Color::Red)); /// println!("{}", "¡Este código es editable y ejecutable!".gradient(Color::Green)); /// println!("{}", "Ce code est modifiable et exécutable !".gradient(Color::Yellow)); /// println!("{}", "Questo codice è modificabile ed eseguibile!".gradient(Color::Blue)); /// println!("{}", "このコードは編集して実行出来ます!".gradient(Color::Magenta)); /// println!("{}", "여기에서 코드를 수정하고 실행할 수 있습니다!".gradient(Color::Cyan)); /// println!("{}", "Ten kod można edytować oraz uruchomić!".gradient(Color::LightGray)); /// println!("{}", "Este código é editável e executável!".gradient(Color::DarkGray)); /// println!("{}", "Этот код можно отредактировать и запустить!".gradient(Color::LightRed)); /// println!("{}", "Bạn có thể edit và run code trực tiếp!".gradient(Color::LightGreen)); /// println!("{}", "这段代码是可以编辑并且能够运行的!".gradient(Color::LightYellow)); /// println!("{}", "Dieser Code kann bearbeitet und ausgeführt werden!".gradient(Color::LightBlue)); /// println!("{}", "Den här koden kan redigeras och köras!".gradient(Color::LightMagenta)); /// println!("{}", "Tento kód můžete upravit a spustit".gradient(Color::LightCyan)); /// println!("{}", "این کد قابلیت ویرایش و اجرا دارد!".gradient(Color::White)); /// println!("{}", "โค้ดนี้สามารถแก้ไขได้และรันได้".gradient(Color::Grey0)); /// } /// ``` /// fn gradient_with_step(self, color: C, step: f32) -> CString; fn gradient_with_color(self, start: C, stop: C) -> CString; fn gradient(self, color: C) -> CString; fn rainbow_with_speed(self, speed: i32); /// Rainbow mode, support multiple lines /// fn rainbow(self); fn neon_with_speed(self, low: C, high: C, speed: i32); /// Neon mode fn neon(self, low: C, high: C); /// Show some warning words. /// fn warn(self); } impl Colorful for T where T: StrMarker { fn color(self, color: C) -> CString { CString::create_by_fg(self, color) } fn black(self) -> CString { self.color(Color::Black) } fn red(self) -> CString { self.color(Color::Red) } fn green(self) -> CString { self.color(Color::Green) } fn yellow(self) -> CString { self.color(Color::Yellow) } fn blue(self) -> CString { self.color(Color::Blue) } fn magenta(self) -> CString { self.color(Color::Magenta) } fn cyan(self) -> CString { self.color(Color::Cyan) } fn light_gray(self) -> CString { self.color(Color::LightGray) } fn dark_gray(self) -> CString { self.color(Color::DarkGray) } fn light_red(self) -> CString { self.color(Color::LightRed) } fn light_green(self) -> CString { self.color(Color::LightGreen) } fn light_yellow(self) -> CString { self.color(Color::LightYellow) } fn light_blue(self) -> CString { self.color(Color::LightBlue) } fn light_magenta(self) -> CString { self.color(Color::LightMagenta) } fn light_cyan(self) -> CString { self.color(Color::LightCyan) } fn white(self) -> CString { self.color(Color::White) } fn bg_color(self, color: C) -> CString { CString::create_by_bg(self, color) } fn bg_black(self) -> CString { self.bg_color(Color::Black) } fn bg_red(self) -> CString { self.bg_color(Color::Red) } fn bg_green(self) -> CString { self.bg_color(Color::Green) } fn bg_yellow(self) -> CString { self.bg_color(Color::Yellow) } fn bg_blue(self) -> CString { self.bg_color(Color::Blue) } fn bg_magenta(self) -> CString { self.bg_color(Color::Magenta) } fn bg_cyan(self) -> CString { self.bg_color(Color::Cyan) } fn bg_light_gray(self) -> CString { self.bg_color(Color::LightGray) } fn bg_dark_gray(self) -> CString { self.bg_color(Color::DarkGray) } fn bg_light_red(self) -> CString { self.bg_color(Color::LightRed) } fn bg_light_green(self) -> CString { self.bg_color(Color::LightGreen) } fn bg_light_yellow(self) -> CString { self.bg_color(Color::LightYellow) } fn bg_light_blue(self) -> CString { self.bg_color(Color::LightBlue) } fn bg_light_magenta(self) -> CString { self.bg_color(Color::LightMagenta) } fn bg_light_cyan(self) -> CString { self.bg_color(Color::LightCyan) } fn bg_white(self) -> CString { self.bg_color(Color::White) } fn rgb(self, r: u8, g: u8, b: u8) -> CString { CString::create_by_fg(self, RGB::new(r, g, b)) } fn bg_rgb(self, r: u8, g: u8, b: u8) -> CString { CString::create_by_bg(self, RGB::new(r, g, b)) } fn hsl(self, h: f32, s: f32, l: f32) -> CString { CString::create_by_fg(self, HSL::new(h, s, l)) } fn bg_hsl(self, h: f32, s: f32, l: f32) -> CString { CString::create_by_bg(self, HSL::new(h, s, l)) } fn style(self, style: Style) -> CString { CString::create_by_style(self, style) } fn bold(self) -> CString { self.style(Style::Bold) } fn blink(self) -> CString { self.style(Style::Blink) } fn dim(self) -> CString { self.style(Style::Dim) } fn underlined(self) -> CString { self.style(Style::Underlined) } fn reverse(self) -> CString { self.style(Style::Reverse) } fn hidden(self) -> CString { self.style(Style::Hidden) } fn gradient_with_step(self, color: C, step: f32) -> CString { let mut t = vec![]; let mut start = color.to_hsl().h; let s = self.to_str(); let c = s.chars(); let length = c.clone().count() - 1; for (index, i) in c.enumerate() { let b = i.to_string(); let tmp = b.hsl(start, 1.0, 0.5).to_string(); t.push(format!("{}", &tmp[..tmp.len() - if index != length { 4 } else { 0 }])); start = (start + step) % 1.0; } CString::create_by_text(self, t.join("")) } fn gradient_with_color(self, start: C, stop: C) -> CString { let mut t = vec![]; let c = self.to_str(); let s = c.chars(); let length = s.clone().count() - 1; let mut start = start.to_hsl().h; let stop = stop.to_hsl().h; let step = (stop - start) / length as f32; for (index, i) in s.enumerate() { let b = i.to_string(); let tmp = b.hsl(start, 1.0, 0.5).to_string(); t.push(format!("{}", &tmp[..tmp.len() - if index != length { 4 } else { 0 }])); start = (start + step) % 1.0; } CString::create_by_text(self, t.join("")) } fn gradient(self, color: C) -> CString { let text = self.to_str(); let lines: Vec<_> = text.lines().collect(); let mut tmp = vec![]; for sub_str in lines.iter() { tmp.push(sub_str.gradient_with_step(color.clone(), 1.5 / 360.0).to_string()); } CString::new(tmp.join("\n")) } fn rainbow_with_speed(self, speed: i32) { let respite: u64 = match speed { 3 => { 10 } 2 => { 5 } 1 => { 2 } _ => { 0 } }; let text = self.to_str(); let lines: Vec<_> = text.lines().collect(); for i in 0..360 { let mut tmp = vec![]; for sub_str in lines.iter() { tmp.push(sub_str.gradient_with_step(HSL::new(i as f32 / 360.0, 1.0, 0.5), 0.02).to_string()); } println!("{}\x1B[{}F\x1B[G\x1B[2K", tmp.join("\n"), lines.len()); let ten_millis = time::Duration::from_millis(respite); thread::sleep(ten_millis); } } fn rainbow(self) { self.rainbow_with_speed(3); } fn neon_with_speed(self, high: C, low: C, speed: i32) { let respite: u64 = match speed { 3 => { 500 } 2 => { 200 } 1 => { 100 } _ => { 0 } }; let text = self.to_str(); let lines: Vec<_> = text.lines().collect(); let mut coin = true; let positive = format!("{}\x1B[{}F\x1B[2K", text.clone().color(high), lines.len()); let negative = format!("{}\x1B[{}F\x1B[2K", text.clone().color(low), lines.len()); for _ in 0..360 { if coin { println!("{}", positive) } else { println!("{}", negative) }; let ten_millis = time::Duration::from_millis(respite); thread::sleep(ten_millis); coin = !coin; } } fn neon(self, high: C, low: C) { self.neon_with_speed(high, low, 3); } fn warn(self) { self.neon_with_speed(RGB::new(226, 14, 14), RGB::new(158, 158, 158), 3); } } pub trait ExtraColorInterface { fn grey0(self) -> CString; } impl ExtraColorInterface for T where T: Colorful { fn grey0(self) -> CString { self.color(Color::Grey0) } } colorful-0.2.2/tests/test_all_color.rs000064400000000000000000000271451046102023000162000ustar 00000000000000extern crate colorful; extern crate core; use colorful::Colorful; use colorful::Color; use colorful::core::ColorInterface; use colorful::HSL; #[test] fn test_color() { let s = "Hello world"; for (i, color) in Color::iterator().enumerate() { assert_eq!(format!("\x1B[38;5;{}mHello world\x1B[0m", i.to_owned()), s.color(*color).to_string()); } } #[test] fn test_color_to_hsl() { let l = vec![ HSL::new(0.0, 0.0, 0.0), HSL::new(0.0, 1.0, 0.25), HSL::new(0.3333333333333333, 1.0, 0.25), HSL::new(0.16666666666666666, 1.0, 0.25), HSL::new(0.6666666666666666, 1.0, 0.25), HSL::new(0.8333333333333334, 1.0, 0.25), HSL::new(0.5, 1.0, 0.25), HSL::new(0.0, 0.0, 0.75), HSL::new(0.0, 0.0, 0.5), HSL::new(0.0, 1.0, 0.5), HSL::new(0.3333333333333333, 1.0, 0.5), HSL::new(0.16666666666666666, 1.0, 0.5), HSL::new(0.6666666666666666, 1.0, 0.5), HSL::new(0.8333333333333334, 1.0, 0.5), HSL::new(0.5, 1.0, 0.5), HSL::new(0.0, 0.0, 1.0), HSL::new(0.0, 0.0, 0.0), HSL::new(0.6666666666666666, 1.0, 0.18), HSL::new(0.6666666666666666, 1.0, 0.26), HSL::new(0.6666666666666666, 1.0, 0.34), HSL::new(0.6666666666666666, 1.0, 0.42), HSL::new(0.6666666666666666, 1.0, 0.5), HSL::new(0.3333333333333333, 1.0, 0.18), HSL::new(0.5, 1.0, 0.18), HSL::new(0.5493827160493834, 1.0, 0.26), HSL::new(0.5761904761904749, 1.0, 0.34), HSL::new(0.5930232558139528, 1.0, 0.42), HSL::new(0.6045751633986917, 1.0, 0.5), HSL::new(0.3333333333333333, 1.0, 0.26), HSL::new(0.4506172839506167, 1.0, 0.26), HSL::new(0.5, 1.0, 0.26), HSL::new(0.538095238095239, 1.0, 0.34), HSL::new(0.5620155038759694, 1.0, 0.42), HSL::new(0.5784313725490194, 1.0, 0.5), HSL::new(0.3333333333333333, 1.0, 0.34), HSL::new(0.423809523809525, 1.0, 0.34), HSL::new(0.4619047619047611, 1.0, 0.34), HSL::new(0.5, 1.0, 0.34), HSL::new(0.5310077519379833, 1.0, 0.42), HSL::new(0.5522875816993472, 1.0, 0.5), HSL::new(0.3333333333333333, 1.0, 0.42), HSL::new(0.40697674418604723, 1.0, 0.42), HSL::new(0.43798449612403056, 1.0, 0.42), HSL::new(0.4689922480620166, 1.0, 0.42), HSL::new(0.5, 1.0, 0.42), HSL::new(0.5261437908496722, 1.0, 0.5), HSL::new(0.3333333333333333, 1.0, 0.5), HSL::new(0.39542483660130834, 1.0, 0.5), HSL::new(0.4215686274509806, 1.0, 0.5), HSL::new(0.4477124183006528, 1.0, 0.5), HSL::new(0.4738562091503278, 1.0, 0.5), HSL::new(0.5, 1.0, 0.5), HSL::new(0.0, 1.0, 0.18), HSL::new(0.8333333333333334, 1.0, 0.18), HSL::new(0.78395061728395, 1.0, 0.26), HSL::new(0.7571428571428583, 1.0, 0.34), HSL::new(0.7403100775193806, 1.0, 0.42), HSL::new(0.7287581699346417, 1.0, 0.5), HSL::new(0.16666666666666666, 1.0, 0.18), HSL::new(0.0, 0.0, 0.37), HSL::new(0.6666666666666666, 0.17, 0.45), HSL::new(0.6666666666666666, 0.33, 0.52), HSL::new(0.6666666666666666, 0.6, 0.6), HSL::new(0.6666666666666666, 1.0, 0.68), HSL::new(0.21604938271604945, 1.0, 0.26), HSL::new(0.3333333333333333, 0.17, 0.45), HSL::new(0.5, 0.17, 0.45), HSL::new(0.5833333333333334, 0.33, 0.52), HSL::new(0.6111111111111112, 0.6, 0.6), HSL::new(0.625, 1.0, 0.68), HSL::new(0.24285714285714277, 1.0, 0.34), HSL::new(0.3333333333333333, 0.33, 0.52), HSL::new(0.4166666666666667, 0.33, 0.52), HSL::new(0.5, 0.33, 0.52), HSL::new(0.5555555555555556, 0.6, 0.6), HSL::new(0.5833333333333334, 1.0, 0.68), HSL::new(0.2596899224806203, 1.0, 0.42), HSL::new(0.3333333333333333, 0.6, 0.6), HSL::new(0.3888888888888889, 0.6, 0.6), HSL::new(0.4444444444444444, 0.6, 0.6), HSL::new(0.5, 0.6, 0.6), HSL::new(0.5416666666666666, 1.0, 0.68), HSL::new(0.27124183006535946, 1.0, 0.5), HSL::new(0.3333333333333333, 1.0, 0.68), HSL::new(0.375, 1.0, 0.68), HSL::new(0.4166666666666667, 1.0, 0.68), HSL::new(0.4583333333333333, 1.0, 0.68), HSL::new(0.5, 1.0, 0.68), HSL::new(0.0, 1.0, 0.26), HSL::new(0.8827160493827166, 1.0, 0.26), HSL::new(0.8333333333333334, 1.0, 0.26), HSL::new(0.7952380952380944, 1.0, 0.34), HSL::new(0.7713178294573639, 1.0, 0.42), HSL::new(0.7549019607843138, 1.0, 0.5), HSL::new(0.11728395061728389, 1.0, 0.26), HSL::new(0.0, 0.17, 0.45), HSL::new(0.8333333333333334, 0.17, 0.45), HSL::new(0.75, 0.33, 0.52), HSL::new(0.7222222222222222, 0.6, 0.6), HSL::new(0.7083333333333334, 1.0, 0.68), HSL::new(0.16666666666666666, 1.0, 0.26), HSL::new(0.16666666666666666, 0.17, 0.45), HSL::new(0.0, 0.0, 0.52), HSL::new(0.6666666666666666, 0.2, 0.6), HSL::new(0.6666666666666666, 0.5, 0.68), HSL::new(0.6666666666666666, 1.0, 0.76), HSL::new(0.2047619047619047, 1.0, 0.34), HSL::new(0.25, 0.33, 0.52), HSL::new(0.3333333333333333, 0.2, 0.6), HSL::new(0.5, 0.2, 0.6), HSL::new(0.5833333333333334, 0.5, 0.68), HSL::new(0.6111111111111112, 1.0, 0.76), HSL::new(0.22868217054263557, 1.0, 0.42), HSL::new(0.2777777777777778, 0.6, 0.6), HSL::new(0.3333333333333333, 0.5, 0.68), HSL::new(0.4166666666666667, 0.5, 0.68), HSL::new(0.5, 0.5, 0.68), HSL::new(0.5555555555555556, 1.0, 0.76), HSL::new(0.2450980392156864, 1.0, 0.5), HSL::new(0.2916666666666667, 1.0, 0.68), HSL::new(0.3333333333333333, 1.0, 0.76), HSL::new(0.3888888888888889, 1.0, 0.76), HSL::new(0.4444444444444444, 1.0, 0.76), HSL::new(0.5, 1.0, 0.76), HSL::new(0.0, 1.0, 0.34), HSL::new(0.9095238095238083, 1.0, 0.34), HSL::new(0.8714285714285722, 1.0, 0.34), HSL::new(0.8333333333333334, 1.0, 0.34), HSL::new(0.80232558139535, 1.0, 0.42), HSL::new(0.7810457516339862, 1.0, 0.5), HSL::new(0.09047619047619054, 1.0, 0.34), HSL::new(0.0, 0.33, 0.52), HSL::new(0.9166666666666666, 0.33, 0.52), HSL::new(0.8333333333333334, 0.33, 0.52), HSL::new(0.7777777777777778, 0.6, 0.6), HSL::new(0.75, 1.0, 0.68), HSL::new(0.12857142857142861, 1.0, 0.34), HSL::new(0.08333333333333333, 0.33, 0.52), HSL::new(0.0, 0.2, 0.6), HSL::new(0.8333333333333334, 0.2, 0.6), HSL::new(0.75, 0.5, 0.68), HSL::new(0.7222222222222222, 1.0, 0.76), HSL::new(0.16666666666666666, 1.0, 0.34), HSL::new(0.16666666666666666, 0.33, 0.52), HSL::new(0.16666666666666666, 0.2, 0.6), HSL::new(0.0, 0.0, 0.68), HSL::new(0.6666666666666666, 0.33, 0.76), HSL::new(0.6666666666666666, 1.0, 0.84), HSL::new(0.1976744186046511, 1.0, 0.42), HSL::new(0.2222222222222222, 0.6, 0.6), HSL::new(0.25, 0.5, 0.68), HSL::new(0.3333333333333333, 0.33, 0.76), HSL::new(0.5, 0.33, 0.76), HSL::new(0.5833333333333334, 1.0, 0.84), HSL::new(0.21895424836601304, 1.0, 0.5), HSL::new(0.25, 1.0, 0.68), HSL::new(0.2777777777777778, 1.0, 0.76), HSL::new(0.3333333333333333, 1.0, 0.84), HSL::new(0.4166666666666667, 1.0, 0.84), HSL::new(0.5, 1.0, 0.84), HSL::new(0.0, 1.0, 0.42), HSL::new(0.926356589147286, 1.0, 0.42), HSL::new(0.8953488372093028, 1.0, 0.42), HSL::new(0.8643410852713166, 1.0, 0.42), HSL::new(0.8333333333333334, 1.0, 0.42), HSL::new(0.8071895424836611, 1.0, 0.5), HSL::new(0.07364341085271306, 1.0, 0.42), HSL::new(0.0, 0.6, 0.6), HSL::new(0.9444444444444444, 0.6, 0.6), HSL::new(0.8888888888888888, 0.6, 0.6), HSL::new(0.8333333333333334, 0.6, 0.6), HSL::new(0.7916666666666666, 1.0, 0.68), HSL::new(0.10465116279069778, 1.0, 0.42), HSL::new(0.05555555555555555, 0.6, 0.6), HSL::new(0.0, 0.5, 0.68), HSL::new(0.9166666666666666, 0.5, 0.68), HSL::new(0.8333333333333334, 0.5, 0.68), HSL::new(0.7777777777777778, 1.0, 0.76), HSL::new(0.13565891472868222, 1.0, 0.42), HSL::new(0.1111111111111111, 0.6, 0.6), HSL::new(0.08333333333333333, 0.5, 0.68), HSL::new(0.0, 0.33, 0.76), HSL::new(0.8333333333333334, 0.33, 0.76), HSL::new(0.75, 1.0, 0.84), HSL::new(0.16666666666666666, 1.0, 0.42), HSL::new(0.16666666666666666, 0.6, 0.6), HSL::new(0.16666666666666666, 0.5, 0.68), HSL::new(0.16666666666666666, 0.33, 0.76), HSL::new(0.0, 0.0, 0.84), HSL::new(0.6666666666666666, 1.0, 0.92), HSL::new(0.19281045751633974, 1.0, 0.5), HSL::new(0.20833333333333334, 1.0, 0.68), HSL::new(0.2222222222222222, 1.0, 0.76), HSL::new(0.25, 1.0, 0.84), HSL::new(0.3333333333333333, 1.0, 0.92), HSL::new(0.5, 1.0, 0.92), HSL::new(0.0, 1.0, 0.5), HSL::new(0.937908496732025, 1.0, 0.5), HSL::new(0.9117647058823528, 1.0, 0.5), HSL::new(0.8856209150326805, 1.0, 0.5), HSL::new(0.8594771241830055, 1.0, 0.5), HSL::new(0.8333333333333334, 1.0, 0.5), HSL::new(0.06209150326797389, 1.0, 0.5), HSL::new(0.0, 1.0, 0.68), HSL::new(0.9583333333333334, 1.0, 0.68), HSL::new(0.9166666666666666, 1.0, 0.68), HSL::new(0.875, 1.0, 0.68), HSL::new(0.8333333333333334, 1.0, 0.68), HSL::new(0.08823529411764694, 1.0, 0.5), HSL::new(0.041666666666666664, 1.0, 0.68), HSL::new(0.0, 1.0, 0.76), HSL::new(0.9444444444444444, 1.0, 0.76), HSL::new(0.8888888888888888, 1.0, 0.76), HSL::new(0.8333333333333334, 1.0, 0.76), HSL::new(0.11437908496732027, 1.0, 0.5), HSL::new(0.08333333333333333, 1.0, 0.68), HSL::new(0.05555555555555555, 1.0, 0.76), HSL::new(0.0, 1.0, 0.84), HSL::new(0.9166666666666666, 1.0, 0.84), HSL::new(0.8333333333333334, 1.0, 0.84), HSL::new(0.14052287581699335, 1.0, 0.5), HSL::new(0.125, 1.0, 0.68), HSL::new(0.1111111111111111, 1.0, 0.76), HSL::new(0.08333333333333333, 1.0, 0.84), HSL::new(0.0, 1.0, 0.92), HSL::new(0.8333333333333334, 1.0, 0.92), HSL::new(0.16666666666666666, 1.0, 0.5), HSL::new(0.16666666666666666, 1.0, 0.68), HSL::new(0.16666666666666666, 1.0, 0.76), HSL::new(0.16666666666666666, 1.0, 0.84), HSL::new(0.16666666666666666, 1.0, 0.92), HSL::new(0.0, 0.0, 1.0), HSL::new(0.0, 0.0, 0.03), HSL::new(0.0, 0.0, 0.07), HSL::new(0.0, 0.0, 0.1), HSL::new(0.0, 0.0, 0.14), HSL::new(0.0, 0.0, 0.18), HSL::new(0.0, 0.0, 0.22), HSL::new(0.0, 0.0, 0.26), HSL::new(0.0, 0.0, 0.3), HSL::new(0.0, 0.0, 0.34), HSL::new(0.0, 0.0, 0.37), HSL::new(0.0, 0.0, 0.4), HSL::new(0.0, 0.0, 0.46), HSL::new(0.0, 0.0, 0.5), HSL::new(0.0, 0.0, 0.54), HSL::new(0.0, 0.0, 0.58), HSL::new(0.0, 0.0, 0.61), HSL::new(0.0, 0.0, 0.65), HSL::new(0.0, 0.0, 0.69), HSL::new(0.0, 0.0, 0.73), HSL::new(0.0, 0.0, 0.77), HSL::new(0.0, 0.0, 0.81), HSL::new(0.0, 0.0, 0.85), HSL::new(0.0, 0.0, 0.89), HSL::new(0.0, 0.0, 0.93), ]; for (i, color) in Color::iterator().enumerate() { assert_eq!(color.to_hsl(), l[i]); } }colorful-0.2.2/tests/test_animation.rs000064400000000000000000000010741046102023000162020ustar 00000000000000extern crate colorful; use colorful::Color; use colorful::Colorful; use colorful::HSL; use colorful::RGB; #[test] fn test_rainbow() { let s = "Hello world"; s.rainbow_with_speed(0); } #[test] fn test_neon_1() { let s = "Hello world"; s.neon_with_speed(Color::Grey0, Color::Grey0, 0); } #[test] fn test_neon_2() { let s = "Hello world"; s.neon_with_speed(HSL::new(1.0, 1.0, 0.4), HSL::new(0.5, 1.0, 0.4), 0); } #[test] fn test_neon_3() { let s = "Hello world"; s.neon_with_speed(RGB::new(122, 122, 122), RGB::new(222, 222, 222), 0); } colorful-0.2.2/tests/test_basic.rs000064400000000000000000000037741046102023000153150ustar 00000000000000extern crate colorful; extern crate core; use colorful::Colorful; use colorful::Color; use colorful::Style; #[test] fn test_1() { assert_eq!("\u{1b}", "\x1B"); } #[test] fn test_color() { let s = "Hello world"; assert_eq!("\x1B[38;5;1mHello world\x1B[0m".to_owned(), s.color(Color::Red).to_string()); assert_eq!("\x1B[38;5;220mHello world\x1B[0m".to_owned(), s.color(Color::Red).color(Color::Gold1).to_string()); } #[test] fn test_bg_color() { let s = "Hello world"; assert_eq!("\x1B[38;5;1m\x1B[48;5;16mHello world\x1B[0m".to_owned(), s.color(Color::Red).bg_color(Color::Grey0).to_string()); assert_eq!("\x1B[38;5;1m\x1B[48;5;6mHello world\x1B[0m".to_owned(), s.color(Color::Red).bg_cyan().to_string()); assert_eq!("\x1B[38;5;220m\x1B[48;5;6mHello world\x1B[0m".to_owned(), s.color(Color::Red).color(Color::Gold1).bg_color(Color::Cyan).to_string()); } #[test] fn test_style() { let s = "Hello world"; assert_eq!("\x1B[1mHello world\x1B[0m".to_owned(), s.style(Style::Bold).to_string()); assert_eq!("\x1B[1;5mHello world\x1B[0m".to_owned(), s.style(Style::Bold).style(Style::Blink).to_string()); } #[test] fn test_interface() { let s = "Hello world"; assert_eq!("\x1B[1mHello world\x1B[0m".to_owned(), s.bold().to_string()); assert_eq!("\x1B[1;5mHello world\x1B[0m".to_owned(), s.bold().blink().to_string()); assert_eq!("\x1B[38;5;1mHello world\x1B[0m".to_owned(), s.red().to_string()); assert_eq!("\x1B[38;5;2mHello world\x1B[0m".to_owned(), s.red().green().to_string()); } #[test] fn test_mix() { let s = "Hello world"; assert_eq!("\x1B[38;5;1;5mHello world\x1B[0m".to_owned(), s.color(Color::Red).blink().to_string()); assert_eq!("\x1B[38;5;220;1mHello world\x1B[0m".to_owned(), s.bold().color(Color::Gold1).to_string()); assert_eq!("\x1B[38;5;2;5;1mHello world\x1B[0m".to_owned(), s.color(Color::Green).blink().bold().to_string()); assert_eq!("\x1B[38;5;220;1;5mHello world\x1B[0m".to_owned(), s.bold().blink().color(Color::Gold1).to_string()); } colorful-0.2.2/tests/test_extra.rs000064400000000000000000000003451046102023000153460ustar 00000000000000extern crate colorful; extern crate core; #[test] fn test_extra_color() { use colorful::ExtraColorInterface; let s = "Hello world"; assert_eq!("\x1B[38;5;16mHello world\x1B[0m".to_owned(), s.grey0().to_string()); } colorful-0.2.2/tests/test_gradient.rs000064400000000000000000000012051046102023000160140ustar 00000000000000extern crate colorful; use colorful::Color; use colorful::Colorful; #[test] fn test_gradient_color() { let s = "Hello world"; assert_eq!("\u{1b}[38;2;255;0;0mH\u{1b}[38;2;255;6;0me\u{1b}[38;2;255;13;0ml\u{1b}[38;2;255;19;0ml\u{1b}[38;2;255;26;0mo\u{1b}[38;2;255;32;0m \u{1b}[38;2;255;38;0mw\u{1b}[38;2;255;45;0mo\u{1b}[38;2;255;51;0mr\u{1b}[38;2;255;57;0ml\u{1b}[38;2;255;64;0md\u{1b}[0m".to_owned(), s.gradient(Color::Red).to_string()); } #[test] fn test_gradient_multiple_lines() { let s = "a\nb"; assert_eq!("\u{1b}[38;2;255;0;0ma\u{1b}[0m\n\u{1b}[38;2;255;0;0mb\u{1b}[0m".to_owned(), s.gradient(Color::Red).to_string()); }colorful-0.2.2/tests/test_hsl.rs000064400000000000000000000003351046102023000150100ustar 00000000000000extern crate colorful; extern crate core; use colorful::Colorful; #[test] fn test_hsl_color() { let s = "Hello world"; assert_eq!("\x1B[38;2;19;205;94mHello world\x1B[0m", s.hsl(0.4, 0.83, 0.44).to_string()); }