From dfc9efa3cc3a00fb3e3fb70d2629a7b30317bcde Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Fri, 30 Apr 2010 19:06:17 +0200 Subject: [PATCH] make out_to_console/stderr lua settings --- src/conky.cc | 39 ++++++++++++++++++++++----------------- src/conky.h | 1 - 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/conky.cc b/src/conky.cc index 118bd930..d8ddbdb8 100644 --- a/src/conky.cc +++ b/src/conky.cc @@ -160,6 +160,10 @@ static conky::simple_config_setting use_spacer("use_spacer", NO_SP static conky::simple_config_setting short_units("short_units", false, true); static conky::simple_config_setting format_human_readable("format_human_readable", true, true); + +static conky::simple_config_setting out_to_stdout("out_to_console", false, false); +static conky::simple_config_setting out_to_stderr("out_to_stderr", false, false); + int top_cpu, top_mem, top_time; #ifdef BUILD_IOSTATS int top_io; @@ -1163,12 +1167,12 @@ static void draw_string(const char *s) s_with_newlines[i] = '\n'; } } - if ((output_methods & TO_STDOUT) && draw_mode == FG) { + if (out_to_stdout.get(*state) && draw_mode == FG) { printf("%s\n", s_with_newlines); if (extra_newline.get(*state)) fputc('\n', stdout); fflush(stdout); /* output immediately, don't buffer */ } - if ((output_methods & TO_STDERR) && draw_mode == FG) { + if (out_to_stderr.get(*state) && draw_mode == FG) { fprintf(stderr, "%s\n", s_with_newlines); fflush(stderr); /* output immediately, don't buffer */ } @@ -2571,7 +2575,8 @@ static void set_default_configurations(void) state->pushboolean(true); out_to_x.lua_set(*state); #else - output_methods = TO_STDOUT; + state->pushboolean(true); + out_to_stdout.lua_set(*state); #endif #ifdef BUILD_X11 set_first_font("6x10"); @@ -2942,17 +2947,6 @@ char load_config_file(const char *f) CONF("max_text_width") { max_text_width = atoi(value); } - CONF("out_to_console") { - if(string_to_bool(value)) { - output_methods |= TO_STDOUT; - } else { - output_methods &= ~TO_STDOUT; - } - } - CONF("out_to_stderr") { - if(string_to_bool(value)) - output_methods |= TO_STDERR; - } #ifdef BUILD_NCURSES CONF("out_to_ncurses") { if(string_to_bool(value)) { @@ -3277,9 +3271,14 @@ char load_config_file(const char *f) endwin(); } #endif /* BUILD_X11 */ - if ((output_methods & (TO_STDOUT | TO_STDERR)) && (output_methods & TO_NCURSES)) { + if ((out_to_stdout.get(*state) || out_to_stderr.get(*state)) + && (output_methods & TO_NCURSES)) { NORM_ERR("out_to_ncurses conflicts with out_to_console and out_to_stderr, disabling the later ones"); - output_methods &= ~(TO_STDOUT | TO_STDERR); + // XXX: this will need some rethinking + state->pushboolean(false); + out_to_stdout.lua_set(*state); + state->pushboolean(false); + out_to_stderr.lua_set(*state); } #endif /* BUILD_NCURSES */ return TRUE; @@ -3445,7 +3444,13 @@ void initialisation(int argc, char **argv) { global_text = strndup(optarg, max_user_text); convert_escapes(global_text); total_run_times = 1; - output_methods = TO_STDOUT; + + state->pushboolean(true); + out_to_stdout.lua_set(*state); +#ifdef BUILD_X11 + state->pushboolean(false); + out_to_x.lua_set(*state); +#endif for_scripts = true; } } diff --git a/src/conky.h b/src/conky.h index b90068c2..41eeacea 100644 --- a/src/conky.h +++ b/src/conky.h @@ -321,7 +321,6 @@ extern unsigned int max_user_text; /* path to config file */ extern std::string current_config; -#define TO_STDOUT 2 #define TO_STDERR 4 #define OVERWRITE_FILE 8 #define APPEND_FILE 16