Skip to content

Commit

Permalink
Support color256 in from_dotted_str()
Browse files Browse the repository at this point in the history
 * `<n>` => `color256(n)`
 * `on_<n>` => `on_color256(n)`

Signed-off-by: Mohammad AlSaleh <CE.Mohammad.AlSaleh@gmail.com>
  • Loading branch information
MoSal committed May 14, 2021
1 parent 278de9d commit 8026191
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,9 @@ impl Style {
///
/// Effectively the string is split at each dot and then the
/// terms in between are applied. For instance `red.on_blue` will
/// create a string that is red on blue background. Unknown terms
/// are ignored.
/// create a string that is red on blue background. `9.on_12` is
/// the same, but using 256 color numbers. Unknown terms are
/// ignored.
pub fn from_dotted_str(s: &str) -> Style {
let mut rv = Style::new();
for part in s.split('.') {
Expand Down Expand Up @@ -214,9 +215,16 @@ impl Style {
"blink" => rv.blink(),
"reverse" => rv.reverse(),
"hidden" => rv.hidden(),
_ => {
on_c if on_c.starts_with("on_") => if let Some(n) = on_c[3..].parse::<u8>().ok() {
rv.on_color256(n)
} else {
continue;
}
},
c => if let Some(n) = c.parse::<u8>().ok() {
rv.color256(n)
} else {
continue;
},
};
}
rv
Expand Down

0 comments on commit 8026191

Please sign in to comment.