From 1b663051b5603cb9f64735f3f35efabbf7d434f3 Mon Sep 17 00:00:00 2001 From: rbrugo Date: Tue, 8 Mar 2022 16:11:07 +0100 Subject: [PATCH] Use the iterator instead of the buffer in styled_arg::format --- include/fmt/color.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/include/fmt/color.h b/include/fmt/color.h index e5a487bf..cf701002 100644 --- a/include/fmt/color.h +++ b/include/fmt/color.h @@ -644,29 +644,29 @@ struct formatter, Char> : formatter { const auto& value = arg.value; auto out = ctx.out(); - using detail::get_buffer; - auto&& buf = get_buffer(out); - bool has_style = false; if (ts.has_emphasis()) { has_style = true; auto emphasis = detail::make_emphasis(ts.get_emphasis()); - buf.append(emphasis.begin(), emphasis.end()); + out = std::copy(emphasis.begin(), emphasis.end(), out); } if (ts.has_foreground()) { has_style = true; auto foreground = detail::make_foreground_color(ts.get_foreground()); - buf.append(foreground.begin(), foreground.end()); + out = std::copy(foreground.begin(), foreground.end(), out); } if (ts.has_background()) { has_style = true; auto background = detail::make_background_color(ts.get_background()); - buf.append(background.begin(), background.end()); + out = std::copy(background.begin(), background.end(), out); } out = formatter::format(value, ctx); - if (has_style) detail::reset_color(buf); + if (has_style) { + auto reset_color = string_view("\x1b[0m"); + out = std::copy(reset_color.begin(), reset_color.end(), out); + } return out; } };