diff --git a/README.md b/README.md index 576e86d..f0dd02f 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,8 @@ These are the features from this crate: - Styled output - Foreground color (16 base colors) - Background color (16 base colors) - - 256 color support (unix only) + - 256 color support (Windows 10 and UNIX only) + - RGB support (Windows 10 and UNIX only) - Text Attributes like: bold, italic, underscore and crossed word ect (unix only) - Custom ANSI color code input to set fore- and background color (unix only) - Terminal diff --git a/docs/ReleaseNotes.md b/docs/ReleaseNotes.md index 7c36bbd..b7d08ad 100644 --- a/docs/ReleaseNotes.md +++ b/docs/ReleaseNotes.md @@ -1,7 +1,9 @@ # Changes crossterm 0.5.0 -- Implemented Display for styled object. -- More convenient API, no need to care about `Screen` unless working with when working with alternate or raw screen [PR](https://github.com/TimonPost/crossterm/pull/44) - Added ability to pause the terminal [issue](https://github.com/TimonPost/crossterm/issues/39) +- RGB support for Windows 10 systems +- ANSI color value (255) color support +- More convenient API, no need to care about `Screen` unless working with when working with alternate or raw screen [PR](https://github.com/TimonPost/crossterm/pull/44) +- Implemented Display for styled object # Changes crossterm to 0.4.3 - Fixed bug [issue 41](https://github.com/TimonPost/crossterm/issues/41) diff --git a/docs/mdbook/src/styling.md b/docs/mdbook/src/styling.md index 44ec3b5..35b5641 100644 --- a/docs/mdbook/src/styling.md +++ b/docs/mdbook/src/styling.md @@ -17,12 +17,11 @@ There are 16 base colors which available for almost all terminals even windows 7 | Cyan | DarkCyan | | White | DarkWhite | -In addition to 16 colours, most unix terminals also support more colors. -For example, GNOME-terminals are supporting the [True color (24-bit)](https://en.wikipedia.org/wiki/Color_depth#True_color_(24-bit)) coloring scheme which allows you to use [RGB](https://nl.wikipedia.org/wiki/RGB-kleursysteem) for setting the terminal color. -All xterm terminals are at least supporting the [256 (Xterm, 8-bit)](https://jonasjacek.github.io/colors/) colors. +In addition to 16 colours, most UNIX terminals and Windows 10 consoles are also supporting more colors. +Those colors could be: [True color (24-bit)](https://en.wikipedia.org/wiki/Color_depth#True_color_(24-bit)) coloring scheme, which allows you to use [RGB](https://nl.wikipedia.org/wiki/RGB-kleursysteem), and [256 (Xterm, 8-bit)](https://jonasjacek.github.io/colors/) colors. ## Attributes -UNIX terminals are supporting attributes on top of text. Crossterm allows you to add attributes to the text. +Only UNIX terminals are supporting attributes on top of text. Crossterm allows you to add attributes to the text. Not all attributes are widely supported for all terminals, keep that in mind when working with this. | Attribute | Note | diff --git a/docs/mdbook/src/styling_example.md b/docs/mdbook/src/styling_example.md index 3dcd5f2..39d8527 100644 --- a/docs/mdbook/src/styling_example.md +++ b/docs/mdbook/src/styling_example.md @@ -38,7 +38,7 @@ When running the above code you are supposed to see colored text with foreground _note: you don't have to color both backround an foreground, if not specified they remain as they are_. ### RGB -Most UNIX terminals are supporting [True color(24-bit)](https://en.wikipedia.org/wiki/Color_depth#True_color_(24-bit)) coloring scheme. +Most UNIX terminals and all Windows 10 consoles are supporting [True color(24-bit)](https://en.wikipedia.org/wiki/Color_depth#True_color_(24-bit)) coloring scheme. You can set the color of the terminal by using `Color::RGB(r,g,b)`. ``` @@ -49,7 +49,7 @@ let styled_object = style("'Light green' text on 'Black' background") This will print some light green text on black background. ### Custom ANSI color value -When working on unix you could also specify a custom ANSI value ranging up from 0 to 256. +When working on UNIX or Windows 10 you could also specify a custom ANSI value ranging up from 0 to 256. See [256 (Xterm, 8-bit) colors](https://jonasjacek.github.io/colors/) for more information. ``` @@ -62,7 +62,7 @@ println!("{}", styled_object); ``` ## Attributes -When working in Linux you could also use attributes to style your font. For example you could cross your text with a line and make it bold. +When working with UNIX terminals you could also use attributes to style your font. For example you could cross your text with a line and make it bold. See [above](styling.md#Attributes) for more information. ``` diff --git a/examples/examples.rs b/examples/examples.rs index 5c807fb..26f3d6e 100644 --- a/examples/examples.rs +++ b/examples/examples.rs @@ -18,8 +18,8 @@ use crossterm::style::{style, Color, Attribute}; fn main() { let styled_object = style("'Red' text on 'White' background") - .with(Color::AnsiValue(9)) - .on(Color::AnsiValue(15)); + .with(Color::Rgb { r: 34, g: 80, b: 23 }) + .on(Color::Rgb { r: 34, g: 80, b: 23 }); println!("{}", styled_object); } \ No newline at end of file diff --git a/src/modules/style/ansi_color.rs b/src/modules/style/ansi_color.rs index 7ff7674..f429c05 100644 --- a/src/modules/style/ansi_color.rs +++ b/src/modules/style/ansi_color.rs @@ -45,7 +45,6 @@ impl ITerminalColor for AnsiColor { ColorType::Background => ansi_value.push_str("48;"), } - #[cfg(unix)] let rgb_val: String; let color_val = match color { @@ -64,12 +63,11 @@ impl ITerminalColor for AnsiColor { Color::DarkCyan => "5;6", Color::Grey => "5;15", Color::White => "5;7", - #[cfg(unix)] + Color::Rgb { r, g, b } => { rgb_val = format!("2;{};{};{}", r, g, b); rgb_val.as_str() } - #[cfg(unix)] Color::AnsiValue(val) => { rgb_val = format!("5;{}", val); rgb_val.as_str() diff --git a/src/modules/style/mod.rs b/src/modules/style/mod.rs index 57e387b..d3a109c 100644 --- a/src/modules/style/mod.rs +++ b/src/modules/style/mod.rs @@ -110,13 +110,11 @@ pub enum Color { Grey, White, - #[cfg(unix)] Rgb { r: u8, g: u8, b: u8, }, - #[cfg(unix)] AnsiValue(u8), } diff --git a/src/modules/style/styledobject.rs b/src/modules/style/styledobject.rs index a9f73fb..a6e9a46 100644 --- a/src/modules/style/styledobject.rs +++ b/src/modules/style/styledobject.rs @@ -220,7 +220,6 @@ impl Display for StyledObject { std::io::stdout().flush().expect("Flush stdout failed"); if reset { -// write!(f, "\x1b[0m")?; colored_terminal.reset(); std::io::stdout().flush().expect("Flush stdout failed"); } diff --git a/src/modules/style/winapi_color.rs b/src/modules/style/winapi_color.rs index 0c2246c..8111c20 100644 --- a/src/modules/style/winapi_color.rs +++ b/src/modules/style/winapi_color.rs @@ -101,6 +101,10 @@ impl ITerminalColor for WinApiColor { Color::DarkCyan => fg_green | fg_blue, Color::Grey => fg_intensity, Color::White => 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.*/ + Color::Rgb{ r, g, b } => { 0 } + Color::AnsiValue(val) => { 0 } }; } ColorType::Background => { @@ -120,6 +124,10 @@ impl ITerminalColor for WinApiColor { Color::DarkCyan => bg_green | bg_blue, Color::Grey => bg_intensity, Color::White => bg_intensity | 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.*/ + Color::Rgb{ r, g, b } => { 0 } + Color::AnsiValue(val) => { 0 } }; } };