2018-10-05 01:48:59 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Conky, a system monitor, based on torsmo
|
|
|
|
*
|
|
|
|
* Please see COPYING for details
|
|
|
|
*
|
2018-10-18 22:51:08 +00:00
|
|
|
* Copyright (C) 2018 François Revol et al.
|
|
|
|
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
|
2021-10-25 14:26:37 +00:00
|
|
|
* Copyright (c) 2005-2021 Brenden Matthews, Philip Kovacs, et. al.
|
2018-10-18 22:51:08 +00:00
|
|
|
* (see AUTHORS)
|
|
|
|
* All rights reserved.
|
2018-10-05 01:48:59 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "conky.h"
|
|
|
|
#include "display-console.hh"
|
2018-10-05 03:09:19 +00:00
|
|
|
#include "nc.h"
|
2018-10-05 01:48:59 +00:00
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
|
|
|
#include <unordered_map>
|
|
|
|
|
2018-10-19 00:30:31 +00:00
|
|
|
static conky::simple_config_setting<bool> extra_newline("extra_newline", false,
|
|
|
|
false);
|
|
|
|
|
2018-10-05 01:48:59 +00:00
|
|
|
namespace conky {
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
conky::display_output_console console_output("console");
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
namespace priv {} // namespace priv
|
|
|
|
|
|
|
|
display_output_console::display_output_console(const std::string &name_)
|
|
|
|
: display_output_base(name_) {
|
|
|
|
// lowest priority, it's a fallback
|
|
|
|
priority = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool display_output_console::detect() {
|
2018-10-05 03:09:19 +00:00
|
|
|
if ((out_to_stdout.get(*state) || out_to_stderr.get(*state)) &&
|
|
|
|
!out_to_ncurses.get(*state)) {
|
2020-12-26 17:49:30 +00:00
|
|
|
DBGP2("Display output '%s' enabled in config.", name.c_str());
|
2018-10-05 01:48:59 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool display_output_console::initialize() { return true; }
|
|
|
|
|
|
|
|
bool display_output_console::shutdown() { return true; }
|
|
|
|
|
2021-10-25 18:17:19 +00:00
|
|
|
void display_output_console::draw_string(const char *s, int) {
|
2018-10-19 00:30:31 +00:00
|
|
|
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 */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-05 01:48:59 +00:00
|
|
|
} // namespace conky
|