diff options
author | Dan Davison <dandavison7@gmail.com> | 2020-06-27 13:55:28 -0400 |
---|---|---|
committer | Dan Davison <dandavison7@gmail.com> | 2020-06-27 14:02:57 -0400 |
commit | aa4b558819ae5882c5a0c37afa736aa1045acef3 (patch) | |
tree | b30b377fb02caea7f4986f2c15f3b2f7adeb9003 | |
parent | 315cc954ab66571b0c576d2ce0e01378535c2c25 (diff) |
Bugfix: inherit style attributes from default style
In particular, plus-non-emph-style was lacking syntax highlighting
prior to this commit.
-rw-r--r-- | src/parse_style.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/parse_style.rs b/src/parse_style.rs index cd018812..e2a57d45 100644 --- a/src/parse_style.rs +++ b/src/parse_style.rs @@ -203,8 +203,12 @@ fn parse_ansi_term_style( let mut style = ansi_term::Style::new(); let mut seen_foreground = false; let mut seen_background = false; + let mut foreground_is_auto = false; + let mut background_is_auto = false; let mut is_omitted = false; let mut is_raw = false; + let mut seen_omit = false; + let mut seen_raw = false; let mut is_syntax_highlighted = false; for word in s .to_lowercase() @@ -222,10 +226,12 @@ fn parse_ansi_term_style( } else if word == "italic" { style.is_italic = true; } else if word == "omit" { + seen_omit = true; is_omitted = true; } else if word == "reverse" { style.is_reverse = true; } else if word == "raw" { + seen_raw = true; is_raw = true; } else if word == "strike" { style.is_strikethrough = true; @@ -235,7 +241,9 @@ fn parse_ansi_term_style( if word == "syntax" { is_syntax_highlighted = true; } else if word == "auto" { + foreground_is_auto = true; style.foreground = default.and_then(|s| s.ansi_term_style.foreground); + is_syntax_highlighted = default.map(|s| s.is_syntax_highlighted).unwrap_or(false); } else { style.foreground = color::color_from_rgb_or_ansi_code_with_default(word, true_color); @@ -250,6 +258,7 @@ fn parse_ansi_term_style( ); process::exit(1); } else if word == "auto" { + background_is_auto = true; style.background = default.and_then(|s| s.ansi_term_style.background); } else { style.background = @@ -264,6 +273,14 @@ fn parse_ansi_term_style( process::exit(1); } } + if foreground_is_auto && background_is_auto { + if !seen_omit { + is_omitted = default.map(|s| s.is_omitted).unwrap_or(false); + } + if !seen_raw { + is_raw = default.map(|s| s.is_raw).unwrap_or(false); + } + } (style, is_omitted, is_raw, is_syntax_highlighted) } |