on master help sign in
Ignore enable_ansi_support errors

- Call `enable_ansi_support` only once. - Ignore errors that appear when trying to enable ANSI support. This will hopefully fix #252 and #264

commit7b803a50af9ed4eeebd2f48f62c878c181c07a3e authorsharkdp <davidpeter@web.de> dateMon 3 Sep 2018, 20:47 (8 years ago) parent67ec5fe
1 file changed+8−13
src/app.rs+8−13
src/app.rs+8−13
@@ -84,10 +84,10 @@ pub struct App {
8484
8585impl App {
8686 pub fn new() -> Self {
87− let interactive_output = atty::is(Stream::Stdout);
88−
8987 #[cfg(windows)]
90− let interactive_output = interactive_output && ansi_term::enable_ansi_support().is_ok();
88+ let _ = ansi_term::enable_ansi_support();
89+
90+ let interactive_output = atty::is(Stream::Stdout);
9191
9292 App {
9393 matches: Self::matches(interactive_output),
@@ -335,15 +335,6 @@ impl App {
335335 pub fn config(&self) -> Result<Config> {
336336 let files = self.files();
337337
338− let colored_output = match self.matches.value_of("color") {
339− Some("always") => true,
340− Some("never") => false,
341− Some("auto") | _ => self.interactive_output,
342− };
343−
344− #[cfg(windows)]
345− let colored_output = colored_output && ansi_term::enable_ansi_support().is_ok();
346−
347338 Ok(Config {
348339 true_color: is_truecolor_terminal(),
349340 output_components: self.output_components()?,
@@ -358,7 +349,11 @@ impl App {
358349 Some("never") | _ => OutputWrap::None,
359350 }
360351 },
361− colored_output,
352+ colored_output: match self.matches.value_of("color") {
353+ Some("always") => true,
354+ Some("never") => false,
355+ Some("auto") | _ => self.interactive_output,
356+ },
362357 paging_mode: match self.matches.value_of("paging") {
363358 Some("always") => PagingMode::Always,
364359 Some("never") => PagingMode::Never,