1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-23 01:59:43 +01:00

Allow disabling output/fine-tuning output

-nooutput disables output completely (both STDOUT and STDERR). -noinfo
disables INFO lines.  -nowarn disables WARN lines. -noerror disables
ERROR lines.
This commit is contained in:
Misa 2021-09-01 13:41:06 -07:00 committed by Misa Elizabeth Kai
parent c68a274c4f
commit 2eb9e23ecc
3 changed files with 63 additions and 0 deletions

View file

@ -23,7 +23,11 @@
#define Color_BOLD_YELLOW COLOR("\x1b[1;33m") #define Color_BOLD_YELLOW COLOR("\x1b[1;33m")
#define Color_BOLD_RED COLOR("\x1b[1;31m") #define Color_BOLD_RED COLOR("\x1b[1;31m")
static int output_enabled = 1;
static int color_enabled = 0; static int color_enabled = 0;
static int info_enabled = 1;
static int warn_enabled = 1;
static int error_enabled = 1;
void vlog_init(void) void vlog_init(void)
{ {
@ -47,16 +51,41 @@ void vlog_init(void)
} }
} }
void vlog_toggle_output(const int enable_output)
{
output_enabled = enable_output;
}
void vlog_toggle_color(const int enable_color) void vlog_toggle_color(const int enable_color)
{ {
color_enabled = enable_color; color_enabled = enable_color;
} }
void vlog_toggle_info(const int enable_info)
{
info_enabled = enable_info;
}
void vlog_toggle_warn(const int enable_warn)
{
warn_enabled = enable_warn;
}
void vlog_toggle_error(const int enable_error)
{
error_enabled = enable_error;
}
int vlog_info(const char* text, ...) int vlog_info(const char* text, ...)
{ {
va_list list; va_list list;
int retval; int retval;
if (!output_enabled || !info_enabled)
{
return 0;
}
printf(Color_BOLD); printf(Color_BOLD);
printf("[INFO]"); printf("[INFO]");
printf(Color_RESET); printf(Color_RESET);
@ -76,6 +105,11 @@ int vlog_warn(const char* text, ...)
va_list list; va_list list;
int retval; int retval;
if (!output_enabled || !warn_enabled)
{
return 0;
}
fprintf(stderr, Color_BOLD_YELLOW); fprintf(stderr, Color_BOLD_YELLOW);
fprintf(stderr, "[WARN]"); fprintf(stderr, "[WARN]");
fprintf(stderr, Color_RESET); fprintf(stderr, Color_RESET);
@ -95,6 +129,11 @@ int vlog_error(const char* text, ...)
va_list list; va_list list;
int retval; int retval;
if (!output_enabled || !error_enabled)
{
return 0;
}
fprintf(stderr, Color_BOLD_RED); fprintf(stderr, Color_BOLD_RED);
fprintf(stderr, "[ERROR]"); fprintf(stderr, "[ERROR]");
fprintf(stderr, Color_RESET); fprintf(stderr, Color_RESET);

View file

@ -8,8 +8,16 @@ extern "C"
void vlog_init(void); void vlog_init(void);
void vlog_toggle_output(int enable_output);
void vlog_toggle_color(int enable_color); void vlog_toggle_color(int enable_color);
void vlog_toggle_info(int enable_info);
void vlog_toggle_warn(int enable_warn);
void vlog_toggle_error(int enable_error);
int vlog_info(const char* text, ...); int vlog_info(const char* text, ...);
int vlog_warn(const char* text, ...); int vlog_warn(const char* text, ...);

View file

@ -432,6 +432,10 @@ int main(int argc, char *argv[])
playassets = "levels/" + std::string(argv[i]) + ".vvvvvv"; playassets = "levels/" + std::string(argv[i]) + ".vvvvvv";
}) })
} }
else if (ARG("-nooutput"))
{
vlog_toggle_output(0);
}
else if (ARG("-forcecolor") || ARG("-forcecolour")) else if (ARG("-forcecolor") || ARG("-forcecolour"))
{ {
vlog_toggle_color(1); vlog_toggle_color(1);
@ -440,6 +444,18 @@ int main(int argc, char *argv[])
{ {
vlog_toggle_color(0); vlog_toggle_color(0);
} }
else if (ARG("-noinfo"))
{
vlog_toggle_info(0);
}
else if (ARG("-nowarn"))
{
vlog_toggle_warn(0);
}
else if (ARG("-noerror"))
{
vlog_toggle_error(0);
}
#undef ARG_INNER #undef ARG_INNER
#undef ARG #undef ARG
else else