Added Support For Chars Colors (#386)
This commit is contained in:
parent
007063896e
commit
49fefd6e8f
@ -1,3 +1,6 @@
|
|||||||
|
# Version 0.16.1
|
||||||
|
- Add support for converting chars to StylizedContent
|
||||||
|
|
||||||
# Version 0.16.0
|
# Version 0.16.0
|
||||||
- Make terminal size function work on `/dev/tty` instead of `STDOUT_FILENO`.
|
- Make terminal size function work on `/dev/tty` instead of `STDOUT_FILENO`.
|
||||||
- Change attribute vector in `ContentStyle` to bitmask.
|
- Change attribute vector in `ContentStyle` to bitmask.
|
||||||
|
52
src/style.rs
52
src/style.rs
@ -197,6 +197,44 @@ impl Colorize<&'static str> for &'static str {
|
|||||||
def_str_color!(background_color: on_grey => Color::Grey);
|
def_str_color!(background_color: on_grey => Color::Grey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Colorize<char> for char {
|
||||||
|
// foreground colors
|
||||||
|
def_char_color!(foreground_color: black => Color::Black);
|
||||||
|
def_char_color!(foreground_color: dark_grey => Color::DarkGrey);
|
||||||
|
def_char_color!(foreground_color: red => Color::Red);
|
||||||
|
def_char_color!(foreground_color: dark_red => Color::DarkRed);
|
||||||
|
def_char_color!(foreground_color: green => Color::Green);
|
||||||
|
def_char_color!(foreground_color: dark_green => Color::DarkGreen);
|
||||||
|
def_char_color!(foreground_color: yellow => Color::Yellow);
|
||||||
|
def_char_color!(foreground_color: dark_yellow => Color::DarkYellow);
|
||||||
|
def_char_color!(foreground_color: blue => Color::Blue);
|
||||||
|
def_char_color!(foreground_color: dark_blue => Color::DarkBlue);
|
||||||
|
def_char_color!(foreground_color: magenta => Color::Magenta);
|
||||||
|
def_char_color!(foreground_color: dark_magenta => Color::DarkMagenta);
|
||||||
|
def_char_color!(foreground_color: cyan => Color::Cyan);
|
||||||
|
def_char_color!(foreground_color: dark_cyan => Color::DarkCyan);
|
||||||
|
def_char_color!(foreground_color: white => Color::White);
|
||||||
|
def_char_color!(foreground_color: grey => Color::Grey);
|
||||||
|
|
||||||
|
// background colors
|
||||||
|
def_char_color!(background_color: on_black => Color::Black);
|
||||||
|
def_char_color!(background_color: on_dark_grey => Color::DarkGrey);
|
||||||
|
def_char_color!(background_color: on_red => Color::Red);
|
||||||
|
def_char_color!(background_color: on_dark_red => Color::DarkRed);
|
||||||
|
def_char_color!(background_color: on_green => Color::Green);
|
||||||
|
def_char_color!(background_color: on_dark_green => Color::DarkGreen);
|
||||||
|
def_char_color!(background_color: on_yellow => Color::Yellow);
|
||||||
|
def_char_color!(background_color: on_dark_yellow => Color::DarkYellow);
|
||||||
|
def_char_color!(background_color: on_blue => Color::Blue);
|
||||||
|
def_char_color!(background_color: on_dark_blue => Color::DarkBlue);
|
||||||
|
def_char_color!(background_color: on_magenta => Color::Magenta);
|
||||||
|
def_char_color!(background_color: on_dark_magenta => Color::DarkMagenta);
|
||||||
|
def_char_color!(background_color: on_cyan => Color::Cyan);
|
||||||
|
def_char_color!(background_color: on_dark_cyan => Color::DarkCyan);
|
||||||
|
def_char_color!(background_color: on_white => Color::White);
|
||||||
|
def_char_color!(background_color: on_grey => Color::Grey);
|
||||||
|
}
|
||||||
|
|
||||||
impl Styler<&'static str> for &'static str {
|
impl Styler<&'static str> for &'static str {
|
||||||
def_str_attr!(reset => Attribute::Reset);
|
def_str_attr!(reset => Attribute::Reset);
|
||||||
def_str_attr!(bold => Attribute::Bold);
|
def_str_attr!(bold => Attribute::Bold);
|
||||||
@ -211,6 +249,20 @@ impl Styler<&'static str> for &'static str {
|
|||||||
def_str_attr!(crossed_out => Attribute::CrossedOut);
|
def_str_attr!(crossed_out => Attribute::CrossedOut);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Styler<char> for char {
|
||||||
|
def_char_attr!(reset => Attribute::Reset);
|
||||||
|
def_char_attr!(bold => Attribute::Bold);
|
||||||
|
def_char_attr!(underlined => Attribute::Underlined);
|
||||||
|
def_char_attr!(reverse => Attribute::Reverse);
|
||||||
|
def_char_attr!(dim => Attribute::Dim);
|
||||||
|
def_char_attr!(italic => Attribute::Italic);
|
||||||
|
def_char_attr!(negative => Attribute::Reverse);
|
||||||
|
def_char_attr!(slow_blink => Attribute::SlowBlink);
|
||||||
|
def_char_attr!(rapid_blink => Attribute::RapidBlink);
|
||||||
|
def_char_attr!(hidden => Attribute::Hidden);
|
||||||
|
def_char_attr!(crossed_out => Attribute::CrossedOut);
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns available color count.
|
/// Returns available color count.
|
||||||
///
|
///
|
||||||
/// # Notes
|
/// # Notes
|
||||||
|
@ -34,6 +34,20 @@ macro_rules! def_str_color {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
macro_rules! def_char_color {
|
||||||
|
($side:ident: $name:ident => $color:path) => {
|
||||||
|
fn $name(self) -> StyledContent<char> {
|
||||||
|
StyledContent::new(
|
||||||
|
ContentStyle {
|
||||||
|
$side: Some($color),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
self
|
||||||
|
)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
macro_rules! def_str_attr {
|
macro_rules! def_str_attr {
|
||||||
($name:ident => $attr:path) => {
|
($name:ident => $attr:path) => {
|
||||||
fn $name(self) -> StyledContent<&'static str> {
|
fn $name(self) -> StyledContent<&'static str> {
|
||||||
@ -47,3 +61,17 @@ macro_rules! def_str_attr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
macro_rules! def_char_attr {
|
||||||
|
($name:ident => $attr:path) => {
|
||||||
|
fn $name(self) -> StyledContent<char> {
|
||||||
|
StyledContent::new(
|
||||||
|
ContentStyle {
|
||||||
|
attributes: $attr.into(),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
self
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user