mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-12-24 11:55:43 +00:00
$execibar $execigraph
git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky@155 7f574dfc-610e-0410-a909-a81674777703
This commit is contained in:
parent
36f808f297
commit
033002fcd8
@ -1,5 +1,8 @@
|
||||
# $Id$
|
||||
|
||||
2005-08-22
|
||||
* Added $execibar and $execigraph
|
||||
|
||||
2005-08-21
|
||||
* Moved source into src/, moved docs into doc/
|
||||
* Updated makefiles
|
||||
|
14
README
14
README
@ -361,19 +361,19 @@ VARIABLES
|
||||
else Text to show if any of the above are not true
|
||||
|
||||
|
||||
exec shell command
|
||||
exec command
|
||||
Executes a shell command and displays the output in conky. warn-
|
||||
ing: this takes a lot more resources than other variables. I'd
|
||||
recommend coding wanted behaviour in C and posting a patch.
|
||||
|
||||
|
||||
execbar shell command
|
||||
execbar command
|
||||
Same as exec, except if the first value return is a value
|
||||
between 0-100, it will use that number for a bar. The size for
|
||||
the bar is currently fixed, but that may change in the future.
|
||||
|
||||
|
||||
execgraph shell command
|
||||
execgraph command
|
||||
Same as execbar, but graphs values
|
||||
|
||||
|
||||
@ -382,6 +382,14 @@ VARIABLES
|
||||
than update_interval in configuration.
|
||||
|
||||
|
||||
execibar interval command
|
||||
Same as execbar, except with an interval
|
||||
|
||||
|
||||
execigraph interval command
|
||||
Same as execigraph, but takes an interval arg graphs values
|
||||
|
||||
|
||||
font font
|
||||
Specify a different font. Only applies to one line.
|
||||
|
||||
|
@ -192,7 +192,7 @@
|
||||
<varlistentry>
|
||||
<term>
|
||||
<command><option>exec</option></command>
|
||||
<option>shell command</option>
|
||||
<option>command</option>
|
||||
</term>
|
||||
<listitem>
|
||||
Executes a shell command and displays the output in conky. warning: this takes a lot more resources than other variables. I'd recommend coding wanted behaviour in C and posting a patch.
|
||||
@ -202,7 +202,7 @@
|
||||
<varlistentry>
|
||||
<term>
|
||||
<command><option>execbar</option></command>
|
||||
<option>shell command</option>
|
||||
<option>command</option>
|
||||
</term>
|
||||
<listitem>
|
||||
Same as exec, except if the first value return is a value between 0-100, it will use that number for a bar. The size for the bar is currently fixed, but that may change in the future.
|
||||
@ -212,7 +212,7 @@
|
||||
<varlistentry>
|
||||
<term>
|
||||
<command><option>execgraph</option></command>
|
||||
<option>shell command</option>
|
||||
<option>command</option>
|
||||
</term>
|
||||
<listitem>
|
||||
Same as execbar, but graphs values
|
||||
@ -222,11 +222,31 @@
|
||||
<varlistentry>
|
||||
<term>
|
||||
<command><option>execi</option></command>
|
||||
<option>interval, shell command</option>
|
||||
<option>interval, shell command</option>
|
||||
</term>
|
||||
<listitem>
|
||||
Same as exec but with specific interval. Interval can't be less than update_interval in configuration.
|
||||
<para></para></listitem>
|
||||
<para></para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term>
|
||||
<command><option>execibar</option></command>
|
||||
<option>interval command</option>
|
||||
</term>
|
||||
<listitem>
|
||||
Same as execbar, except with an interval
|
||||
<para></para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term>
|
||||
<command><option>execigraph</option></command>
|
||||
<option>interval command</option>
|
||||
</term>
|
||||
<listitem>
|
||||
Same as execigraph, but takes an interval arg graphs values
|
||||
<para></para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
|
118
src/conky.c
118
src/conky.c
@ -515,7 +515,7 @@ inline void graph_append(struct special_t *graph, double f)
|
||||
}
|
||||
}
|
||||
|
||||
static void new_graph(char *buf, int w, int h, unsigned int first_colour, unsigned int second_colour, double i, int scaled)
|
||||
static void new_graph(char *buf, int w, int h, unsigned int first_colour, unsigned int second_colour, double i, int scaled, int append)
|
||||
{
|
||||
struct special_t *s = new_special(buf, GRAPH);
|
||||
s->width = w;
|
||||
@ -531,7 +531,9 @@ static void new_graph(char *buf, int w, int h, unsigned int first_colour, unsign
|
||||
} else {
|
||||
s->graph_scale = 100;
|
||||
}
|
||||
graph_append(s, i);
|
||||
if (append) {
|
||||
graph_append(s, i);
|
||||
}
|
||||
}
|
||||
|
||||
static const char *scan_graph(const char *args, int *w, int *h, unsigned int *first_colour, unsigned int *last_colour)
|
||||
@ -701,6 +703,8 @@ enum text_object_type {
|
||||
OBJ_execi,
|
||||
OBJ_execbar,
|
||||
OBJ_execgraph,
|
||||
OBJ_execibar,
|
||||
OBJ_execigraph,
|
||||
OBJ_freq,
|
||||
OBJ_freq_g,
|
||||
OBJ_fs_bar,
|
||||
@ -847,6 +851,7 @@ struct text_object {
|
||||
float interval;
|
||||
char *cmd;
|
||||
char *buffer;
|
||||
double data;
|
||||
} execi; /* 5 */
|
||||
|
||||
struct {
|
||||
@ -875,7 +880,6 @@ static struct text_object *new_text_object()
|
||||
static void free_text_objects()
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < text_object_count; i++) {
|
||||
switch (text_objects[i].type) {
|
||||
case OBJ_acpitemp:
|
||||
@ -896,8 +900,20 @@ static void free_text_objects()
|
||||
break;
|
||||
case OBJ_text:
|
||||
case OBJ_exec:
|
||||
free(text_objects[i].data.s);
|
||||
break;
|
||||
case OBJ_execbar:
|
||||
free(text_objects[i].data.s);
|
||||
break;
|
||||
case OBJ_execgraph:
|
||||
free(text_objects[i].data.s);
|
||||
break;
|
||||
/* case OBJ_execibar:
|
||||
free(text_objects[i].data.s);
|
||||
break;
|
||||
case OBJ_execigraph:
|
||||
free(text_objects[i].data.s);
|
||||
break;*/
|
||||
#ifdef MPD
|
||||
case OBJ_mpd_title:
|
||||
case OBJ_mpd_artist:
|
||||
@ -1015,6 +1031,26 @@ if (s[0] == '#') {
|
||||
OBJ(exec, 0) obj->data.s = strdup(arg ? arg : "");
|
||||
END OBJ(execbar, 0) obj->data.s = strdup(arg ? arg : "");
|
||||
END OBJ(execgraph, 0) obj->data.s = strdup(arg ? arg : "");
|
||||
END OBJ(execibar, 0) unsigned int n;
|
||||
if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
|
||||
char buf[256];
|
||||
ERR("${execibar <interval> command}");
|
||||
obj->type = OBJ_text;
|
||||
snprintf(buf, 256, "${%s}", s);
|
||||
obj->data.s = strdup(buf);
|
||||
} else {
|
||||
obj->data.s = strdup(arg + n);
|
||||
}
|
||||
END OBJ(execigraph, 0) unsigned int n;
|
||||
if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
|
||||
char buf[256];
|
||||
ERR("${execigraph <interval> command}");
|
||||
obj->type = OBJ_text;
|
||||
snprintf(buf, 256, "${%s}", s);
|
||||
obj->data.s = strdup(buf);
|
||||
} else {
|
||||
obj->data.s = strdup(arg + n);
|
||||
}
|
||||
END OBJ(execi, 0) unsigned int n;
|
||||
|
||||
if (!arg
|
||||
@ -1628,7 +1664,7 @@ static void generate_text()
|
||||
new_graph(p, obj->a,
|
||||
obj->b, obj->c, obj->d,
|
||||
(unsigned int) (cur->cpu_usage *
|
||||
100), 0);
|
||||
100), 0, 1);
|
||||
}
|
||||
OBJ(color) {
|
||||
new_fg(p, obj->data.l);
|
||||
@ -1665,7 +1701,7 @@ static void generate_text()
|
||||
obj->data.net->recv_speed = 0.01;
|
||||
new_graph(p, obj->a, obj->b, obj->c, obj->d,
|
||||
(obj->data.net->recv_speed /
|
||||
1024.0), 1);
|
||||
1024.0), 1, 1);
|
||||
}
|
||||
OBJ(
|
||||
else
|
||||
@ -1736,8 +1772,7 @@ static void generate_text()
|
||||
ERR("your execbar value is not between 0 and 100, therefore it will be ignored");
|
||||
} else {
|
||||
barnum = barnum / 100.0;
|
||||
new_bar(p, 0,
|
||||
4, (int) (barnum * 255.0));
|
||||
new_bar(p, 0, 4, (int) (barnum * 255.0));
|
||||
}
|
||||
|
||||
}
|
||||
@ -1764,7 +1799,70 @@ static void generate_text()
|
||||
ERR("your execgraph value is not between 0 and 100, therefore it will be ignored");
|
||||
} else {
|
||||
new_graph(p, 0,
|
||||
25, obj->c, obj->d, (int) (barnum), 0);
|
||||
25, obj->c, obj->d, (int) (barnum), 0, 1);
|
||||
}
|
||||
|
||||
}
|
||||
OBJ(execibar) {
|
||||
if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
|
||||
new_bar(p, 0, 4, (int) obj->data.execi.data);
|
||||
} else {
|
||||
char *p2 = p;
|
||||
FILE *fp = popen(obj->data.s, "r");
|
||||
int n2 = fread(p, 1, n, fp);
|
||||
(void) pclose(fp);
|
||||
p[n2] = '\0';
|
||||
if (n2 && p[n2 - 1] == '\n')
|
||||
p[n2 - 1] = '\0';
|
||||
|
||||
while (*p2) {
|
||||
if (*p2 == '\001')
|
||||
*p2 = ' ';
|
||||
p2++;
|
||||
}
|
||||
double barnum;
|
||||
if (sscanf(p, "%lf", &barnum) == 0) {
|
||||
ERR("reading execibar value failed (perhaps it's not the correct format?)");
|
||||
}
|
||||
if (barnum > 100 || barnum < 0) {
|
||||
ERR("your execibar value is not between 0 and 100, therefore it will be ignored");
|
||||
} else {
|
||||
obj->data.execi.data = 255 * barnum / 100.0;
|
||||
new_bar(p, 0, 4, (int) obj->data.execi.data);
|
||||
}
|
||||
obj->data.execi.last_update =
|
||||
current_update_time;
|
||||
}
|
||||
}
|
||||
OBJ(execigraph) {
|
||||
if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
|
||||
new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->data.execi.data), 0, 0);
|
||||
} else {
|
||||
char *p2 = p;
|
||||
FILE *fp = popen(obj->data.s, "r");
|
||||
int n2 = fread(p, 1, n, fp);
|
||||
(void) pclose(fp);
|
||||
p[n2] = '\0';
|
||||
if (n2 && p[n2 - 1] == '\n')
|
||||
p[n2 - 1] = '\0';
|
||||
|
||||
while (*p2) {
|
||||
if (*p2 == '\001')
|
||||
*p2 = ' ';
|
||||
p2++;
|
||||
}
|
||||
double barnum;
|
||||
if (sscanf(p, "%lf", &barnum) == 0) {
|
||||
ERR("reading execigraph value failed (perhaps it's not the correct format?)");
|
||||
}
|
||||
if (barnum > 100 || barnum < 0) {
|
||||
ERR("your execigraph value is not between 0 and 100, therefore it will be ignored");
|
||||
} else {
|
||||
obj->data.execi.data = barnum;
|
||||
new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->data.execi.data), 0, 1);
|
||||
}
|
||||
obj->data.execi.last_update = current_update_time;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -2003,7 +2101,7 @@ static void generate_text()
|
||||
new_graph(p, obj->a,
|
||||
obj->b, obj->c, obj->d,
|
||||
cur->memmax ? (cur->mem * 100.0) /
|
||||
(cur->memmax) : 0.0, 0);
|
||||
(cur->memmax) : 0.0, 0, 1);
|
||||
}
|
||||
/* mixer stuff */
|
||||
OBJ(mixer) {
|
||||
@ -2206,7 +2304,7 @@ static void generate_text()
|
||||
obj->data.net->trans_speed = 0.01;
|
||||
new_graph(p, obj->a, obj->b, obj->c, obj->d,
|
||||
(obj->data.net->trans_speed /
|
||||
1024.0), 1);
|
||||
1024.0), 1, 1);
|
||||
}
|
||||
OBJ(uptime_short) {
|
||||
format_seconds_short(p, n,
|
||||
|
Loading…
Reference in New Issue
Block a user