implement ASCII gauge and enable all gauge objects for use with no X
authorPhil Sutter <phil@nwl.cc>
Sun, 22 Nov 2009 00:55:29 +0000 (01:55 +0100)
committerPhil Sutter <phil@nwl.cc>
Sun, 22 Nov 2009 01:09:46 +0000 (02:09 +0100)
src/conky.c
src/core.c
src/exec.c
src/llua.c
src/specials.c
src/specials.h

index 742d454..e7d28e1 100644 (file)
@@ -895,10 +895,8 @@ void generate_text_internal(char *p, int p_max_size,
                                percent_print(p, p_max_size,
                                              round_to_int(cur->cpu_usage[obj->data.i] * 100.0));
                        }
-#ifdef X11
                        OBJ(cpugauge)
-                               new_gauge(obj, p, round_to_int(cur->cpu_usage[obj->data.i] * 255.0));
-#endif /* X11 */
+                               new_gauge(obj, p, p_max_size, round_to_int(cur->cpu_usage[obj->data.i] * 255.0));
                        OBJ(cpubar) {
                                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) {
                                print_execp(obj, p, p_max_size);
                        }
-#ifdef X11
                        OBJ(execgauge) {
                                print_execgauge(obj, p, p_max_size);
                        }
-#endif /* X11 */
                        OBJ(execbar) {
                                print_execbar(obj, p, p_max_size);
                        }
@@ -1133,10 +1129,10 @@ void generate_text_internal(char *p, int p_max_size,
                        OBJ(execigraph) {
                                print_execigraph(obj, p, p_max_size);
                        }
+#endif /* X11 */
                        OBJ(execigauge) {
                                print_execigauge(obj, p, p_max_size);
                        }
-#endif /* X11 */
                        OBJ(execi) {
                                print_execi(obj, p, p_max_size);
                        }
@@ -1238,10 +1234,10 @@ void generate_text_internal(char *p, int p_max_size,
                        OBJ(lua_graph) {
                                print_lua_graph(obj, p, p_max_size);
                        }
+#endif /* X11 */
                        OBJ(lua_gauge) {
                                print_lua_gauge(obj, p, p_max_size);
                        }
-#endif /* X11 */
 #endif /* HAVE_LUA */
 #ifdef HDDTEMP
                        OBJ(hddtemp) {
@@ -1369,11 +1365,9 @@ void generate_text_internal(char *p, int p_max_size,
                                if (cur->memmax)
                                        percent_print(p, p_max_size, cur->mem * 100 / cur->memmax);
                        }
-#ifdef X11
                        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) {
                                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]);
                                new_graph(obj, p, (int)progress);
                        }
+#endif /* X11 */
                        OBJ(apcupsd_loadgauge) {
                                double progress;
                                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) {
                                snprintf(p, p_max_size, "%s",
                                                 cur->apcupsd.items[APCUPSD_CHARGE]);
index b1aea2d..e174174 100644 (file)
@@ -339,12 +339,10 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
        END OBJ(cpu, &update_cpu_usage)
                SCAN_CPU(arg, obj->data.i);
                DBGP2("Adding $cpu for CPU %d", obj->data.i);
-#ifdef X11
        END OBJ(cpugauge, &update_cpu_usage)
                SCAN_CPU(arg, obj->data.i);
                scan_gauge(obj, arg);
                DBGP2("Adding $cpugauge for CPU %d", obj->data.i);
-#endif /* X11 */
        END OBJ(cpubar, &update_cpu_usage)
                SCAN_CPU(arg, obj->data.i);
                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);
        END OBJ(execbar, 0)
                scan_exec_arg(obj, arg);
-#ifdef X11
        END OBJ(execgauge, 0)
                scan_exec_arg(obj, arg);
+#ifdef X11
        END OBJ(execgraph, 0)
                scan_execgraph_arg(obj, arg);
 #endif /* X11 */
@@ -482,9 +480,9 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
 #ifdef X11
        END OBJ_ARG(execigraph, 0, "execigraph needs arguments")
                scan_execgraph_arg(obj, arg);
+#endif /* X11 */
        END OBJ_ARG(execigauge, 0, "execigauge needs arguments")
                scan_execi_arg(obj, arg);
