Skip to content

Commit

Permalink
Allow more zero padding in ANSI code parsing
Browse files Browse the repository at this point in the history
Fixes #352
  • Loading branch information
ogham committed Oct 8, 2018
1 parent a4d9b53 commit ce3f05c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/style/lsc.rs
Expand Up @@ -49,11 +49,11 @@ impl<'var> Pair<'var> {
let mut iter = self.value.split(";").peekable();

while let Some(num) = iter.next() {
match num {
match num.trim_left_matches('0') {

// Bold and italic
"1" | "01" => style = style.bold(),
"4" | "04" => style = style.underline(),
"1" => style = style.bold(),
"4" => style = style.underline(),

// Foreground colours
"30" => style = style.fg(Black),
Expand Down Expand Up @@ -102,11 +102,15 @@ mod ansi_test {

// Styles
test!(bold: "1" => Style::default().bold());
test!(bold2: "01" => Style::default().bold());
test!(under: "4" => Style::default().underline());
test!(unde2: "04" => Style::default().underline());
test!(both: "1;4" => Style::default().bold().underline());
test!(both2: "01;04" => Style::default().bold().underline());
test!(fg: "31" => Red.normal());
test!(bg: "43" => Style::default().on(Yellow));
test!(bfg: "31;43" => Red.on(Yellow));
test!(bfg2: "0031;0043" => Red.on(Yellow));
test!(all: "43;31;1;4" => Red.on(Yellow).bold().underline());
test!(again: "1;1;1;1;1" => Style::default().bold());

Expand Down

0 comments on commit ce3f05c

Please sign in to comment.