diff options
author | jdiez17 <jose.manuel.diez@gmail.com> | 2015-08-09 20:35:56 +0200 |
---|---|---|
committer | jdiez17 <jose.manuel.diez@gmail.com> | 2015-08-09 20:38:02 +0200 |
commit | c688ff704d29d000a4d62a4a1e927116c4f9eba9 (patch) | |
tree | cb7f4a081cd3f78e45eaacb061ed0faad6eaf1d5 /sway | |
parent | ec2fedf6d0d4d101351bfa03a60beb02c90573fc (diff) |
log, commands: Add log_colors command
Diffstat (limited to 'sway')
-rw-r--r-- | sway/commands.c | 17 | ||||
-rw-r--r-- | sway/log.c | 15 | ||||
-rw-r--r-- | sway/log.h | 1 |
3 files changed, 31 insertions, 2 deletions
diff --git a/sway/commands.c b/sway/commands.c index 33a5e485..efa72f19 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -146,6 +146,22 @@ int cmd_set(struct sway_config *config, int argc, char **argv) { return 0; } +int cmd_log_colors(struct sway_config *config, int argc, char **argv) { + if (argc != 1) { + sway_log(L_ERROR, "Invalid log_colors command (expected 1 argument, got %d)", argc); + return 1; + } + + if (strcasecmp(argv[0], "no") != 0 && strcasecmp(argv[0], "yes") != 0) { + sway_log(L_ERROR, "Invalid log_colors command (expected `yes` or `no`, got '%s')", argv[0]); + return 1; + } + + sway_log_colors(!strcasecmp(argv[0], "yes")); + return 0; +} + + /* Keep alphabetized */ struct cmd_handler handlers[] = { { "bindsym", cmd_bindsym }, @@ -153,6 +169,7 @@ struct cmd_handler handlers[] = { { "exit", cmd_exit }, { "focus_follows_mouse", cmd_focus_follows_mouse }, { "layout", cmd_layout }, + { "log_colors", cmd_log_colors }, { "set", cmd_set }, }; @@ -17,6 +17,10 @@ void init_log(int verbosity) { v = verbosity; } +void sway_log_colors(int mode) { + colored = (mode == 1) ? 1 : 0; +} + void sway_abort(char *format, ...) { fprintf(stderr, "ERROR: "); va_list args; @@ -33,11 +37,18 @@ void sway_log(int verbosity, char* format, ...) { if (c > sizeof(verbosity_colors) / sizeof(char *)) { c = sizeof(verbosity_colors) / sizeof(char *) - 1; } - fprintf(stderr, verbosity_colors[c]); + + if(colored) { + fprintf(stderr, verbosity_colors[c]); + } + va_list args; va_start(args, format); vfprintf(stderr, format, args); va_end(args); - fprintf(stderr, "\x1B[0m\n"); + + if(colored) { + fprintf(stderr, "\x1B[0m\n"); + } } } @@ -9,6 +9,7 @@ typedef enum { } log_importance_t; void init_log(int verbosity); +void sway_log_colors(int mode); void sway_log(int verbosity, char* format, ...); void sway_abort(char* format, ...); |