From 770056e84712ff9c152f135aa695ef2f65d094eb Mon Sep 17 00:00:00 2001 From: Malte Tammena Date: Sun, 24 Oct 2021 18:08:25 +0200 Subject: [PATCH] Redo color disable on windows --- src/main.rs | 45 ++++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/src/main.rs b/src/main.rs index 0bb0720..39619c6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -74,25 +74,40 @@ use tracing::error; /// /// This will colorize for Stdout based on heuristics and colors /// from the [`owo_colors`] library. +/// +/// **Windows**: Automatic color defaults to no color at the moment! +// TODO: Make colors work on windows macro_rules! color { ($what:expr; $($fn:ident),+) => { { - use owo_colors::{OwoColorize, Stream}; - use crate::config::args::ColorWhen; - match crate::config::CONF.args.color { - ColorWhen::Always => { - $what $(. $fn())+ .to_string() + #[cfg(not(windows))] + { + use owo_colors::{OwoColorize, Stream}; + use crate::config::args::ColorWhen; + match crate::config::CONF.args.color { + ColorWhen::Always => { + $what $(. $fn())+ .to_string() + } + ColorWhen::Automatic => { + $what.if_supports_color(Stream::Stdout, + |txt| txt $(. $fn().to_string())+).to_string() + } + ColorWhen::Never => { + $what.to_string() + } } - ColorWhen::Automatic => { - // TODO: Colors don't seem to work on windows - #[cfg(not(windows))] - { $what.if_supports_color(Stream::Stdout, - |txt| txt $(. $fn().to_string())+).to_string() } - #[cfg(windows)] - $what.to_string() - } - ColorWhen::Never => { - $what.to_string() + } + #[cfg(windows)] + { + use owo_colors::{OwoColorize}; + use crate::config::args::ColorWhen; + match crate::config::CONF.args.color { + ColorWhen::Always => { + $what $(. $fn())+ .to_string() + } + ColorWhen::Automatic | ColorWhen::Never => { + $what.to_string() + } } } }