From 2cf540ebfdc63508c7012a77c4510d4d9fe7d5a0 Mon Sep 17 00:00:00 2001 From: RuboGubo Date: Mon, 15 Jul 2024 23:08:52 +0100 Subject: [PATCH] use the rgb crate instead of own struct closes #173 --- Cargo.toml | 1 + src/customcolors.rs | 45 --------------------------------------------- src/lib.rs | 8 ++++---- 3 files changed, 5 insertions(+), 49 deletions(-) delete mode 100644 src/customcolors.rs diff --git a/Cargo.toml b/Cargo.toml index 97f9eb7..5897a73 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,7 @@ no-color = [] [dependencies] lazy_static = "1" +rgb = "0.8" [target.'cfg(windows)'.dependencies.windows-sys] version = "0.48" diff --git a/src/customcolors.rs b/src/customcolors.rs deleted file mode 100644 index 049d211..0000000 --- a/src/customcolors.rs +++ /dev/null @@ -1,45 +0,0 @@ -/// Custom color structure, it will generate a true color in the result -#[derive(Debug, Copy, Clone, PartialEq, Eq)] -pub struct CustomColor { - /// Red - pub r: u8, - /// Green - pub g: u8, - /// Blue - pub b: u8, -} - -/// This only makes custom color creation easier. -impl CustomColor { - /// Create a new custom color - pub fn new(r: u8, g: u8, b: u8) -> Self { - Self { r, g, b } - } -} - -impl From<(u8, u8, u8)> for CustomColor { - fn from((r, g, b): (u8, u8, u8)) -> Self { - Self::new(r, g, b) - } -} - -#[cfg(test)] -mod tests { - use crate::*; - #[cfg_attr(feature = "no-color", ignore)] - #[test] - fn main() { - let my_color = CustomColor::new(0, 120, 120); - insta::assert_display_snapshot!("Greetings from Ukraine".custom_color(my_color)); - } - - #[test] - fn from_tuple() { - let tuple = (1u8, 255u8, 0u8); - let cc = CustomColor::from(tuple); - - assert_eq!(cc.r, tuple.0); - assert_eq!(cc.g, tuple.1); - assert_eq!(cc.b, tuple.2); - } -} diff --git a/src/lib.rs b/src/lib.rs index 6942868..f527a62 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -40,10 +40,10 @@ pub mod control; mod error; mod style; -pub use self::customcolors::CustomColor; +pub use rgb::RGB; /// Custom colors support. -pub mod customcolors; +pub use rgb; pub use color::*; @@ -261,7 +261,7 @@ pub trait Colorize { fn custom_color(self, color: T) -> ColoredString where Self: Sized, - T: Into, + T: Into>, { let color = color.into(); @@ -390,7 +390,7 @@ pub trait Colorize { fn on_custom_color(self, color: T) -> ColoredString where Self: Sized, - T: Into, + T: Into>, { let color = color.into();