diff options
| author | David Härdeman <david@hardeman.nu> | 2020-07-01 17:28:09 +0200 | 
|---|---|---|
| committer | David Härdeman <david@hardeman.nu> | 2020-07-01 17:28:09 +0200 | 
| commit | e045a7b80cc0cb96b79456f9c74c3705989a12df (patch) | |
| tree | 00532a51671d2835217997dfdb204ba863fb0a1e /minecctl | |
| parent | 829ea0768672dad977ddeb30dd5e2b254bb4a4e9 (diff) | |
Turn colors into global variables
Diffstat (limited to 'minecctl')
| -rw-r--r-- | minecctl/misc.c | 23 | ||||
| -rw-r--r-- | minecctl/misc.h | 2 | ||||
| -rw-r--r-- | minecctl/rcon-commands.c | 5 | 
3 files changed, 13 insertions, 17 deletions
diff --git a/minecctl/misc.c b/minecctl/misc.c index 3f5ba50..c8e1d05 100644 --- a/minecctl/misc.c +++ b/minecctl/misc.c @@ -9,8 +9,6 @@  #include "misc.h"  #include "minecctl.h" -bool use_colors = false; -  /* FIXME: Can be shared */  void set_use_colors()  { @@ -34,7 +32,7 @@ void set_use_colors()  	if (streq(e, "dumb"))  		return; -	use_colors = true; +	enable_colors();  }  char **strv_copy(char *const *strv) @@ -210,20 +208,23 @@ void free_password(char **password)  void __debug(_unused_ enum debug_lvl lvl, const char *fmt, ...)  {  	va_list ap; +	const char *color = NULL; -	if (use_colors) { -		if (lvl & DBG_ERROR) -			fprintf(stderr, ANSI_RED); -		else if (!(lvl & (DBG_INFO | DBG_VERBOSE))) -			fprintf(stderr, ANSI_GREY); -	} + +	if (lvl & DBG_ERROR) +		color = ansi_red; +	else if (!(lvl & (DBG_INFO | DBG_VERBOSE))) +		color = ansi_grey; + +	if (color) +		fprintf(stderr, "%s", color);  	va_start(ap, fmt);  	vfprintf(stderr, fmt, ap);  	va_end(ap); -	if (use_colors && !(lvl & (DBG_INFO | DBG_VERBOSE))) -		fprintf(stderr, ANSI_NORMAL); +	if (color) +		fprintf(stderr, "%s", ansi_normal);  }  _noreturn_ void __die(const char *fmt, ...) diff --git a/minecctl/misc.h b/minecctl/misc.h index c8254df..0c97ad4 100644 --- a/minecctl/misc.h +++ b/minecctl/misc.h @@ -1,8 +1,6 @@  #ifndef foomischfoo  #define foomischfoo -extern bool use_colors; -  void set_use_colors();  char **strv_copy(char *const *strv); diff --git a/minecctl/rcon-commands.c b/minecctl/rcon-commands.c index eff397d..fc5b932 100644 --- a/minecctl/rcon-commands.c +++ b/minecctl/rcon-commands.c @@ -166,10 +166,7 @@ static bool send_cmd(int sfd, const char *cmd)  		return false;  	} -	if (use_colors) -		info("%s%s%s", ANSI_GREY, reply, ANSI_NORMAL); -	else -		info("%s", reply); +	info("%s%s%s", ansi_grey, reply, ansi_normal);  	return true;  }  | 
