| 1450 | |
| 1451 | #if defined(DEATH_TRACE) |
| 1452 | void Application::InitializeTrace() |
| 1453 | { |
| 1454 | # if defined(DEATH_TARGET_EMSCRIPTEN) |
| 1455 | char* userAgent = (char*)EM_ASM_PTR({ |
| 1456 | return (typeof navigator !== 'undefined' && navigator !== null && |
| 1457 | typeof navigator.userAgent !== 'undefined' && navigator.userAgent !== null |
| 1458 | ? stringToNewUTF8(navigator.userAgent) : 0); |
| 1459 | }); |
| 1460 | if (userAgent != nullptr) { |
| 1461 | // Only Chrome supports ANSI escape sequences for now |
| 1462 | __consoleType = (::strcasestr(userAgent, "chrome") != nullptr ? ConsoleType::EscapeCodes : ConsoleType::Redirect); |
| 1463 | std::free(userAgent); |
| 1464 | } else { |
| 1465 | __consoleType = ConsoleType::Redirect; |
| 1466 | } |
| 1467 | # elif defined(DEATH_TARGET_APPLE) || defined(DEATH_TARGET_UNIX) |
| 1468 | # if defined(DEATH_TARGET_UNIX) |
| 1469 | ::setvbuf(stdout, nullptr, _IONBF, 0); |
| 1470 | ::setvbuf(stderr, nullptr, _IONBF, 0); |
| 1471 | # endif |
| 1472 | |
| 1473 | // Xcode's console reports that it is a TTY, but it doesn't support colors, TERM is not defined in this case |
| 1474 | __consoleType = ConsoleType::Redirect; |
| 1475 | |
| 1476 | StringView NO_COLOR = ::getenv("NO_COLOR"); |
| 1477 | StringView FORCE_COLOR = ::getenv("FORCE_COLOR"); |
| 1478 | if (NO_COLOR) { |
| 1479 | // Don't use colors if NO_COLOR is set, even if the console supports it |
| 1480 | } else if (::isatty(1)) { |
| 1481 | StringView COLORTERM = ::getenv("COLORTERM"); |
| 1482 | StringView TERM = ::getenv("TERM"); |
| 1483 | |
| 1484 | if (!COLORTERM.empty()) { |
| 1485 | if (COLORTERM.contains("truecolor"_s) || COLORTERM.contains("24bit"_s)) { |
| 1486 | __consoleType = ConsoleType::EscapeCodes24bit; |
| 1487 | CheckConsoleCapabilities(); |
| 1488 | } else if (COLORTERM.contains("256color"_s) || COLORTERM.contains("rxvt-xpm"_s)) { |
| 1489 | __consoleType = ConsoleType::EscapeCodes8bit; |
| 1490 | } |
| 1491 | } |
| 1492 | |
| 1493 | if (__consoleType < ConsoleType::EscapeCodes8bit && !TERM.empty()) { |
| 1494 | if (TERM.contains("256color"_s) || TERM.contains("rxvt-xpm"_s)) { |
| 1495 | __consoleType = ConsoleType::EscapeCodes8bit; |
| 1496 | } else if (TERM.contains("xterm"_s) || TERM.contains("vt1"_s) || TERM.contains("linux"_s)) { |
| 1497 | __consoleType = ConsoleType::EscapeCodes; |
| 1498 | } |
| 1499 | } |
| 1500 | } else if (FORCE_COLOR) { |
| 1501 | // Use colors if FORCE_COLOR is set, even if the console doesn't report support for it (e.g., |
| 1502 | // when piping to a file), this is useful when the output is later viewed in a compatible viewer |
| 1503 | __consoleType = ConsoleType::EscapeCodes24bit; |
| 1504 | } |
| 1505 | |
| 1506 | ::signal(SIGINT, OnHandleInterruptSignal); |
| 1507 | # elif defined(DEATH_TARGET_WINDOWS) && !defined(DEATH_TARGET_WINDOWS_RT) |
| 1508 | DWORD NO_COLOR = ::GetEnvironmentVariable(L"NO_COLOR", nullptr, 0); |
| 1509 | if (NO_COLOR) { |
nothing calls this directly
no test coverage detected