add -nocolor for TB, etc
fix crashes on vis and light for invalid options fix TB and others not receiving output
This commit is contained in:
parent
3564f6085d
commit
075481a36f
|
|
@ -46,6 +46,7 @@ static std::ofstream logfile;
|
|||
namespace logging
|
||||
{
|
||||
bitflags<flag> mask = bitflags<flag>(flag::ALL) & ~bitflags<flag>(flag::VERBOSE);
|
||||
bool enable_color_codes = true;
|
||||
|
||||
void init(const fs::path &filename, const settings::common_settings &settings)
|
||||
{
|
||||
|
|
@ -71,14 +72,17 @@ void print(flag logflag, const char *str)
|
|||
}
|
||||
|
||||
fmt::text_style style;
|
||||
if (string_icontains(str, "error")) {
|
||||
style = fmt::fg(fmt::color::red);
|
||||
} else if (string_icontains(str, "warning")) {
|
||||
style = fmt::fg(fmt::terminal_color::yellow);
|
||||
} else if (bitflags<flag>(logflag) & flag::PERCENT) {
|
||||
style = fmt::fg(fmt::terminal_color::blue);
|
||||
} else if (bitflags<flag>(logflag) & flag::STAT) {
|
||||
style = fmt::fg(fmt::terminal_color::cyan);
|
||||
|
||||
if (enable_color_codes) {
|
||||
if (string_icontains(str, "error")) {
|
||||
style = fmt::fg(fmt::color::red);
|
||||
} else if (string_icontains(str, "warning")) {
|
||||
style = fmt::fg(fmt::terminal_color::yellow);
|
||||
} else if (bitflags<flag>(logflag) & flag::PERCENT) {
|
||||
style = fmt::fg(fmt::terminal_color::blue);
|
||||
} else if (bitflags<flag>(logflag) & flag::STAT) {
|
||||
style = fmt::fg(fmt::terminal_color::cyan);
|
||||
}
|
||||
}
|
||||
|
||||
print_mutex.lock();
|
||||
|
|
@ -97,8 +101,15 @@ void print(flag logflag, const char *str)
|
|||
#endif
|
||||
}
|
||||
|
||||
// stdout (assume the terminal can render ANSI colors)
|
||||
fmt::print(style, "{}", str);
|
||||
if (enable_color_codes) {
|
||||
// stdout (assume the terminal can render ANSI colors)
|
||||
fmt::print(style, "{}", str);
|
||||
} else {
|
||||
std::cout << str;
|
||||
}
|
||||
|
||||
// for TB, etc...
|
||||
fflush(stdout);
|
||||
|
||||
print_mutex.unlock();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -185,5 +185,9 @@ void common_settings::postinitialize(int argc, const char **argv)
|
|||
if (noprogress.value()) {
|
||||
logging::mask &= ~bitflags<logging::flag>(logging::flag::PROGRESS);
|
||||
}
|
||||
|
||||
if (nocolor.value()) {
|
||||
logging::enable_color_codes = false;
|
||||
}
|
||||
}
|
||||
} // namespace settings
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ enum class flag : uint8_t
|
|||
};
|
||||
|
||||
extern bitflags<flag> mask;
|
||||
extern bool enable_color_codes;
|
||||
|
||||
// initialize logging subsystem
|
||||
void init(const fs::path &filename, const settings::common_settings &settings);
|
||||
|
|
|
|||
|
|
@ -851,6 +851,7 @@ public:
|
|||
setting_bool nopercent{this, "nopercent", false, &logging_group, "don't output percentage messages"};
|
||||
setting_bool nostat{this, "nostat", false, &logging_group, "don't output statistic messages"};
|
||||
setting_bool noprogress{this, "noprogress", false, &logging_group, "don't output progress messages"};
|
||||
setting_bool nocolor{this, "nocolor", false, &logging_group, "don't output color codes (for TB, etc)"};
|
||||
setting_redirect quiet{this, {"quiet", "noverbose"}, {&nopercent, &nostat, &noprogress}, &logging_group,
|
||||
"suppress non-important messages (equivalent to -nopercent -nostat -noprogress)"};
|
||||
setting_path gamedir{this, "gamedir", "", &game_group,
|
||||
|
|
|
|||
|
|
@ -114,14 +114,19 @@ setting_group experimental_group{"Experimental options", 60};
|
|||
|
||||
void light_settings::initialize(int argc, const char **argv)
|
||||
{
|
||||
token_parser_t p(argc - 1, argv + 1, { "command line" });
|
||||
auto remainder = parse(p);
|
||||
try {
|
||||
token_parser_t p(argc - 1, argv + 1, { "command line" });
|
||||
auto remainder = parse(p);
|
||||
|
||||
if (remainder.size() <= 0 || remainder.size() > 1) {
|
||||
if (remainder.size() <= 0 || remainder.size() > 1) {
|
||||
printHelp();
|
||||
}
|
||||
|
||||
sourceMap = remainder[0];
|
||||
} catch (parse_exception &ex) {
|
||||
logging::print(ex.what());
|
||||
printHelp();
|
||||
}
|
||||
|
||||
sourceMap = remainder[0];
|
||||
}
|
||||
|
||||
void light_settings::postinitialize(int argc, const char **argv)
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ void qbsp_settings::initialize(int argc, const char **argv)
|
|||
if (remainder.size() == 2) {
|
||||
qbsp_options.bsp_path = remainder[1];
|
||||
}
|
||||
} catch (parse_exception ex) {
|
||||
} catch (parse_exception &ex) {
|
||||
logging::print(ex.what());
|
||||
printHelp();
|
||||
}
|
||||
|
|
|
|||
15
vis/vis.cc
15
vis/vis.cc
|
|
@ -63,14 +63,19 @@ setting_group advanced_group{"Advanced", 300};
|
|||
|
||||
void vis_settings::initialize(int argc, const char **argv)
|
||||
{
|
||||
token_parser_t p(argc - 1, argv + 1, { "command line" });
|
||||
auto remainder = parse(p);
|
||||
try {
|
||||
token_parser_t p(argc - 1, argv + 1, { "command line" });
|
||||
auto remainder = parse(p);
|
||||
|
||||
if (remainder.size() <= 0 || remainder.size() > 1) {
|
||||
if (remainder.size() <= 0 || remainder.size() > 1) {
|
||||
printHelp();
|
||||
}
|
||||
|
||||
sourceMap = DefaultExtension(remainder[0], "bsp");
|
||||
} catch (parse_exception &ex) {
|
||||
logging::print(ex.what());
|
||||
printHelp();
|
||||
}
|
||||
|
||||
sourceMap = DefaultExtension(remainder[0], "bsp");
|
||||
}
|
||||
} // namespace settings
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue