From 1c5198bccdaa7c91aaac67a1b7171ea346c957f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Fri, 19 Oct 2018 02:30:31 +0200 Subject: [PATCH] proper console display (move code out of conky.cc) --- src/conky.cc | 11 ----------- src/display-console.cc | 15 +++++++++++++++ src/display-console.hh | 2 ++ 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/conky.cc b/src/conky.cc index 5b52aec7..64bd23f4 100644 --- a/src/conky.cc +++ b/src/conky.cc @@ -201,8 +201,6 @@ int top_cpu, top_mem, top_time; int top_io; #endif int top_running; -static conky::simple_config_setting extra_newline("extra_newline", false, - false); /* Update interval */ conky::range_config_setting update_interval( @@ -1075,15 +1073,6 @@ static void draw_string(const char *s) { #ifdef BUILD_X11 width_of_s = get_string_width(s); #endif /* BUILD_X11 */ - if (out_to_stdout.get(*state) && draw_mode == FG) { - printf("%s\n", s); - if (extra_newline.get(*state)) { fputc('\n', stdout); } - fflush(stdout); /* output immediately, don't buffer */ - } - if (out_to_stderr.get(*state) && draw_mode == FG) { - fprintf(stderr, "%s\n", s); - fflush(stderr); /* output immediately, don't buffer */ - } if (draw_mode == FG && (overwrite_fpointer != nullptr)) { fprintf(overwrite_fpointer, "%s\n", s); } diff --git a/src/display-console.cc b/src/display-console.cc index 8601c3a5..04439606 100644 --- a/src/display-console.cc +++ b/src/display-console.cc @@ -34,6 +34,9 @@ #include #include +static conky::simple_config_setting extra_newline("extra_newline", false, + false); + namespace conky { namespace { @@ -63,4 +66,16 @@ bool display_output_console::initialize() { return true; } bool display_output_console::shutdown() { return true; } +void display_output_console::draw_string(const char *s, int w) { + if (out_to_stdout.get(*state)) { + printf("%s\n", s); + if (extra_newline.get(*state)) { fputc('\n', stdout); } + fflush(stdout); /* output immediately, don't buffer */ + } + if (out_to_stderr.get(*state)) { + fprintf(stderr, "%s\n", s); + fflush(stderr); /* output immediately, don't buffer */ + } +} + } // namespace conky diff --git a/src/display-console.hh b/src/display-console.hh index 92c0d7af..d366c122 100644 --- a/src/display-console.hh +++ b/src/display-console.hh @@ -47,6 +47,8 @@ class display_output_console : public display_output_base { virtual bool initialize(); virtual bool shutdown(); + virtual void draw_string(const char *s, int w); + // console-specific };