3737//!
3838//! Example: [`examples/term_grid.rs`](https://github.com/catppuccin/rust/blob/main/examples/term_grid.rs)
3939//!
40+ //! ### Bevy
41+ //!
42+ //! Enable the `bevy` feature to enable the conversion of Catppuccin colors to
43+ //! [`bevy::prelude::Color`] instances.
44+ //! This adds [bevy](https://crates.io/crates/bevy) as a dependency.
45+ //!
46+ //! Example: [`examples/bevy.rs`](https://github.com/catppuccin/rust/blob/main/examples/bevy.rs)
47+ //!
4048//! ### CSS colors
4149//!
4250//! Enable the `css-colors` feature to enable the conversion of Catppuccin colors to
4553//!
4654//! Example: [`examples/css.rs`](https://github.com/catppuccin/rust/blob/main/examples/css.rs)
4755//!
56+ //! ### Iced
57+ //!
58+ //! Enable the `iced` feature to enable the conversion of Catppuccin colors to
59+ //! [`iced::Color`] instances.
60+ //! This adds [iced](https://crates.io/crates/iced) as a dependency.
61+ //!
62+ //! Example: [`examples/iced.rs`](https://github.com/catppuccin/rust/blob/main/examples/iced.rs)
63+ //!
4864//! ### Ratatui
4965//!
5066//! Enable the `ratatui` feature to enable the conversion of Catppuccin colors to
5369//!
5470//! Example: [`examples/ratatui.rs`](https://github.com/catppuccin/rust/blob/main/examples/ratatui.rs)
5571//!
56- //! ### Bevy
57- //!
58- //! Enable the `bevy` feature to enable the conversion of Catppuccin colors to
59- //! [`bevy::prelude::Color`] instances.
60- //! This adds [bevy](https://crates.io/crates/bevy) as a dependency.
61- //!
62- //! Example: [`examples/bevy.rs`](https://github.com/catppuccin/rust/blob/main/examples/bevy.rs)
63- //!
6472//! ### Serde
6573//!
6674//! Enable the `serde` feature to enable the serialization of Catppuccin's palette,
@@ -559,6 +567,58 @@ impl From<(f64, f64, f64)> for Hsl {
559567 }
560568}
561569
570+ #[ cfg( feature = "ansi-term" ) ]
571+ mod ansi_term {
572+ use crate :: { AnsiColor , Color } ;
573+
574+ impl Color {
575+ /// Paints the given input with a color à la [ansi_term](https://docs.rs/ansi_term/latest/ansi_term/)
576+ pub fn ansi_paint < ' a , I , S : ' a + ToOwned + ?Sized > (
577+ & self ,
578+ input : I ,
579+ ) -> ansi_term:: ANSIGenericString < ' a , S >
580+ where
581+ I : Into < std:: borrow:: Cow < ' a , S > > ,
582+ <S as ToOwned >:: Owned : core:: fmt:: Debug ,
583+ {
584+ ansi_term:: Color :: RGB ( self . rgb . r , self . rgb . g , self . rgb . b ) . paint ( input)
585+ }
586+ }
587+
588+ impl AnsiColor {
589+ /// Paints the given input with a color à la [ansi_term](https://docs.rs/ansi_term/latest/ansi_term/)
590+ pub fn ansi_paint < ' a , I , S : ' a + ToOwned + ?Sized > (
591+ & self ,
592+ input : I ,
593+ ) -> ansi_term:: ANSIGenericString < ' a , S >
594+ where
595+ I : Into < std:: borrow:: Cow < ' a , S > > ,
596+ <S as ToOwned >:: Owned : core:: fmt:: Debug ,
597+ {
598+ ansi_term:: Color :: RGB ( self . rgb . r , self . rgb . g , self . rgb . b ) . paint ( input)
599+ }
600+ }
601+ }
602+
603+ #[ cfg( feature = "bevy" ) ]
604+ mod bevy {
605+ use crate :: { AnsiColor , Color } ;
606+
607+ impl From < Color > for bevy:: prelude:: Color {
608+ fn from ( value : Color ) -> Self {
609+ #[ allow( clippy:: cast_possible_truncation) ]
610+ Self :: hsl ( value. hsl . h as f32 , value. hsl . s as f32 , value. hsl . l as f32 )
611+ }
612+ }
613+
614+ impl From < AnsiColor > for bevy:: prelude:: Color {
615+ fn from ( value : AnsiColor ) -> Self {
616+ #[ allow( clippy:: cast_possible_truncation) ]
617+ Self :: hsl ( value. hsl . h as f32 , value. hsl . s as f32 , value. hsl . l as f32 )
618+ }
619+ }
620+ }
621+
562622#[ cfg( feature = "css-colors" ) ]
563623mod css_colors {
564624 use crate :: { AnsiColor , Color } ;
@@ -606,35 +666,19 @@ mod css_colors {
606666 }
607667}
608668
609- #[ cfg( feature = "ansi-term " ) ]
610- mod ansi_term {
669+ #[ cfg( feature = "iced " ) ]
670+ mod iced {
611671 use crate :: { AnsiColor , Color } ;
612672
613- impl Color {
614- /// Paints the given input with a color à la [ansi_term](https://docs.rs/ansi_term/latest/ansi_term/)
615- pub fn ansi_paint < ' a , I , S : ' a + ToOwned + ?Sized > (
616- & self ,
617- input : I ,
618- ) -> ansi_term:: ANSIGenericString < ' a , S >
619- where
620- I : Into < std:: borrow:: Cow < ' a , S > > ,
621- <S as ToOwned >:: Owned : core:: fmt:: Debug ,
622- {
623- ansi_term:: Color :: RGB ( self . rgb . r , self . rgb . g , self . rgb . b ) . paint ( input)
673+ impl From < Color > for iced:: Color {
674+ fn from ( value : Color ) -> Self {
675+ Self :: from_rgb8 ( value. rgb . r , value. rgb . g , value. rgb . b )
624676 }
625677 }
626678
627- impl AnsiColor {
628- /// Paints the given input with a color à la [ansi_term](https://docs.rs/ansi_term/latest/ansi_term/)
629- pub fn ansi_paint < ' a , I , S : ' a + ToOwned + ?Sized > (
630- & self ,
631- input : I ,
632- ) -> ansi_term:: ANSIGenericString < ' a , S >
633- where
634- I : Into < std:: borrow:: Cow < ' a , S > > ,
635- <S as ToOwned >:: Owned : core:: fmt:: Debug ,
636- {
637- ansi_term:: Color :: RGB ( self . rgb . r , self . rgb . g , self . rgb . b ) . paint ( input)
679+ impl From < AnsiColor > for iced:: Color {
680+ fn from ( value : AnsiColor ) -> Self {
681+ Self :: from_rgb8 ( value. rgb . r , value. rgb . g , value. rgb . b )
638682 }
639683 }
640684}
@@ -655,20 +699,3 @@ mod ratatui {
655699 }
656700 }
657701}
658-
659- #[ cfg( feature = "bevy" ) ]
660- mod bevy {
661- use crate :: { AnsiColor , Color } ;
662-
663- impl From < Color > for bevy:: prelude:: Color {
664- fn from ( value : Color ) -> Self {
665- Self :: hsl ( value. hsl . h as f32 , value. hsl . s as f32 , value. hsl . l as f32 )
666- }
667- }
668-
669- impl From < AnsiColor > for bevy:: prelude:: Color {
670- fn from ( value : AnsiColor ) -> Self {
671- Self :: hsl ( value. hsl . h as f32 , value. hsl . s as f32 , value. hsl . l as f32 )
672- }
673- }
674- }
0 commit comments