diff --git a/examples/ratatui.rs b/examples/ratatui.rs index b5c506c..ec8e985 100644 --- a/examples/ratatui.rs +++ b/examples/ratatui.rs @@ -15,7 +15,7 @@ fn main() -> io::Result<()> { }, )?; for flavor in &PALETTE { - terminal.insert_before(4, |buf| { + terminal.insert_before(8, |buf| { let analogous: Vec = flavor .colors .into_iter() @@ -28,11 +28,25 @@ fn main() -> io::Result<()> { .filter(|c| !c.accent) .map(|c| "██".fg(*c)) // fg accepts any type that implements Into .collect(); + let ansi_normals: Vec = flavor + .ansi_colors + .into_iter() + .map(|c| "██".fg(c.normal)) // fg accepts any type that implements Into + .collect::>(); + let ansi_brights: Vec = flavor + .ansi_colors + .into_iter() + .map(|c| "██".fg(c.bright)) // fg accepts any type that implements Into + .collect::>(); let width = buf.area.width; Paragraph::new(flavor.name.to_string()).render(Rect::new(0, 0, width, 1), buf); Paragraph::new(Line::from(analogous)).render(Rect::new(0, 1, width, 1), buf); Paragraph::new(Line::from(monochromatic)).render(Rect::new(0, 2, width, 1), buf); + Paragraph::new(format!("{} ANSI", flavor.name.to_string())) + .render(Rect::new(0, 4, width, 1), buf); + Paragraph::new(Line::from(ansi_normals)).render(Rect::new(0, 5, width, 1), buf); + Paragraph::new(Line::from(ansi_brights)).render(Rect::new(0, 6, width, 1), buf); })?; } diff --git a/src/lib.rs b/src/lib.rs index 3f45e79..07b17ee 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -541,8 +541,18 @@ impl Color { } #[cfg(feature = "ratatui")] -impl From for ratatui::style::Color { - fn from(value: Color) -> Self { - Self::Rgb(value.rgb.r, value.rgb.g, value.rgb.b) +mod ratatui { + use crate::{AnsiColor, Color}; + + impl From for ratatui::style::Color { + fn from(value: Color) -> Self { + Self::Rgb(value.rgb.r, value.rgb.g, value.rgb.b) + } + } + + impl From for ratatui::style::Color { + fn from(value: AnsiColor) -> Self { + Self::Rgb(value.rgb.r, value.rgb.g, value.rgb.b) + } } }