mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-12-29 05:12:41 +00:00
Make {overwrite,append}_file lua settings
This commit is contained in:
parent
3dd4593bc9
commit
2c96799e59
66
src/conky.cc
66
src/conky.cc
@ -360,8 +360,12 @@ conky::range_config_setting<int> net_avg_samples("net_avg_samples", 1, 14, 2, tr
|
|||||||
conky::range_config_setting<int> diskio_avg_samples("diskio_avg_samples", 1, 14, 2, true);
|
conky::range_config_setting<int> diskio_avg_samples("diskio_avg_samples", 1, 14, 2, true);
|
||||||
|
|
||||||
/* filenames for output */
|
/* filenames for output */
|
||||||
char *overwrite_file = NULL; FILE *overwrite_fpointer = NULL;
|
static conky::simple_config_setting<std::string> overwrite_file("overwrite_file",
|
||||||
char *append_file = NULL; FILE *append_fpointer = NULL;
|
std::string(), true);
|
||||||
|
static FILE *overwrite_fpointer = NULL;
|
||||||
|
static conky::simple_config_setting<std::string> append_file("append_file",
|
||||||
|
std::string(), true);
|
||||||
|
static FILE *append_fpointer = NULL;
|
||||||
|
|
||||||
#ifdef BUILD_HTTP
|
#ifdef BUILD_HTTP
|
||||||
std::string webpage;
|
std::string webpage;
|
||||||
@ -895,7 +899,7 @@ static void generate_text(void)
|
|||||||
p = text_buffer;
|
p = text_buffer;
|
||||||
|
|
||||||
generate_text_internal(p, max_user_text, global_root_object);
|
generate_text_internal(p, max_user_text, global_root_object);
|
||||||
int mw = max_text_width.get(*state);
|
unsigned int mw = max_text_width.get(*state);
|
||||||
if(mw > 0) {
|
if(mw > 0) {
|
||||||
for(i = 0, j = 0; p[i] != 0; i++) {
|
for(i = 0, j = 0; p[i] != 0; i++) {
|
||||||
if(p[i] == '\n') j = 0;
|
if(p[i] == '\n') j = 0;
|
||||||
@ -1255,10 +1259,10 @@ static void draw_string(const char *s)
|
|||||||
fprintf(stderr, "%s\n", s_with_newlines);
|
fprintf(stderr, "%s\n", s_with_newlines);
|
||||||
fflush(stderr); /* output immediately, don't buffer */
|
fflush(stderr); /* output immediately, don't buffer */
|
||||||
}
|
}
|
||||||
if ((output_methods & OVERWRITE_FILE) && draw_mode == FG && overwrite_fpointer) {
|
if (draw_mode == FG && overwrite_fpointer) {
|
||||||
fprintf(overwrite_fpointer, "%s\n", s_with_newlines);
|
fprintf(overwrite_fpointer, "%s\n", s_with_newlines);
|
||||||
}
|
}
|
||||||
if ((output_methods & APPEND_FILE) && draw_mode == FG && append_fpointer) {
|
if (draw_mode == FG && append_fpointer) {
|
||||||
fprintf(append_fpointer, "%s\n", s_with_newlines);
|
fprintf(append_fpointer, "%s\n", s_with_newlines);
|
||||||
}
|
}
|
||||||
#ifdef BUILD_NCURSES
|
#ifdef BUILD_NCURSES
|
||||||
@ -1899,15 +1903,15 @@ static void draw_stuff(void)
|
|||||||
#ifdef BUILD_IMLIB2
|
#ifdef BUILD_IMLIB2
|
||||||
cimlib_render(text_start_x, text_start_y, window.width, window.height);
|
cimlib_render(text_start_x, text_start_y, window.width, window.height);
|
||||||
#endif /* BUILD_IMLIB2 */
|
#endif /* BUILD_IMLIB2 */
|
||||||
if (overwrite_file) {
|
if (overwrite_file.get(*state).size()) {
|
||||||
overwrite_fpointer = fopen(overwrite_file, "w");
|
overwrite_fpointer = fopen(overwrite_file.get(*state).c_str(), "w");
|
||||||
if(!overwrite_fpointer)
|
if(!overwrite_fpointer)
|
||||||
NORM_ERR("Can't overwrite '%s' anymore", overwrite_file);
|
NORM_ERR("Cannot overwrite '%s'", overwrite_file.get(*state).c_str());
|
||||||
}
|
}
|
||||||
if (append_file) {
|
if (append_file.get(*state).size()) {
|
||||||
append_fpointer = fopen(append_file, "a");
|
append_fpointer = fopen(append_file.get(*state).c_str(), "a");
|
||||||
if(!append_fpointer)
|
if(!append_fpointer)
|
||||||
NORM_ERR("Can't append '%s' anymore", append_file);
|
NORM_ERR("Cannot append to '%s'", append_file.get(*state).c_str());
|
||||||
}
|
}
|
||||||
#ifdef BUILD_X11
|
#ifdef BUILD_X11
|
||||||
if (out_to_x.get(*state)) {
|
if (out_to_x.get(*state)) {
|
||||||
@ -2399,8 +2403,6 @@ static void main_loop(void)
|
|||||||
#endif /* BUILD_XDAMAGE */
|
#endif /* BUILD_XDAMAGE */
|
||||||
}
|
}
|
||||||
#endif /* BUILD_X11 */
|
#endif /* BUILD_X11 */
|
||||||
free_and_zero(overwrite_file);
|
|
||||||
free_and_zero(append_file);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
/* Reaching here means someone set a signal
|
/* Reaching here means someone set a signal
|
||||||
@ -2652,28 +2654,6 @@ static void set_default_configurations(void)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* returns 1 if you can overwrite or create the file at 'path' */
|
|
||||||
static bool overwrite_works(const char *path)
|
|
||||||
{
|
|
||||||
FILE *filepointer;
|
|
||||||
|
|
||||||
if (!(filepointer = fopen(path, "w")))
|
|
||||||
return false;
|
|
||||||
fclose(filepointer);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* returns 1 if you can append or create the file at 'path' */
|
|
||||||
static bool append_works(const char *path)
|
|
||||||
{
|
|
||||||
FILE *filepointer;
|
|
||||||
|
|
||||||
if (!(filepointer = fopen(path, "a")))
|
|
||||||
return false;
|
|
||||||
fclose(filepointer);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef BUILD_X11
|
#ifdef BUILD_X11
|
||||||
static void X11_create_window(void)
|
static void X11_create_window(void)
|
||||||
{
|
{
|
||||||
@ -2878,22 +2858,6 @@ char load_config_file(const char *f)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
CONF("overwrite_file") {
|
|
||||||
free_and_zero(overwrite_file);
|
|
||||||
if (overwrite_works(value)) {
|
|
||||||
overwrite_file = strdup(value);
|
|
||||||
output_methods |= OVERWRITE_FILE;
|
|
||||||
} else
|
|
||||||
NORM_ERR("overwrite_file won't be able to create/overwrite '%s'", value);
|
|
||||||
}
|
|
||||||
CONF("append_file") {
|
|
||||||
free_and_zero(append_file);
|
|
||||||
if(append_works(value)) {
|
|
||||||
append_file = strdup(value);
|
|
||||||
output_methods |= APPEND_FILE;
|
|
||||||
} else
|
|
||||||
NORM_ERR("append_file won't be able to create/append '%s'", value);
|
|
||||||
}
|
|
||||||
#ifdef BUILD_X11
|
#ifdef BUILD_X11
|
||||||
#ifdef BUILD_XFT
|
#ifdef BUILD_XFT
|
||||||
CONF("font") {
|
CONF("font") {
|
||||||
|
@ -321,8 +321,6 @@ extern unsigned int max_user_text;
|
|||||||
extern std::string current_config;
|
extern std::string current_config;
|
||||||
|
|
||||||
#define TO_STDERR 4
|
#define TO_STDERR 4
|
||||||
#define OVERWRITE_FILE 8
|
|
||||||
#define APPEND_FILE 16
|
|
||||||
|
|
||||||
enum x_initialiser_state {
|
enum x_initialiser_state {
|
||||||
NO = 0,
|
NO = 0,
|
||||||
|
Loading…
Reference in New Issue
Block a user