Consider color when printing squeeze indicator

When color option has been set to never, the squeeze indicator
character asterisk '*' should not be printed in color.

Fixes #63
This commit is contained in:
Armin Widegreen authored and David Peter committed 2019-05-30 15:29:37 +02:00
1 parent def066ff92
commit c4028bb213
1 file changed
+7 -2
+7 -2
View File
@@ -16,8 +16,8 @@ use clap::{App, AppSettings, Arg};
use ansi_term::Color; use ansi_term::Color;
use ansi_term::Color::Fixed; use ansi_term::Color::Fixed;
use atty::Stream;
use crate::squeezer::{SqueezeAction, Squeezer}; use crate::squeezer::{SqueezeAction, Squeezer};
use atty::Stream;
const BUFFER_SIZE: usize = 256; const BUFFER_SIZE: usize = 256;
@@ -369,10 +369,15 @@ impl<'a> Printer<'a> {
SqueezeAction::Print => { SqueezeAction::Print => {
self.buffer_line.clear(); self.buffer_line.clear();
let style = COLOR_OFFSET.normal(); let style = COLOR_OFFSET.normal();
let asterisk = if self.show_color {
format!("{}", style.paint("*"))
} else {
String::from("*")
};
let _ = writeln!( let _ = writeln!(
&mut self.buffer_line, &mut self.buffer_line,
"{5}{0}{1:2$}{5}{1:3$}{6}{1:3$}{5}{1:4$}{6}{1:4$}{5}", "{5}{0}{1:2$}{5}{1:3$}{6}{1:3$}{5}{1:4$}{6}{1:4$}{5}",
style.paint("*"), asterisk,
"", "",
7, 7,
25, 25,