From 35510be63b5e1ab113fb2f48ef191e17de21de1e Mon Sep 17 00:00:00 2001 From: Nicolas Lesser Date: Sun, 9 Dec 2018 16:32:31 +0100 Subject: [PATCH] Disable printing the reset escape code when no style modifiers where applied. --- include/fmt/color.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/include/fmt/color.h b/include/fmt/color.h index 20399210..80798a0c 100644 --- a/include/fmt/color.h +++ b/include/fmt/color.h @@ -429,20 +429,26 @@ template < typename S, typename Char = typename internal::char_t::type> void vprint(const text_style &tf, const S &format, basic_format_args::type> args) { + bool has_style = false; if (tf.has_emphasis()) { + has_style = true; internal::fputs( internal::make_emphasis(tf.get_emphasis()), stdout); } if (tf.has_foreground()) { + has_style = true; internal::fputs( internal::make_foreground_color(tf.get_foreground()), stdout); } if (tf.has_background()) { + has_style = true; internal::fputs( internal::make_background_color(tf.get_background()), stdout); } vprint(format, args); - internal::reset_color(stdout); + if (has_style) { + internal::reset_color(stdout); + } } /**