diff options
author | Ezinwa Okpoechi <brainmaestro@outlook.com> | 2018-05-05 15:55:16 +0200 |
---|---|---|
committer | David Peter <sharkdp@users.noreply.github.com> | 2018-05-06 14:47:53 +0200 |
commit | d4553c6b386c2c71a9a177c3cdcb530eaf7ec59b (patch) | |
tree | 5573a5f38a5dc21114b1dee5a24c0f2de58b84eb /src/terminal.rs | |
parent | 23d92d7641ed81d92fc3d758bb7351a8f29964fa (diff) |
Add color flag
Colors are disabled if the terminal is not interactive unless explicitly
set otherwise
Diffstat (limited to 'src/terminal.rs')
-rw-r--r-- | src/terminal.rs | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/terminal.rs b/src/terminal.rs index 660c16e1..0e26376b 100644 --- a/src/terminal.rs +++ b/src/terminal.rs @@ -1,5 +1,6 @@ use std::fmt::Write; +use ansi_term::Style; use ansi_term::Colour::{Fixed, RGB}; use syntect::highlighting; @@ -25,14 +26,16 @@ fn rgb2ansi(r: u8, g: u8, b: u8) -> u8 { } } -pub fn as_terminal_escaped(v: &[(highlighting::Style, &str)], true_color: bool) -> String { +pub fn as_terminal_escaped(v: &[(highlighting::Style, &str)], true_color: bool, colored: bool) -> String { let mut s: String = String::new(); for &(ref style, text) in v.iter() { - let style = if true_color { - RGB(style.foreground.r, style.foreground.g, style.foreground.b) + let style = if !colored { + Style::default() + } else if true_color { + RGB(style.foreground.r, style.foreground.g, style.foreground.b).normal() } else { let ansi = rgb2ansi(style.foreground.r, style.foreground.g, style.foreground.b); - Fixed(ansi) + Fixed(ansi).normal() }; write!(s, "{}", style.paint(text)).unwrap(); |