From a3e3916daa1a56fec093020e22cb1f9e2293ed71 Mon Sep 17 00:00:00 2001 From: Jeremy <51220084+jeremy-rifkin@users.noreply.github.com> Date: Sun, 4 Feb 2024 13:49:10 -0600 Subject: [PATCH] Fix issue with trying to call detail::enable_virtual_terminal_processing_if_needed unconditionally on print --- src/cpptrace.cpp | 6 +++++- src/ctrace.cpp | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/cpptrace.cpp b/src/cpptrace.cpp index acd7fc3..d69a2c2 100644 --- a/src/cpptrace.cpp +++ b/src/cpptrace.cpp @@ -167,7 +167,11 @@ namespace cpptrace { } void stacktrace::print(std::ostream& stream, bool color, bool newline_at_end, const char* header) const { - if(color) { + if( + color && ( + (&stream == &std::cout && isatty(stdout_fileno)) || (&stream == &std::cerr && isatty(stderr_fileno)) + ) + ) { detail::enable_virtual_terminal_processing_if_needed(); } stream<<(header ? header : "Stack trace (most recent call first):")<count == 0 || !trace->frames) { ctrace::ffprintf(to, "\n");