-
-
Notifications
You must be signed in to change notification settings - Fork 623
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move file output to a separate display-file
- Loading branch information
Showing
4 changed files
with
180 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* | ||
* | ||
* Conky, a system monitor, based on torsmo | ||
* | ||
* Please see COPYING for details | ||
* | ||
* Copyright (C) 2018 François Revol et al. | ||
* | ||
* 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 "nc.h" | ||
#include "display-file.hh" | ||
|
||
#include <iostream> | ||
#include <sstream> | ||
#include <unordered_map> | ||
|
||
/* filenames for output */ | ||
static conky::simple_config_setting<std::string> overwrite_file( | ||
"overwrite_file", std::string(), true); | ||
static FILE *overwrite_fpointer = nullptr; | ||
static conky::simple_config_setting<std::string> append_file("append_file", | ||
std::string(), | ||
true); | ||
static FILE *append_fpointer = nullptr; | ||
|
||
namespace conky { | ||
namespace { | ||
|
||
conky::display_output_file file_output("file"); | ||
|
||
} // namespace | ||
|
||
namespace priv { | ||
|
||
|
||
} // namespace priv | ||
|
||
display_output_file::display_output_file(const std::string &name_) | ||
: display_output_base(name_) { | ||
// lowest priority, it's a fallback | ||
priority = 0; | ||
} | ||
|
||
bool display_output_file::detect() { | ||
if (static_cast<unsigned int>(!overwrite_file.get(*state).empty()) != 0u || | ||
static_cast<unsigned int>(!append_file.get(*state).empty()) != 0u) { | ||
std::cerr << "Display output '" << name << "' enabled in config." << std::endl; | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
bool display_output_file::initialize() { | ||
return true; | ||
} | ||
|
||
bool display_output_file::shutdown() { | ||
return true; | ||
} | ||
|
||
void display_output_file::draw_string(const char *s, int w) { | ||
if (overwrite_fpointer != nullptr) { | ||
fprintf(overwrite_fpointer, "%s\n", s); | ||
} | ||
if (append_fpointer != nullptr) { | ||
fprintf(append_fpointer, "%s\n", s); | ||
} | ||
} | ||
|
||
void display_output_x11::begin_draw_stuff() { | ||
if (static_cast<unsigned int>(!overwrite_file.get(*state).empty()) != 0u) { | ||
overwrite_fpointer = fopen(overwrite_file.get(*state).c_str(), "we"); | ||
if (overwrite_fpointer == nullptr) { | ||
NORM_ERR("Cannot overwrite '%s'", overwrite_file.get(*state).c_str()); | ||
} | ||
} | ||
if (static_cast<unsigned int>(!append_file.get(*state).empty()) != 0u) { | ||
append_fpointer = fopen(append_file.get(*state).c_str(), "ae"); | ||
if (append_fpointer == nullptr) { | ||
NORM_ERR("Cannot append to '%s'", append_file.get(*state).c_str()); | ||
} | ||
} | ||
} | ||
|
||
void display_output_x11::end_draw_stuff() { | ||
if (overwrite_fpointer != nullptr) { | ||
fclose(overwrite_fpointer); | ||
overwrite_fpointer = nullptr; | ||
} | ||
if (append_fpointer != nullptr) { | ||
fclose(append_fpointer); | ||
append_fpointer = nullptr; | ||
} | ||
} | ||
|
||
} // namespace conky | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* | ||
* Conky, a system monitor, based on torsmo | ||
* | ||
* Please see COPYING for details | ||
* | ||
* Copyright (C) 2018 François Revol et al. | ||
* | ||
* 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/>. | ||
* | ||
*/ | ||
|
||
#ifndef DISPLAY_FILE_HH | ||
#define DISPLAY_FILE_HH | ||
|
||
#include <limits> | ||
#include <string> | ||
#include <type_traits> | ||
|
||
#include "luamm.hh" | ||
#include "display-output.hh" | ||
|
||
namespace conky { | ||
|
||
/* | ||
* A base class for file display output. | ||
*/ | ||
class display_output_file : public display_output_base { | ||
|
||
public: | ||
|
||
explicit display_output_file(const std::string &name_); | ||
|
||
virtual ~display_output_file() {} | ||
|
||
// check if available and enabled in settings | ||
virtual bool detect(); | ||
// connect to DISPLAY and other stuff | ||
virtual bool initialize(); | ||
virtual bool shutdown(); | ||
|
||
virtual void draw_string(const char *s, int w); | ||
|
||
virtual void begin_draw_stuff(); | ||
virtual void end_draw_stuff(); | ||
|
||
// file-specific | ||
}; | ||
|
||
} // namespace conky | ||
|
||
#endif /* DISPLAY_FILE_HH */ |