1 use std::io::{self, stdout, Write}; 2 3 use crossterm::{style::*, ExecutableCommand}; 4 5 pub struct StyleManager; 6 7 #[allow(dead_code)] 8 impl StyleManager { 9 #[inline] 10 pub fn set_foreground_color(color: Color) -> io::Result<()> { 11 stdout().execute(SetForegroundColor(color)).unwrap().flush() 12 } 13 14 #[inline] 15 pub fn set_background_color(color: Color) -> io::Result<()> { 16 stdout().execute(SetBackgroundColor(color)).unwrap().flush() 17 } 18 19 #[inline] 20 pub fn set_underline_color(color: Color) -> io::Result<()> { 21 stdout().execute(SetUnderlineColor(color)).unwrap().flush() 22 } 23 24 #[inline] 25 pub fn set_color(fg: Option<Color>, bg: Option<Color>) -> io::Result<()> { 26 stdout() 27 .execute(SetColors(Colors { 28 foreground: fg, 29 background: bg, 30 })) 31 .unwrap() 32 .flush() 33 } 34 35 #[inline] 36 pub fn set_attr(attr: Attribute) -> io::Result<()> { 37 stdout().execute(SetAttribute(attr)).unwrap().flush() 38 } 39 40 #[inline] 41 pub fn set_attrs(attr: Attributes) -> io::Result<()> { 42 stdout().execute(SetAttributes(attr)).unwrap().flush() 43 } 44 45 #[inline] 46 pub fn set_style(style: ContentStyle) -> io::Result<()> { 47 stdout().execute(SetStyle(style)).unwrap().flush() 48 } 49 50 #[inline] 51 pub fn reset_color() -> io::Result<()> { 52 stdout().execute(ResetColor).unwrap().flush() 53 } 54 } 55