mirror of
https://github.com/google/benchmark.git
synced 2024-12-26 20:40:21 +08:00
Issue1731 created console does not receive output (#1732)
* Instead of directly comparing std::cout and GetOutputStream(), the underlying buffers are retreived via rdbuf(), and then compared. * Instead of fflush(stdout), call out.flush(). Use out << FormatString() instead of vprintf --------- Co-authored-by: dominic <510002+dmah42@users.noreply.github.com>
This commit is contained in:
parent
4575fc415f
commit
e61e332df9
@ -140,12 +140,12 @@ void ColorPrintf(std::ostream& out, LogColor color, const char* fmt,
|
|||||||
// We need to flush the stream buffers into the console before each
|
// We need to flush the stream buffers into the console before each
|
||||||
// SetConsoleTextAttribute call lest it affect the text that is already
|
// SetConsoleTextAttribute call lest it affect the text that is already
|
||||||
// printed but has not yet reached the console.
|
// printed but has not yet reached the console.
|
||||||
fflush(stdout);
|
out.flush();
|
||||||
SetConsoleTextAttribute(stdout_handle,
|
SetConsoleTextAttribute(stdout_handle,
|
||||||
GetPlatformColorCode(color) | FOREGROUND_INTENSITY);
|
GetPlatformColorCode(color) | FOREGROUND_INTENSITY);
|
||||||
vprintf(fmt, args);
|
out << FormatString(fmt, args);
|
||||||
|
|
||||||
fflush(stdout);
|
out.flush();
|
||||||
// Restores the text color.
|
// Restores the text color.
|
||||||
SetConsoleTextAttribute(stdout_handle, old_color_attrs);
|
SetConsoleTextAttribute(stdout_handle, old_color_attrs);
|
||||||
#else
|
#else
|
||||||
|
@ -42,11 +42,15 @@ bool ConsoleReporter::ReportContext(const Context& context) {
|
|||||||
PrintBasicContext(&GetErrorStream(), context);
|
PrintBasicContext(&GetErrorStream(), context);
|
||||||
|
|
||||||
#ifdef BENCHMARK_OS_WINDOWS
|
#ifdef BENCHMARK_OS_WINDOWS
|
||||||
if ((output_options_ & OO_Color) && &std::cout != &GetOutputStream()) {
|
if ((output_options_ & OO_Color)) {
|
||||||
GetErrorStream()
|
auto stdOutBuf = std::cout.rdbuf();
|
||||||
<< "Color printing is only supported for stdout on windows."
|
auto outStreamBuf = GetOutputStream().rdbuf();
|
||||||
" Disabling color printing\n";
|
if (stdOutBuf != outStreamBuf) {
|
||||||
output_options_ = static_cast<OutputOptions>(output_options_ & ~OO_Color);
|
GetErrorStream()
|
||||||
|
<< "Color printing is only supported for stdout on windows."
|
||||||
|
" Disabling color printing\n";
|
||||||
|
output_options_ = static_cast<OutputOptions>(output_options_ & ~OO_Color);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user