use memory_buffer to make color print behave atomic #1348
This commit is contained in:
parent
a1079e9fd6
commit
3ce69f4ca5
@ -504,24 +504,32 @@ template <typename S, typename Char = char_t<S> >
|
|||||||
void vprint(std::FILE* f, const text_style& ts, const S& format,
|
void vprint(std::FILE* f, const text_style& ts, const S& format,
|
||||||
basic_format_args<buffer_context<Char> > args) {
|
basic_format_args<buffer_context<Char> > args) {
|
||||||
bool has_style = false;
|
bool has_style = false;
|
||||||
|
basic_memory_buffer<Char> buf;
|
||||||
if (ts.has_emphasis()) {
|
if (ts.has_emphasis()) {
|
||||||
has_style = true;
|
has_style = true;
|
||||||
internal::fputs<Char>(internal::make_emphasis<Char>(ts.get_emphasis()), f);
|
auto emphasis = internal::make_emphasis<Char>(ts.get_emphasis());
|
||||||
|
buf.append(emphasis.begin(), emphasis.end());
|
||||||
}
|
}
|
||||||
if (ts.has_foreground()) {
|
if (ts.has_foreground()) {
|
||||||
has_style = true;
|
has_style = true;
|
||||||
internal::fputs<Char>(
|
auto foreground = internal::make_foreground_color<Char>(ts.get_foreground());
|
||||||
internal::make_foreground_color<Char>(ts.get_foreground()), f);
|
buf.append(foreground.begin(), foreground.end());
|
||||||
}
|
}
|
||||||
if (ts.has_background()) {
|
if (ts.has_background()) {
|
||||||
has_style = true;
|
has_style = true;
|
||||||
internal::fputs<Char>(
|
auto background = internal::make_background_color<Char>(ts.get_background());
|
||||||
internal::make_background_color<Char>(ts.get_background()), f);
|
buf.append(background.begin(), background.end());
|
||||||
}
|
}
|
||||||
vprint(f, format, args);
|
|
||||||
|
format_to( buf, "{}", format );
|
||||||
|
|
||||||
if (has_style) {
|
if (has_style) {
|
||||||
internal::reset_color<Char>(f);
|
size_t retset_color_char_count = sizeof( internal::data::reset_color ) / (*internal::data::reset_color);
|
||||||
|
buf.append(internal::data::reset_color, internal::data::reset_color + retset_color_char_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
vprint(f, buf.data(), args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user