diff --git a/bspinfo/main.cc b/bspinfo/main.cc index e0627b90..46b4f035 100644 --- a/bspinfo/main.cc +++ b/bspinfo/main.cc @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -84,6 +85,8 @@ settings::common_settings bspinfo_options; int main(int argc, char **argv) { + logging::preinitialize(); + fmt::print("---- bspinfo / ericw-tools {} ----\n", ERICWTOOLS_VERSION); if (argc == 1) { printf("usage: bspinfo bspfile [bspfiles]\n"); diff --git a/bsputil/bsputil.cc b/bsputil/bsputil.cc index 169afd9c..ce79c955 100644 --- a/bsputil/bsputil.cc +++ b/bsputil/bsputil.cc @@ -471,6 +471,8 @@ settings::common_settings bsputil_options; int main(int argc, char **argv) { + logging::preinitialize(); + bspdata_t bspdata; // FIXME: doesn't this get overwritten by ConvertBSPFormat below? mbsp_t &bsp = bspdata.bsp.emplace(); diff --git a/common/log.cc b/common/log.cc index 00369fb8..a79201d3 100644 --- a/common/log.cc +++ b/common/log.cc @@ -54,6 +54,15 @@ namespace logging bitflags mask = bitflags(flag::ALL) & ~bitflags(flag::VERBOSE); bool enable_color_codes = true; +void preinitialize() +{ +#ifdef _WIN32 + // enable processing of ANSI escape sequences on Windows + HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE); + SetConsoleMode(hOutput, ENABLE_PROCESSED_OUTPUT | ENABLE_VIRTUAL_TERMINAL_PROCESSING); +#endif +} + void init(const fs::path &filename, const settings::common_settings &settings) { if (settings.log.value()) { diff --git a/include/common/log.hh b/include/common/log.hh index 295e221b..ef08d273 100644 --- a/include/common/log.hh +++ b/include/common/log.hh @@ -57,6 +57,9 @@ enum class flag : uint8_t extern bitflags mask; extern bool enable_color_codes; +// Windows: calls SetConsoleMode for ANSI escape sequence processing (so colors work) +void preinitialize(); + // initialize logging subsystem void init(const fs::path &filename, const settings::common_settings &settings); diff --git a/light/main.cc b/light/main.cc index 54f8b4c0..330cb7a1 100644 --- a/light/main.cc +++ b/light/main.cc @@ -19,9 +19,12 @@ #include #include +#include int main(int argc, const char **argv) { + logging::preinitialize(); + try { return light_main(argc, argv); } catch (const settings::quit_after_help_exception &) { diff --git a/qbsp/main.cc b/qbsp/main.cc index 0cfd4643..bccd048f 100644 --- a/qbsp/main.cc +++ b/qbsp/main.cc @@ -19,9 +19,12 @@ #include #include +#include int main(int argc, const char **argv) { + logging::preinitialize(); + try { return qbsp_main(argc, argv); } catch (const settings::quit_after_help_exception &) { diff --git a/tests/test_main.cc b/tests/test_main.cc index 450ffaf8..31d39d23 100644 --- a/tests/test_main.cc +++ b/tests/test_main.cc @@ -3,7 +3,10 @@ #include -int main(int argc, char** argv) { +int main(int argc, char** argv) +{ + logging::preinitialize(); + // writing console colors within test case output breaks doctest/CLion integration logging::enable_color_codes = false; diff --git a/vis/main.cc b/vis/main.cc index 91fc5f0f..de10a70e 100644 --- a/vis/main.cc +++ b/vis/main.cc @@ -19,9 +19,12 @@ #include #include +#include int main(int argc, const char **argv) { + logging::preinitialize(); + try { return vis_main(argc, argv); } catch (const settings::quit_after_help_exception &) {