diff options
author | 2015-08-09 20:35:56 +0200 | |
---|---|---|
committer | 2015-08-09 20:38:02 +0200 | |
commit | c688ff704d29d000a4d62a4a1e927116c4f9eba9 (patch) | |
tree | cb7f4a081cd3f78e45eaacb061ed0faad6eaf1d5 | |
parent | Implement layout [splith|splitv|toggle split] (diff) | |
download | sway-c688ff704d29d000a4d62a4a1e927116c4f9eba9.tar.gz sway-c688ff704d29d000a4d62a4a1e927116c4f9eba9.tar.zst sway-c688ff704d29d000a4d62a4a1e927116c4f9eba9.zip |
log, commands: Add log_colors command
-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) { | |||
146 | return 0; | 146 | return 0; |
147 | } | 147 | } |
148 | 148 | ||
149 | int cmd_log_colors(struct sway_config *config, int argc, char **argv) { | ||
150 | if (argc != 1) { | ||
151 | sway_log(L_ERROR, "Invalid log_colors command (expected 1 argument, got %d)", argc); | ||
152 | return 1; | ||
153 | } | ||
154 | |||
155 | if (strcasecmp(argv[0], "no") != 0 && strcasecmp(argv[0], "yes") != 0) { | ||
156 | sway_log(L_ERROR, "Invalid log_colors command (expected `yes` or `no`, got '%s')", argv[0]); | ||
157 | return 1; | ||
158 | } | ||
159 | |||
160 | sway_log_colors(!strcasecmp(argv[0], "yes")); | ||
161 | return 0; | ||
162 | } | ||
163 | |||
164 | |||
149 | /* Keep alphabetized */ | 165 | /* Keep alphabetized */ |
150 | struct cmd_handler handlers[] = { | 166 | struct cmd_handler handlers[] = { |
151 | { "bindsym", cmd_bindsym }, | 167 | { "bindsym", cmd_bindsym }, |
@@ -153,6 +169,7 @@ struct cmd_handler handlers[] = { | |||
153 | { "exit", cmd_exit }, | 169 | { "exit", cmd_exit }, |
154 | { "focus_follows_mouse", cmd_focus_follows_mouse }, | 170 | { "focus_follows_mouse", cmd_focus_follows_mouse }, |
155 | { "layout", cmd_layout }, | 171 | { "layout", cmd_layout }, |
172 | { "log_colors", cmd_log_colors }, | ||
156 | { "set", cmd_set }, | 173 | { "set", cmd_set }, |
157 | }; | 174 | }; |
158 | 175 | ||
@@ -17,6 +17,10 @@ void init_log(int verbosity) { | |||
17 | v = verbosity; | 17 | v = verbosity; |
18 | } | 18 | } |
19 | 19 | ||
20 | void sway_log_colors(int mode) { | ||
21 | colored = (mode == 1) ? 1 : 0; | ||
22 | } | ||
23 | |||
20 | void sway_abort(char *format, ...) { | 24 | void sway_abort(char *format, ...) { |
21 | fprintf(stderr, "ERROR: "); | 25 | fprintf(stderr, "ERROR: "); |
22 | va_list args; | 26 | va_list args; |
@@ -33,11 +37,18 @@ void sway_log(int verbosity, char* format, ...) { | |||
33 | if (c > sizeof(verbosity_colors) / sizeof(char *)) { | 37 | if (c > sizeof(verbosity_colors) / sizeof(char *)) { |
34 | c = sizeof(verbosity_colors) / sizeof(char *) - 1; | 38 | c = sizeof(verbosity_colors) / sizeof(char *) - 1; |
35 | } | 39 | } |
36 | fprintf(stderr, verbosity_colors[c]); | 40 | |
41 | if(colored) { | ||
42 | fprintf(stderr, verbosity_colors[c]); | ||
43 | } | ||
44 | |||
37 | va_list args; | 45 | va_list args; |
38 | va_start(args, format); | 46 | va_start(args, format); |
39 | vfprintf(stderr, format, args); | 47 | vfprintf(stderr, format, args); |
40 | va_end(args); | 48 | va_end(args); |
41 | fprintf(stderr, "\x1B[0m\n"); | 49 | |
50 | if(colored) { | ||
51 | fprintf(stderr, "\x1B[0m\n"); | ||
52 | } | ||
42 | } | 53 | } |
43 | } | 54 | } |
@@ -9,6 +9,7 @@ typedef enum { | |||
9 | } log_importance_t; | 9 | } log_importance_t; |
10 | 10 | ||
11 | void init_log(int verbosity); | 11 | void init_log(int verbosity); |
12 | void sway_log_colors(int mode); | ||
12 | void sway_log(int verbosity, char* format, ...); | 13 | void sway_log(int verbosity, char* format, ...); |
13 | void sway_abort(char* format, ...); | 14 | void sway_abort(char* format, ...); |
14 | 15 | ||