pub struct TerminalStyle { /* private fields */ }
Expand description
Stores a custom style for terminal text. This creates the escape command needed to change terminal text color. ANSI Escape Codes
§Examples
use terminal_text_styler::{TerminalStyle, SGREffect, ANSIForegroundColor};
// Manual with codes
let yellow_manual = TerminalStyle::from(vec![0, 93]);
// Using enums
let yellow = TerminalStyle::new(vec![SGREffect::Normal], Some(ANSIForegroundColor::BrightYellow), None);
let no_color = TerminalStyle::new_empty();
assert_eq!(yellow.command(), "\u{001B}[0;93m");
assert_eq!(no_color.command(), "\u{001B}[0m");
assert_eq!(yellow.wrap("Hello, World!"), "\u{001B}[0;93mHello, World!\u{001B}[0m");
Implementations§
Source§impl TerminalStyle
impl TerminalStyle
Sourcepub fn foreground(&self) -> Option<ANSIForegroundColor>
pub fn foreground(&self) -> Option<ANSIForegroundColor>
Looks up the foreground color (Note: This is not supported for ANSI 256-colors and will return None
)
Sourcepub fn background(&self) -> Option<ANSIBackgroundColor>
pub fn background(&self) -> Option<ANSIBackgroundColor>
Looks up the background color (Note: This is not supported for ANSI 256-colors and will return None
)
Sourcepub fn new(
effects: Vec<SGREffect>,
foreground: Option<ANSIForegroundColor>,
background: Option<ANSIBackgroundColor>,
) -> Self
pub fn new( effects: Vec<SGREffect>, foreground: Option<ANSIForegroundColor>, background: Option<ANSIBackgroundColor>, ) -> Self
Creates a new terminal color with given options.
Sourcepub fn wrap(&self, text: &str) -> String
pub fn wrap(&self, text: &str) -> String
Wraps given text with a command to start the custom color at the beginning and ends the string with a no-color command.
§Examples
use terminal_text_styler::{TerminalStyle, SGREffect, ANSIForegroundColor};
let style = TerminalStyle::new(vec![SGREffect::Bold], Some(ANSIForegroundColor::BrightYellow), None);
let output = style.wrap("This will be bold and highlighted in bright yellow.");
println!("{}", output);
Source§impl TerminalStyle
impl TerminalStyle
pub fn no_color() -> Self
pub fn reset() -> Self
pub fn black() -> Self
pub fn red() -> Self
pub fn green() -> Self
pub fn yellow() -> Self
pub fn blue() -> Self
pub fn magenta() -> Self
pub fn cyan() -> Self
pub fn white() -> Self
pub fn bright_black() -> Self
pub fn bright_red() -> Self
pub fn bright_green() -> Self
pub fn bright_yellow() -> Self
pub fn bright_blue() -> Self
pub fn bright_magenta() -> Self
pub fn bright_cyan() -> Self
pub fn bright_white() -> Self
pub fn italic_black() -> Self
pub fn italic_red() -> Self
pub fn italic_green() -> Self
pub fn italic_yellow() -> Self
pub fn italic_blue() -> Self
pub fn italic_magenta() -> Self
pub fn italic_cyan() -> Self
pub fn italic_white() -> Self
pub fn red_background() -> Self
pub fn blue_background() -> Self
pub fn green_background() -> Self
pub fn yellow_background() -> Self
pub fn normal_bright_yellow() -> Self
pub fn blink() -> Self
Trait Implementations§
Source§impl Clone for TerminalStyle
impl Clone for TerminalStyle
Source§impl Debug for TerminalStyle
impl Debug for TerminalStyle
Source§impl Display for TerminalStyle
impl Display for TerminalStyle
Source§impl PartialEq for TerminalStyle
impl PartialEq for TerminalStyle
impl Eq for TerminalStyle
Auto Trait Implementations§
impl Freeze for TerminalStyle
impl RefUnwindSafe for TerminalStyle
impl Send for TerminalStyle
impl Sync for TerminalStyle
impl Unpin for TerminalStyle
impl UnwindSafe for TerminalStyle
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more