1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2025-02-04 13:08:31 +00:00

implement ASCII gauge and enable all gauge objects for use with no X

This commit is contained in:
Phil Sutter 2009-11-22 01:55:29 +01:00
parent c2eb77c3f0
commit 66df73f74a
6 changed files with 45 additions and 30 deletions

View File

@ -895,10 +895,8 @@ void generate_text_internal(char *p, int p_max_size,
percent_print(p, p_max_size, percent_print(p, p_max_size,
round_to_int(cur->cpu_usage[obj->data.i] * 100.0)); round_to_int(cur->cpu_usage[obj->data.i] * 100.0));
} }
#ifdef X11
OBJ(cpugauge) OBJ(cpugauge)
new_gauge(obj, p, round_to_int(cur->cpu_usage[obj->data.i] * 255.0)); new_gauge(obj, p, p_max_size, round_to_int(cur->cpu_usage[obj->data.i] * 255.0));
#endif /* X11 */
OBJ(cpubar) { OBJ(cpubar) {
new_bar(obj, p, p_max_size, round_to_int(cur->cpu_usage[obj->data.i] * 255.0)); new_bar(obj, p, p_max_size, round_to_int(cur->cpu_usage[obj->data.i] * 255.0));
} }
@ -1113,11 +1111,9 @@ void generate_text_internal(char *p, int p_max_size,
OBJ(execp) { OBJ(execp) {
print_execp(obj, p, p_max_size); print_execp(obj, p, p_max_size);
} }
#ifdef X11
OBJ(execgauge) { OBJ(execgauge) {
print_execgauge(obj, p, p_max_size); print_execgauge(obj, p, p_max_size);
} }
#endif /* X11 */
OBJ(execbar) { OBJ(execbar) {
print_execbar(obj, p, p_max_size); print_execbar(obj, p, p_max_size);
} }
@ -1133,10 +1129,10 @@ void generate_text_internal(char *p, int p_max_size,
OBJ(execigraph) { OBJ(execigraph) {
print_execigraph(obj, p, p_max_size); print_execigraph(obj, p, p_max_size);
} }
#endif /* X11 */
OBJ(execigauge) { OBJ(execigauge) {
print_execigauge(obj, p, p_max_size); print_execigauge(obj, p, p_max_size);
} }
#endif /* X11 */
OBJ(execi) { OBJ(execi) {
print_execi(obj, p, p_max_size); print_execi(obj, p, p_max_size);
} }
@ -1238,10 +1234,10 @@ void generate_text_internal(char *p, int p_max_size,
OBJ(lua_graph) { OBJ(lua_graph) {
print_lua_graph(obj, p, p_max_size); print_lua_graph(obj, p, p_max_size);
} }
#endif /* X11 */
OBJ(lua_gauge) { OBJ(lua_gauge) {
print_lua_gauge(obj, p, p_max_size); print_lua_gauge(obj, p, p_max_size);
} }
#endif /* X11 */
#endif /* HAVE_LUA */ #endif /* HAVE_LUA */
#ifdef HDDTEMP #ifdef HDDTEMP
OBJ(hddtemp) { OBJ(hddtemp) {
@ -1369,11 +1365,9 @@ void generate_text_internal(char *p, int p_max_size,
if (cur->memmax) if (cur->memmax)
percent_print(p, p_max_size, cur->mem * 100 / cur->memmax); percent_print(p, p_max_size, cur->mem * 100 / cur->memmax);
} }
#ifdef X11
OBJ(memgauge){ OBJ(memgauge){
new_gauge(obj, p, cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0); new_gauge(obj, p, p_max_size, cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0);
} }
#endif /* X11 */
OBJ(membar) { OBJ(membar) {
new_bar(obj, p, p_max_size, cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0); new_bar(obj, p, p_max_size, cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0);
} }
@ -2333,12 +2327,12 @@ void generate_text_internal(char *p, int p_max_size,
progress = atof(cur->apcupsd.items[APCUPSD_LOAD]); progress = atof(cur->apcupsd.items[APCUPSD_LOAD]);
new_graph(obj, p, (int)progress); new_graph(obj, p, (int)progress);
} }
#endif /* X11 */
OBJ(apcupsd_loadgauge) { OBJ(apcupsd_loadgauge) {
double progress; double progress;
progress = atof(cur->apcupsd.items[APCUPSD_LOAD]) / 100.0 * 255.0; progress = atof(cur->apcupsd.items[APCUPSD_LOAD]) / 100.0 * 255.0;
new_gauge(obj, p, (int)progress); new_gauge(obj, p, p_max_size, (int)progress);
} }
#endif /* X11 */
OBJ(apcupsd_charge) { OBJ(apcupsd_charge) {
snprintf(p, p_max_size, "%s", snprintf(p, p_max_size, "%s",
cur->apcupsd.items[APCUPSD_CHARGE]); cur->apcupsd.items[APCUPSD_CHARGE]);

View File

@ -339,12 +339,10 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
END OBJ(cpu, &update_cpu_usage) END OBJ(cpu, &update_cpu_usage)
SCAN_CPU(arg, obj->data.i); SCAN_CPU(arg, obj->data.i);
DBGP2("Adding $cpu for CPU %d", obj->data.i); DBGP2("Adding $cpu for CPU %d", obj->data.i);
#ifdef X11
END OBJ(cpugauge, &update_cpu_usage) END OBJ(cpugauge, &update_cpu_usage)
SCAN_CPU(arg, obj->data.i); SCAN_CPU(arg, obj->data.i);
scan_gauge(obj, arg); scan_gauge(obj, arg);
DBGP2("Adding $cpugauge for CPU %d", obj->data.i); DBGP2("Adding $cpugauge for CPU %d", obj->data.i);
#endif /* X11 */
END OBJ(cpubar, &update_cpu_usage) END OBJ(cpubar, &update_cpu_usage)
SCAN_CPU(arg, obj->data.i); SCAN_CPU(arg, obj->data.i);
scan_bar(obj, arg); scan_bar(obj, arg);
@ -471,9 +469,9 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
scan_exec_arg(obj, arg); scan_exec_arg(obj, arg);
END OBJ(execbar, 0) END OBJ(execbar, 0)
scan_exec_arg(obj, arg); scan_exec_arg(obj, arg);
#ifdef X11
END OBJ(execgauge, 0) END OBJ(execgauge, 0)
scan_exec_arg(obj, arg); scan_exec_arg(obj, arg);
#ifdef X11
END OBJ(execgraph, 0) END OBJ(execgraph, 0)
scan_execgraph_arg(obj, arg); scan_execgraph_arg(obj, arg);
#endif /* X11 */ #endif /* X11 */
@ -482,9 +480,9 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
#ifdef X11 #ifdef X11
END OBJ_ARG(execigraph, 0, "execigraph needs arguments") END OBJ_ARG(execigraph, 0, "execigraph needs arguments")
scan_execgraph_arg(obj, arg); scan_execgraph_arg(obj, arg);
#endif /* X11 */
END OBJ_ARG(execigauge, 0, "execigauge needs arguments") END OBJ_ARG(execigauge, 0, "execigauge needs arguments")
scan_execi_arg(obj, arg); scan_execi_arg(obj, arg);
#endif /* X11 */
END OBJ_ARG(execi, 0, "execi needs arguments") END OBJ_ARG(execi, 0, "execi needs arguments")
scan_execi_arg(obj, arg); scan_execi_arg(obj, arg);
END OBJ_ARG(execpi, 0, "execpi needs arguments") END OBJ_ARG(execpi, 0, "execpi needs arguments")
@ -609,10 +607,8 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
END OBJ(memfree, &update_meminfo) END OBJ(memfree, &update_meminfo)
END OBJ(memmax, &update_meminfo) END OBJ(memmax, &update_meminfo)
END OBJ(memperc, &update_meminfo) END OBJ(memperc, &update_meminfo)
#ifdef X11
END OBJ(memgauge, &update_meminfo) END OBJ(memgauge, &update_meminfo)
scan_gauge(obj, arg); scan_gauge(obj, arg);
#endif /* X11*/
END OBJ(membar, &update_meminfo) END OBJ(membar, &update_meminfo)
scan_bar(obj, arg); scan_bar(obj, arg);
#ifdef X11 #ifdef X11
@ -1041,6 +1037,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
} else { } else {
CRIT_ERR(obj, free_at_crash, "lua_graph needs arguments: <function name> [height],[width] [gradient colour 1] [gradient colour 2] [scale] [-t] [-l]"); CRIT_ERR(obj, free_at_crash, "lua_graph needs arguments: <function name> [height],[width] [gradient colour 1] [gradient colour 2] [scale] [-t] [-l]");
} }
#endif /* X11 */
END OBJ_ARG(lua_gauge, 0, "lua_gauge needs arguments: <height>,<width> <function name> [function parameters]") END OBJ_ARG(lua_gauge, 0, "lua_gauge needs arguments: <height>,<width> <function name> [function parameters]")
arg = scan_gauge(obj, arg); arg = scan_gauge(obj, arg);
if (arg) { if (arg) {
@ -1048,7 +1045,6 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
} else { } else {
CRIT_ERR(obj, free_at_crash, "lua_gauge needs arguments: <height>,<width> <function name> [function parameters]"); CRIT_ERR(obj, free_at_crash, "lua_gauge needs arguments: <height>,<width> <function name> [function parameters]");
} }
#endif /* X11 */
#endif /* HAVE_LUA */ #endif /* HAVE_LUA */
#ifdef HDDTEMP #ifdef HDDTEMP
END OBJ(hddtemp, &update_hddtemp) END OBJ(hddtemp, &update_hddtemp)
@ -1119,9 +1115,9 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
char* buf = 0; char* buf = 0;
buf = scan_graph(obj, arg, 0); buf = scan_graph(obj, arg, 0);
if (buf) free(buf); if (buf) free(buf);
#endif /* X11 */
END OBJ(apcupsd_loadgauge, &update_apcupsd) END OBJ(apcupsd_loadgauge, &update_apcupsd)
scan_gauge(obj, arg); scan_gauge(obj, arg);
#endif /* X11 */
END OBJ(apcupsd_charge, &update_apcupsd) END OBJ(apcupsd_charge, &update_apcupsd)
END OBJ(apcupsd_timeleft, &update_apcupsd) END OBJ(apcupsd_timeleft, &update_apcupsd)
END OBJ(apcupsd_temp, &update_apcupsd) END OBJ(apcupsd_temp, &update_apcupsd)
@ -1476,8 +1472,8 @@ void free_text_objects(struct text_object *root, int internal)
break; break;
case OBJ_exec: case OBJ_exec:
case OBJ_execbar: case OBJ_execbar:
#ifdef X11
case OBJ_execgauge: case OBJ_execgauge:
#ifdef X11
case OBJ_execgraph: case OBJ_execgraph:
#endif #endif
case OBJ_execp: case OBJ_execp:
@ -1617,8 +1613,8 @@ void free_text_objects(struct text_object *root, int internal)
case OBJ_lua_bar: case OBJ_lua_bar:
#ifdef X11 #ifdef X11
case OBJ_lua_graph: case OBJ_lua_graph:
case OBJ_lua_gauge:
#endif /* X11 */ #endif /* X11 */
case OBJ_lua_gauge:
free(data.s); free(data.s);
break; break;
#endif /* HAVE_LUA */ #endif /* HAVE_LUA */
@ -1641,8 +1637,8 @@ void free_text_objects(struct text_object *root, int internal)
case OBJ_texeci: case OBJ_texeci:
#ifdef X11 #ifdef X11
case OBJ_execigraph: case OBJ_execigraph:
case OBJ_execigauge:
#endif /* X11 */ #endif /* X11 */
case OBJ_execigauge:
free_execi(obj); free_execi(obj);
break; break;
case OBJ_nameserver: case OBJ_nameserver:
@ -1777,8 +1773,8 @@ void free_text_objects(struct text_object *root, int internal)
case OBJ_apcupsd_loadbar: case OBJ_apcupsd_loadbar:
#ifdef X11 #ifdef X11
case OBJ_apcupsd_loadgraph: case OBJ_apcupsd_loadgraph:
case OBJ_apcupsd_loadgauge:
#endif /* X11 */ #endif /* X11 */
case OBJ_apcupsd_loadgauge:
case OBJ_apcupsd_charge: case OBJ_apcupsd_charge:
case OBJ_apcupsd_timeleft: case OBJ_apcupsd_timeleft:
case OBJ_apcupsd_temp: case OBJ_apcupsd_temp:

View File

@ -371,7 +371,7 @@ void print_execgauge(struct text_object *obj, char *p, int p_max_size)
if (barnum >= 0.0) { if (barnum >= 0.0) {
barnum /= 100; barnum /= 100;
new_gauge(obj, p, round_to_int(barnum * 255.0)); new_gauge(obj, p, p_max_size, round_to_int(barnum * 255.0));
} }
} }
@ -430,7 +430,7 @@ void print_execigauge(struct text_object *obj, char *p, int p_max_size)
} }
ed->last_update = current_update_time; ed->last_update = current_update_time;
} }
new_gauge(obj, p, round_to_int(ed->barnum)); new_gauge(obj, p, p_max_size, round_to_int(ed->barnum));
} }
#endif /* X11 */ #endif /* X11 */