-#endif /* X11 */
        END OBJ_ARG(execi, 0, "execi needs arguments")
                scan_execi_arg(obj, arg);
        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(memmax, &update_meminfo)
        END OBJ(memperc, &update_meminfo)
-#ifdef X11
        END OBJ(memgauge, &update_meminfo)
                scan_gauge(obj, arg);
-#endif /* X11*/
        END OBJ(membar, &update_meminfo)
                scan_bar(obj, arg);
 #ifdef X11
@@ -1041,6 +1037,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                } else {
                        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]")
                arg = scan_gauge(obj, arg);
                if (arg) {
@@ -1048,7 +1045,6 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                } else {
                        CRIT_ERR(obj, free_at_crash, "lua_gauge needs arguments: <height>,<width> <function name> [function parameters]");
                }
-#endif /* X11 */
 #endif /* HAVE_LUA */
 #ifdef 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;
                buf = scan_graph(obj, arg, 0);
                if (buf) free(buf);
+#endif /* X11 */
        END OBJ(apcupsd_loadgauge, &update_apcupsd)
                scan_gauge(obj, arg);
-#endif /* X11 */
        END OBJ(apcupsd_charge, &update_apcupsd)
        END OBJ(apcupsd_timeleft, &update_apcupsd)
        END OBJ(apcupsd_temp, &update_apcupsd)
@@ -1476,8 +1472,8 @@ void free_text_objects(struct text_object *root, int internal)
                                break;
                        case OBJ_exec:
                        case OBJ_execbar:
-#ifdef X11
                        case OBJ_execgauge:
+#ifdef X11
                        case OBJ_execgraph:
 #endif
                        case OBJ_execp:
@@ -1617,8 +1613,8 @@ void free_text_objects(struct text_object *root, int internal)
                        case OBJ_lua_bar:
 #ifdef X11
                        case OBJ_lua_graph:
-                       case OBJ_lua_gauge:
 #endif /* X11 */
+                       case OBJ_lua_gauge:
                                free(data.s);
                                break;
 #endif /* HAVE_LUA */
@@ -1641,8 +1637,8 @@ void free_text_objects(struct text_object *root, int internal)
                        case OBJ_texeci:
 #ifdef X11
                        case OBJ_execigraph:
-                       case OBJ_execigauge:
 #endif /* X11 */
+                       case OBJ_execigauge:
                                free_execi(obj);
                                break;
                        case OBJ_nameserver:
@@ -1777,8 +1773,8 @@ void free_text_objects(struct text_object *root, int internal)
                        case OBJ_apcupsd_loadbar:
 #ifdef X11
                        case OBJ_apcupsd_loadgraph:
-                       case OBJ_apcupsd_loadgauge:
 #endif /* X11 */
+                       case OBJ_apcupsd_loadgauge:
                        case OBJ_apcupsd_charge:
                        case OBJ_apcupsd_timeleft:
                        case OBJ_apcupsd_temp:
index ce669ac..280e58c 100644 (file)
@@ -371,7 +371,7 @@ void print_execgauge(struct text_object *obj, char *p, int p_max_size)
 
        if (barnum >= 0.0) {
                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;
        }
-       new_gauge(obj, p, round_to_int(ed->barnum));
+       new_gauge(obj, p, p_max_size, round_to_int(ed->barnum));
 }
 #endif /* X11 */
 
index f983376..6153ea7 100644 (file)
@@ -575,7 +575,7 @@ void print_lua_gauge(struct text_object *obj, char *p, int p_max_size)
                return;
 
        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 */
index 101a0a6..a290413 100644 (file)
@@ -245,8 +245,16 @@ static struct special_t *new_special(char *buf, enum special_types t)
        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
-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 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->arg = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage);
+       s->arg = usage;
        s->width = g->width;
        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)
 {
        if ((output_methods & TO_X) == 0)
index cc0b34c..0d93fa9 100644 (file)
@@ -103,7 +103,7 @@ void scan_tab(struct text_object *, const char *);
 void scan_stippled_hr(struct text_object *, const char*);
 
 /* 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_font(char *, char *);
 void new_graph(struct text_object *, char *, double);