Fixes white/grey and added dark grey (#131)
* fixed white/grey and added dark grey * add dark grey to style example
This commit is contained in:
parent
a4ff052119
commit
b8be1910b6
@ -41,7 +41,7 @@ impl ITerminalColor for AnsiColor {
|
|||||||
fn color_value(&self, colored: Colored) -> String {
|
fn color_value(&self, colored: Colored) -> String {
|
||||||
let mut ansi_value = String::new();
|
let mut ansi_value = String::new();
|
||||||
|
|
||||||
let mut color = Color::White;
|
let color;
|
||||||
|
|
||||||
match colored {
|
match colored {
|
||||||
Colored::Fg(new_color) => {
|
Colored::Fg(new_color) => {
|
||||||
@ -58,6 +58,7 @@ impl ITerminalColor for AnsiColor {
|
|||||||
|
|
||||||
let color_val = match color {
|
let color_val = match color {
|
||||||
Color::Black => "5;0",
|
Color::Black => "5;0",
|
||||||
|
Color::DarkGrey => "5;8",
|
||||||
Color::Red => "5;9",
|
Color::Red => "5;9",
|
||||||
Color::DarkRed => "5;1",
|
Color::DarkRed => "5;1",
|
||||||
Color::Green => "5;10",
|
Color::Green => "5;10",
|
||||||
@ -70,8 +71,8 @@ impl ITerminalColor for AnsiColor {
|
|||||||
Color::DarkMagenta => "5;5",
|
Color::DarkMagenta => "5;5",
|
||||||
Color::Cyan => "5;14",
|
Color::Cyan => "5;14",
|
||||||
Color::DarkCyan => "5;6",
|
Color::DarkCyan => "5;6",
|
||||||
Color::Grey => "5;15",
|
Color::White => "5;15",
|
||||||
Color::White => "5;7",
|
Color::Grey => "5;7",
|
||||||
|
|
||||||
Color::Rgb { r, g, b } => {
|
Color::Rgb { r, g, b } => {
|
||||||
rgb_val = format!("2;{};{};{}", r, g, b);
|
rgb_val = format!("2;{};{};{}", r, g, b);
|
||||||
|
@ -5,6 +5,7 @@ use std::str::FromStr;
|
|||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
pub enum Color {
|
pub enum Color {
|
||||||
Black,
|
Black,
|
||||||
|
DarkGrey,
|
||||||
|
|
||||||
Red,
|
Red,
|
||||||
DarkRed,
|
DarkRed,
|
||||||
@ -24,8 +25,8 @@ pub enum Color {
|
|||||||
Cyan,
|
Cyan,
|
||||||
DarkCyan,
|
DarkCyan,
|
||||||
|
|
||||||
Grey,
|
|
||||||
White,
|
White,
|
||||||
|
Grey,
|
||||||
/// Color representing RGB-colors;
|
/// Color representing RGB-colors;
|
||||||
/// r = red
|
/// r = red
|
||||||
/// g = green
|
/// g = green
|
||||||
@ -61,6 +62,7 @@ impl FromStr for Color {
|
|||||||
|
|
||||||
match src.as_ref() {
|
match src.as_ref() {
|
||||||
"black" => Ok(Color::Black),
|
"black" => Ok(Color::Black),
|
||||||
|
"dark_grey" => Ok(Color::DarkGrey),
|
||||||
"red" => Ok(Color::Red),
|
"red" => Ok(Color::Red),
|
||||||
"dark_red" => Ok(Color::DarkRed),
|
"dark_red" => Ok(Color::DarkRed),
|
||||||
"green" => Ok(Color::Green),
|
"green" => Ok(Color::Green),
|
||||||
@ -73,8 +75,8 @@ impl FromStr for Color {
|
|||||||
"dark_magenta" => Ok(Color::DarkMagenta),
|
"dark_magenta" => Ok(Color::DarkMagenta),
|
||||||
"cyan" => Ok(Color::Cyan),
|
"cyan" => Ok(Color::Cyan),
|
||||||
"dark_cyan" => Ok(Color::DarkCyan),
|
"dark_cyan" => Ok(Color::DarkCyan),
|
||||||
"grey" => Ok(Color::Grey),
|
|
||||||
"white" => Ok(Color::White),
|
"white" => Ok(Color::White),
|
||||||
|
"grey" => Ok(Color::Grey),
|
||||||
_ => Ok(Color::White),
|
_ => Ok(Color::White),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -80,6 +80,7 @@ where
|
|||||||
impl Colorize<&'static str> for &'static str {
|
impl Colorize<&'static str> for &'static str {
|
||||||
// foreground colors
|
// foreground colors
|
||||||
def_str_color!(fg_color: black => Color::Black);
|
def_str_color!(fg_color: black => Color::Black);
|
||||||
|
def_str_color!(fg_color: dark_grey => Color::DarkGrey);
|
||||||
def_str_color!(fg_color: red => Color::Red);
|
def_str_color!(fg_color: red => Color::Red);
|
||||||
def_str_color!(fg_color: dark_red => Color::DarkRed);
|
def_str_color!(fg_color: dark_red => Color::DarkRed);
|
||||||
def_str_color!(fg_color: green => Color::Green);
|
def_str_color!(fg_color: green => Color::Green);
|
||||||
@ -97,6 +98,7 @@ impl Colorize<&'static str> for &'static str {
|
|||||||
|
|
||||||
// background colors
|
// background colors
|
||||||
def_str_color!(bg_color: on_black => Color::Black);
|
def_str_color!(bg_color: on_black => Color::Black);
|
||||||
|
def_str_color!(bg_color: on_dark_grey => Color::DarkGrey);
|
||||||
def_str_color!(bg_color: on_red => Color::Red);
|
def_str_color!(bg_color: on_red => Color::Red);
|
||||||
def_str_color!(bg_color: on_dark_red => Color::DarkRed);
|
def_str_color!(bg_color: on_dark_red => Color::DarkRed);
|
||||||
def_str_color!(bg_color: on_green => Color::Green);
|
def_str_color!(bg_color: on_green => Color::Green);
|
||||||
|
@ -83,6 +83,7 @@ impl<D: Display> Display for StyledObject<D> {
|
|||||||
impl<D: Display> Colorize<D> for StyledObject<D> {
|
impl<D: Display> Colorize<D> for StyledObject<D> {
|
||||||
// foreground colors
|
// foreground colors
|
||||||
def_color!(fg_color: black => Color::Black);
|
def_color!(fg_color: black => Color::Black);
|
||||||
|
def_color!(fg_color: dark_grey => Color::DarkGrey);
|
||||||
def_color!(fg_color: red => Color::Red);
|
def_color!(fg_color: red => Color::Red);
|
||||||
def_color!(fg_color: dark_red => Color::DarkRed);
|
def_color!(fg_color: dark_red => Color::DarkRed);
|
||||||
def_color!(fg_color: green => Color::Green);
|
def_color!(fg_color: green => Color::Green);
|
||||||
@ -100,6 +101,7 @@ impl<D: Display> Colorize<D> for StyledObject<D> {
|
|||||||
|
|
||||||
// background colors
|
// background colors
|
||||||
def_color!(bg_color: on_black => Color::Black);
|
def_color!(bg_color: on_black => Color::Black);
|
||||||
|
def_color!(bg_color: on_dark_grey => Color::DarkGrey);
|
||||||
def_color!(bg_color: on_red => Color::Red);
|
def_color!(bg_color: on_red => Color::Red);
|
||||||
def_color!(bg_color: on_dark_red => Color::DarkRed);
|
def_color!(bg_color: on_dark_red => Color::DarkRed);
|
||||||
def_color!(bg_color: on_green => Color::Green);
|
def_color!(bg_color: on_green => Color::Green);
|
||||||
|
@ -13,6 +13,7 @@ use std::fmt::Display;
|
|||||||
/// ```
|
/// ```
|
||||||
pub trait Colorize<D: Display> {
|
pub trait Colorize<D: Display> {
|
||||||
fn black(self) -> StyledObject<D>;
|
fn black(self) -> StyledObject<D>;
|
||||||
|
fn dark_grey(self) -> StyledObject<D>;
|
||||||
fn red(self) -> StyledObject<D>;
|
fn red(self) -> StyledObject<D>;
|
||||||
fn dark_red(self) -> StyledObject<D>;
|
fn dark_red(self) -> StyledObject<D>;
|
||||||
fn green(self) -> StyledObject<D>;
|
fn green(self) -> StyledObject<D>;
|
||||||
@ -29,6 +30,7 @@ pub trait Colorize<D: Display> {
|
|||||||
fn grey(self) -> StyledObject<D>;
|
fn grey(self) -> StyledObject<D>;
|
||||||
|
|
||||||
fn on_black(self) -> StyledObject<D>;
|
fn on_black(self) -> StyledObject<D>;
|
||||||
|
fn on_dark_grey(self) -> StyledObject<D>;
|
||||||
fn on_red(self) -> StyledObject<D>;
|
fn on_red(self) -> StyledObject<D>;
|
||||||
fn on_dark_red(self) -> StyledObject<D>;
|
fn on_dark_red(self) -> StyledObject<D>;
|
||||||
fn on_green(self) -> StyledObject<D>;
|
fn on_green(self) -> StyledObject<D>;
|
||||||
|
@ -99,6 +99,7 @@ impl ITerminalColor for WinApiColor {
|
|||||||
Colored::Fg(color) => {
|
Colored::Fg(color) => {
|
||||||
winapi_color = match color {
|
winapi_color = match color {
|
||||||
Color::Black => 0,
|
Color::Black => 0,
|
||||||
|
Color::DarkGrey => fg_intensity,
|
||||||
Color::Red => fg_intensity | fg_red,
|
Color::Red => fg_intensity | fg_red,
|
||||||
Color::DarkRed => fg_red,
|
Color::DarkRed => fg_red,
|
||||||
Color::Green => fg_intensity | fg_green,
|
Color::Green => fg_intensity | fg_green,
|
||||||
@ -111,8 +112,8 @@ impl ITerminalColor for WinApiColor {
|
|||||||
Color::DarkMagenta => fg_red | fg_blue,
|
Color::DarkMagenta => fg_red | fg_blue,
|
||||||
Color::Cyan => fg_intensity | fg_green | fg_blue,
|
Color::Cyan => fg_intensity | fg_green | fg_blue,
|
||||||
Color::DarkCyan => fg_green | fg_blue,
|
Color::DarkCyan => fg_green | fg_blue,
|
||||||
Color::Grey => fg_intensity,
|
Color::White => fg_red | fg_green | fg_blue,
|
||||||
Color::White => fg_intensity | fg_red | fg_green | fg_blue,
|
Color::Grey => fg_intensity | fg_red | fg_green | fg_blue,
|
||||||
|
|
||||||
/* WinApi will be used for systems that do not support ANSI, those are windows version less then 10. RGB and 255 (AnsiBValue) colors are not supported in that case.*/
|
/* WinApi will be used for systems that do not support ANSI, those are windows version less then 10. RGB and 255 (AnsiBValue) colors are not supported in that case.*/
|
||||||
Color::Rgb { r: _, g: _, b: _ } => 0,
|
Color::Rgb { r: _, g: _, b: _ } => 0,
|
||||||
@ -122,6 +123,7 @@ impl ITerminalColor for WinApiColor {
|
|||||||
Colored::Bg(color) => {
|
Colored::Bg(color) => {
|
||||||
winapi_color = match color {
|
winapi_color = match color {
|
||||||
Color::Black => 0,
|
Color::Black => 0,
|
||||||
|
Color::DarkGrey => bg_intensity,
|
||||||
Color::Red => bg_intensity | bg_red,
|
Color::Red => bg_intensity | bg_red,
|
||||||
Color::DarkRed => bg_red,
|
Color::DarkRed => bg_red,
|
||||||
Color::Green => bg_intensity | bg_green,
|
Color::Green => bg_intensity | bg_green,
|
||||||
@ -134,8 +136,8 @@ impl ITerminalColor for WinApiColor {
|
|||||||
Color::DarkMagenta => bg_red | bg_blue,
|
Color::DarkMagenta => bg_red | bg_blue,
|
||||||
Color::Cyan => bg_intensity | bg_green | bg_blue,
|
Color::Cyan => bg_intensity | bg_green | bg_blue,
|
||||||
Color::DarkCyan => bg_green | bg_blue,
|
Color::DarkCyan => bg_green | bg_blue,
|
||||||
Color::Grey => bg_intensity,
|
|
||||||
Color::White => bg_intensity | bg_red | bg_green | bg_blue,
|
Color::White => bg_intensity | bg_red | bg_green | bg_blue,
|
||||||
|
Color::Grey => bg_red | bg_green | bg_blue,
|
||||||
|
|
||||||
/* WinApi will be used for systems that do not support ANSI, those are windows version less then 10. RGB and 255 (AnsiBValue) colors are not supported in that case.*/
|
/* WinApi will be used for systems that do not support ANSI, those are windows version less then 10. RGB and 255 (AnsiBValue) colors are not supported in that case.*/
|
||||||
Color::Rgb { r: _, g: _, b: _ } => 0,
|
Color::Rgb { r: _, g: _, b: _ } => 0,
|
||||||
|
@ -25,6 +25,11 @@ pub fn print_all_foreground_colors_with_enum() {
|
|||||||
Colored::Fg(Color::Black),
|
Colored::Fg(Color::Black),
|
||||||
Attribute::Reset
|
Attribute::Reset
|
||||||
);
|
);
|
||||||
|
println!(
|
||||||
|
"DarkGrey : \t\t {} ■ {}\n",
|
||||||
|
Colored::Fg(Color::DarkGrey),
|
||||||
|
Attribute::Reset
|
||||||
|
);
|
||||||
println!(
|
println!(
|
||||||
"Red : \t\t {} ■ {}\n",
|
"Red : \t\t {} ■ {}\n",
|
||||||
Colored::Fg(Color::Red),
|
Colored::Fg(Color::Red),
|
||||||
@ -117,6 +122,11 @@ pub fn print_all_foreground_colors_with_method() {
|
|||||||
"■".black(),
|
"■".black(),
|
||||||
Attribute::Reset
|
Attribute::Reset
|
||||||
);
|
);
|
||||||
|
println!(
|
||||||
|
"DarkGrey : \t\t {} {}\n",
|
||||||
|
"■".dark_grey(),
|
||||||
|
Attribute::Reset
|
||||||
|
);
|
||||||
println!("Red : \t\t {} {}\n", "■".red(), Attribute::Reset);
|
println!("Red : \t\t {} {}\n", "■".red(), Attribute::Reset);
|
||||||
println!(
|
println!(
|
||||||
"DarkRed : \t\t {} {}\n",
|
"DarkRed : \t\t {} {}\n",
|
||||||
@ -180,6 +190,11 @@ pub fn print_all_background_colors_with_enum() {
|
|||||||
Colored::Bg(Color::Black),
|
Colored::Bg(Color::Black),
|
||||||
Attribute::Reset
|
Attribute::Reset
|
||||||
);
|
);
|
||||||
|
println!(
|
||||||
|
"DarkGrey : \t\t {} ■ {}\n",
|
||||||
|
Colored::Bg(Color::DarkGrey),
|
||||||
|
Attribute::Reset
|
||||||
|
);
|
||||||
println!(
|
println!(
|
||||||
"Red : \t\t {} ■ {}\n",
|
"Red : \t\t {} ■ {}\n",
|
||||||
Colored::Bg(Color::Red),
|
Colored::Bg(Color::Red),
|
||||||
@ -272,6 +287,11 @@ pub fn print_all_background_colors_with_method() {
|
|||||||
"■".on_black(),
|
"■".on_black(),
|
||||||
Attribute::Reset
|
Attribute::Reset
|
||||||
);
|
);
|
||||||
|
println!(
|
||||||
|
"DarkGrey : \t\t {} {}\n",
|
||||||
|
"■".on_dark_grey(),
|
||||||
|
Attribute::Reset
|
||||||
|
);
|
||||||
println!(
|
println!(
|
||||||
"Red : \t\t {} {}\n",
|
"Red : \t\t {} {}\n",
|
||||||
"■".on_red(),
|
"■".on_red(),
|
||||||
|
Loading…
Reference in New Issue
Block a user