View File

@ -575,7 +575,7 @@ void print_lua_gauge(struct text_object *obj, char *p, int p_max_size)
return; return;
if (llua_getnumber(obj->data.s, &per)) { if (llua_getnumber(obj->data.s, &per)) {
new_gauge(obj, p, (per/100.0 * 255)); new_gauge(obj, p, p_max_size, (per/100.0 * 255));
} }
} }
#endif /* X11 */ #endif /* X11 */

View File

@ -245,8 +245,16 @@ static struct special_t *new_special(char *buf, enum special_types t)
return &specials[special_count++]; return &specials[special_count++];
} }
void new_gauge_in_shell(struct text_object *obj, char *p, int p_max_size, int usage)
{
static const char *gaugevals[] = { "_. ", "\\. ", " | ", " ./", " ._" };
(void)obj;
snprintf(p, p_max_size, "%s", gaugevals[round_to_int((double)usage * 4 / 255)]);
}
#ifdef X11 #ifdef X11
void new_gauge(struct text_object *obj, char *buf, int usage) void new_gauge_in_x11(struct text_object *obj, char *buf, int usage)
{ {
struct special_t *s = 0; struct special_t *s = 0;
struct gauge *g = obj->special_data; struct gauge *g = obj->special_data;
@ -259,11 +267,28 @@ void new_gauge(struct text_object *obj, char *buf, int usage)
s = new_special(buf, GAUGE); s = new_special(buf, GAUGE);
s->arg = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage); s->arg = usage;
s->width = g->width; s->width = g->width;
s->height = g->height; s->height = g->height;
} }
#endif /* X11 */
void new_gauge(struct text_object *obj, char *p, int p_max_size, int usage)
{
if (!p_max_size)
return;
usage = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage);
#ifdef X11
if (output_methods & TO_X)
new_gauge_in_x11(obj, p, usage);
else
#endif /* X11 */
new_gauge_in_shell(obj, p, p_max_size, usage);
}
#ifdef X11
void new_font(char *buf, char *args) void new_font(char *buf, char *args)
{ {
if ((output_methods & TO_X) == 0) if ((output_methods & TO_X) == 0)

View File

@ -103,7 +103,7 @@ void scan_tab(struct text_object *, const char *);
void scan_stippled_hr(struct text_object *, const char*); void scan_stippled_hr(struct text_object *, const char*);
/* printing specials */ /* printing specials */
void new_gauge(struct text_object *, char *, int); void new_gauge(struct text_object *, char *, int, int);
void new_bar(struct text_object *, char *, int, int); void new_bar(struct text_object *, char *, int, int);
void new_font(char *, char *); void new_font(char *, char *);
void new_graph(struct text_object *, char *, double); void new_graph(struct text_object *, char *, double);