1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2025-02-05 13:38:33 +00:00

make out_to_ncurses a lua setting

this completes the porting of bool settings
This commit is contained in:
Pavel Labath 2010-04-30 19:33:21 +02:00
parent dfc9efa3cc
commit f81c29a42d
7 changed files with 76 additions and 55 deletions

View File

@ -174,6 +174,10 @@ if(BUILD_BUILTIN_CONFIG)
set(optional_sources ${optional_sources} conf_cookie.cc)
endif(BUILD_BUILTIN_CONFIG)
if(BUILD_NCURSES)
set(optional_sources ${optional_sources} nc.cc)
endif(BUILD_NCURSES)
add_executable(conky ${conky_sources} ${optional_sources})
target_link_libraries(conky ${conky_libs})

View File

@ -67,12 +67,6 @@
#include <netdb.h>
#include <fcntl.h>
#include <getopt.h>
#ifdef BUILD_NCURSES
#include <ncurses.h>
#ifdef LEAKFREE_NCURSES
#include "nc.h"
#endif
#endif
#ifdef BUILD_WEATHER_XOAP
#include <libxml/parser.h>
#endif /* BUILD_WEATHER_XOAP */
@ -94,6 +88,7 @@
#endif /* BUILD_LUA */
#include "logging.h"
#include "mail.h"
#include "nc.h"
#include "net_stat.h"
#include "temphelper.h"
#include "template.h"
@ -1141,7 +1136,7 @@ static inline void set_foreground_color(long c)
}
#endif /* BUILD_X11 */
#ifdef BUILD_NCURSES
if (output_methods & TO_NCURSES) {
if (out_to_ncurses.get(*state)) {
attron(COLOR_PAIR(c));
}
#endif /* BUILD_NCURSES */
@ -1183,7 +1178,7 @@ static void draw_string(const char *s)
fprintf(append_fpointer, "%s\n", s_with_newlines);
}
#ifdef BUILD_NCURSES
if ((output_methods & TO_NCURSES) && draw_mode == FG) {
if (out_to_ncurses.get(*state) && draw_mode == FG) {
printw("%s", s_with_newlines);
}
#endif
@ -1710,7 +1705,7 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied)
#endif /* BUILD_X11 */
draw_string(s);
#ifdef BUILD_NCURSES
if (output_methods & TO_NCURSES) {
if (out_to_ncurses.get(*state)) {
printw("\n");
}
#endif /* BUILD_NCURSES */
@ -1733,7 +1728,7 @@ static int draw_line(char *s, int special_index)
}
#endif /* BUILD_X11 */
#ifdef BUILD_NCURSES
if (output_methods & TO_NCURSES) {
if (out_to_ncurses.get(*state)) {
return draw_each_line_inner(s, special_index, -1);
}
#endif /* BUILD_NCURSES */
@ -2252,7 +2247,7 @@ static void main_loop(void)
update_text();
draw_stuff();
#ifdef BUILD_NCURSES
if(output_methods & TO_NCURSES) {
if(out_to_ncurses.get(*state)) {
refresh();
clear();
}
@ -2418,11 +2413,6 @@ void clean_up(void *memtofree1, void* memtofree2)
{
free_update_callbacks();
#ifdef BUILD_NCURSES
if(output_methods & TO_NCURSES) {
endwin();
}
#endif
conftree_empty(currentconffile);
currentconffile = NULL;
free_and_zero(memtofree1);
@ -2487,21 +2477,6 @@ void clean_up(void *memtofree1, void* memtofree2)
state.reset();
}
static bool string_to_bool(const char *s)
{
if (!s) {
// Assumes an option without a true/false means true
return true;
} else if (strcasecmp(s, "yes") == EQUAL) {
return true;
} else if (strcasecmp(s, "true") == EQUAL) {
return true;
} else if (strcasecmp(s, "1") == EQUAL) {
return true;
}
return false;
}
static void set_default_configurations(void)
{
#ifdef BUILD_MPD
@ -2947,15 +2922,6 @@ char load_config_file(const char *f)
CONF("max_text_width") {
max_text_width = atoi(value);
}
#ifdef BUILD_NCURSES
CONF("out_to_ncurses") {
if(string_to_bool(value)) {
initscr();
start_color();
output_methods |= TO_NCURSES;
}
}
#endif
CONF("overwrite_file") {
free_and_zero(overwrite_file);
if (overwrite_works(value)) {
@ -3265,14 +3231,14 @@ char load_config_file(const char *f)
if(out_to_x.get(*state)) {
current_text_color = default_color.get(*state);
}
if (out_to_x.get(*state) && (output_methods & TO_NCURSES)) {
if (out_to_x.get(*state) && out_to_ncurses.get(*state)) {
NORM_ERR("out_to_x and out_to_ncurses are incompatible, turning out_to_ncurses off");
output_methods &= ~TO_NCURSES;
endwin();
state->pushboolean(false);
out_to_ncurses.lua_set(*state);
}
#endif /* BUILD_X11 */
if ((out_to_stdout.get(*state) || out_to_stderr.get(*state))
&& (output_methods & TO_NCURSES)) {
&& out_to_ncurses.get(*state)) {
NORM_ERR("out_to_ncurses conflicts with out_to_console and out_to_stderr, disabling the later ones");
// XXX: this will need some rethinking
state->pushboolean(false);

View File

@ -324,9 +324,6 @@ extern std::string current_config;
#define TO_STDERR 4
#define OVERWRITE_FILE 8
#define APPEND_FILE 16
#ifdef BUILD_NCURSES
#define TO_NCURSES 32
#endif /* BUILD_NCURSES */
enum x_initialiser_state {
NO = 0,
YES = 1,

View File

@ -63,6 +63,7 @@
#include "mixer.h"
#include "mail.h"
#include "mboxscan.h"
#include "nc.h"
#include "net_stat.h"
#ifdef BUILD_NVIDIA
#include "nvidia.h"
@ -78,10 +79,6 @@
#include "user.h"
#include "users.h"
#ifdef BUILD_NCURSES
#include <ncurses.h>
#endif
/* check for OS and include appropriate headers */
#if defined(__linux__)
#include "linux.h"
@ -505,7 +502,7 @@ struct text_object *construct_text_object(char *s, const char *arg, long
}
#endif /* BUILD_X11 */
#ifdef BUILD_NCURSES
if (output_methods & TO_NCURSES) {
if (out_to_ncurses.get(*state)) {
obj->data.l = COLOR_WHITE;
if(arg) {
if(strcasecmp(arg, "red") == 0) {

35
src/nc.cc Normal file
View File

@ -0,0 +1,35 @@
/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
*/
#include <config.h>
#include "nc.h"
namespace priv {
void out_to_ncurses_setting::lua_setter(lua::state &l, bool init)
{
lua::stack_sentry s(l, -2);
Base::lua_setter(l, init);
if(init && do_convert(l, -1).first) {
initscr();
start_color();
}
++s;
}
void out_to_ncurses_setting::cleanup(lua::state &l)
{
lua::stack_sentry s(l, -1);
if(do_convert(l, -1).first)
endwin();
l.pop();
}
}
priv::out_to_ncurses_setting out_to_ncurses;

View File

@ -2,13 +2,34 @@
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
*/
#ifndef CONKY_NC_H
#if defined(BUILD_NCURSES) && !defined(CONKY_NC_H)
#define CONKY_NC_H
#include <ncurses.h>
#include "setting.hh"
#ifdef LEAKFREE_NCURSES
extern "C" {
void _nc_free_and_exit(int);
}
#endif
namespace priv {
class out_to_ncurses_setting: public conky::simple_config_setting<bool> {
typedef conky::simple_config_setting<bool> Base;
protected:
virtual void lua_setter(lua::state &l, bool init);
virtual void cleanup(lua::state &l);
public:
out_to_ncurses_setting()
: Base("out_to_ncurses", false, false)
{}
};
}
extern priv::out_to_ncurses_setting out_to_ncurses;
#endif /* CONKY_NC_H */

View File

@ -33,6 +33,7 @@
#include "fonts.h"
#endif /* BUILD_X11 */
#include "logging.h"
#include "nc.h"
#include "specials.h"
#include <math.h>
#ifdef HAVE_SYS_PARAM_H
@ -484,7 +485,7 @@ void new_fg(struct text_object *obj, char *p, int p_max_size)
new_special(p, FG)->arg = obj->data.l;
#endif /* BUILD_X11 */
#ifdef BUILD_NCURSES
if (output_methods & TO_NCURSES)
if (out_to_ncurses.get(*state))
new_special(p, FG)->arg = obj->data.l;
#endif /* BUILD_NCURSES */
UNUSED(obj);