Merge pull request #337 from TTimo/colorcodes

Enable support for ANSI color codes on Windows 10 and newer, without …
This commit is contained in:
Eric Wasylishen 2022-11-19 09:10:24 -08:00 committed by GitHub
commit c9111b2a6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 30 additions and 1 deletions

View File

@ -20,6 +20,7 @@
#include <common/bspinfo.hh>
#include <common/cmdlib.hh>
#include <common/bspfile.hh>
#include <common/log.hh>
#include <fstream>
#include <fmt/ostream.h>
@ -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");

View File

@ -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<mbsp_t>();

View File

@ -54,6 +54,15 @@ namespace logging
bitflags<flag> mask = bitflags<flag>(flag::ALL) & ~bitflags<flag>(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()) {

View File

@ -57,6 +57,9 @@ enum class flag : uint8_t
extern bitflags<flag> 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);

View File

@ -19,9 +19,12 @@
#include <light/light.hh>
#include <common/settings.hh>
#include <common/log.hh>
int main(int argc, const char **argv)
{
logging::preinitialize();
try {
return light_main(argc, argv);
} catch (const settings::quit_after_help_exception &) {

View File

@ -19,9 +19,12 @@
#include <qbsp/qbsp.hh>
#include <common/settings.hh>
#include <common/log.hh>
int main(int argc, const char **argv)
{
logging::preinitialize();
try {
return qbsp_main(argc, argv);
} catch (const settings::quit_after_help_exception &) {

View File

@ -3,7 +3,10 @@
#include <common/log.hh>
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;

View File

@ -19,9 +19,12 @@
#include <vis/vis.hh>
#include <common/settings.hh>
#include <common/log.hh>
int main(int argc, const char **argv)
{
logging::preinitialize();
try {
return vis_main(argc, argv);
} catch (const settings::quit_after_help_exception &) {