From 8ba334942e6d28505dbe256e231d562b279f0998 Mon Sep 17 00:00:00 2001 From: gotmor Date: Sat, 18 Aug 2007 00:42:39 +0000 Subject: conky style progressmeters for gdbar and gcpubar git-svn-id: http://dzen.googlecode.com/svn/trunk@158 f2baff5b-bf2c-0410-a398-912abdc3d8b2 --- gadgets/README.gcpubar | 2 ++ gadgets/README.gdbar | 1 + gadgets/gcpubar.c | 21 +++++++++++++++------ gadgets/gdbar.c | 29 ++++++++++++++++++++--------- 4 files changed, 38 insertions(+), 15 deletions(-) (limited to 'gadgets') diff --git a/gadgets/README.gcpubar b/gadgets/README.gcpubar index ec548cc..5d9ca36 100644 --- a/gadgets/README.gcpubar +++ b/gadgets/README.gcpubar @@ -26,6 +26,8 @@ Command line options: -bg : Meter background color (default: darkgrey) + -o : Toggle conky style meter drawing + -nonl: no new line, don't put '\n' at the end of the bar (default: do print '\n') diff --git a/gadgets/README.gdbar b/gadgets/README.gdbar index d3374b8..3bfbcde 100644 --- a/gadgets/README.gdbar +++ b/gadgets/README.gdbar @@ -21,6 +21,7 @@ Options: -h : bar height -l : label to be prepended to the bar (default: '' ) + -o : Draw conky style meters -nonl: no new line, don't put '\n' at the end of the bar (default: do print '\n') diff --git a/gadgets/gcpubar.c b/gadgets/gcpubar.c index ea96d1a..7d52b69 100644 --- a/gadgets/gcpubar.c +++ b/gadgets/gcpubar.c @@ -32,7 +32,7 @@ THE SOFTWARE. /* bar color for critical values */ #define CRITCOL "red" -static void pbar (double, int, int, int); +static void pbar (double, int, int, int, int); struct cpu_info { unsigned long long user; @@ -44,7 +44,7 @@ struct cpu_info { char *bg, *fg; static void -pbar(double perc, int maxc, int height, int print_nl) { +pbar(double perc, int maxc, int height, int print_nl, int mode) { int i, rp; double l; @@ -57,9 +57,14 @@ pbar(double perc, int maxc, int height, int print_nl) { else rp = (int)perc; - printf("CPU: %3d%% ^fg(%s)^r(%dx%d)^fg(%s)^r(%dx%d)^fg()%s", rp, - (rp>=CPUCRIT) ? CRITCOL : fg, (int)l, height, - bg, maxc-(int)l, height, print_nl ? "\n" : ""); + if(mode) + printf("CPU: %3d%% ^ib(1)^fg(%s)^ro(%dx%d)^p(%d)^fg(%s)^r(%dx%d)^fg()%s", + rp, bg, maxc, height, -1*(maxc-1), + (rp>=CPUCRIT) ? CRITCOL : fg, (int)l-2, height-2, print_nl ? "\n" : ""); + else + printf("CPU: %3d%% ^fg(%s)^r(%dx%d)^fg(%s)^r(%dx%d)^fg()%s", + rp, (rp>=CPUCRIT) ? CRITCOL : fg, (int)l, height, + bg, maxc-(int)l, height, print_nl ? "\n" : ""); fflush(stdout); } @@ -74,6 +79,7 @@ main(int argc, char *argv[]) char buf[256], *ep; /* defaults */ + int mode = 0; double ival = 1.0; int counts = 0; int barwidth = 100; @@ -92,6 +98,9 @@ main(int argc, char *argv[]) i++; } } + else if(!strncmp(argv[i], "-o", 3)) { + mode = 1; + } else if(!strncmp(argv[i], "-c", 3)) { if(++i < argc) counts = atoi(argv[i]); @@ -166,7 +175,7 @@ main(int argc, char *argv[]) total = (mcpu.user + mcpu.sys + mcpu.idle + mcpu.iowait) / 100.0; myload = (mcpu.user + mcpu.sys + mcpu.iowait) / total; - pbar(myload, barwidth, barheight, print_nl); + pbar(myload, barwidth, barheight, print_nl, mode); ocpu = ncpu; } } diff --git a/gadgets/gdbar.c b/gadgets/gdbar.c index 918caf0..3466b4f 100644 --- a/gadgets/gdbar.c +++ b/gadgets/gdbar.c @@ -31,13 +31,13 @@ THE SOFTWARE. #define MAXLEN 512 -static void pbar (const char *, double, int, int, int); +static void pbar (const char *, double, int, int, int, int); char *bg, *fg; static void -pbar(const char* label, double perc, int maxc, int height, int pnl) { +pbar(const char* label, double perc, int maxc, int height, int pnl, int mode) { int i, rp; double l; @@ -51,11 +51,18 @@ pbar(const char* label, double perc, int maxc, int height, int pnl) { else rp = (int)perc; - printf("%s %3d%% ^fg(%s)^r(%dx%d)^fg(%s)^r(%dx%d)^fg()%s", - label ? label : "", rp, - fg, (int)l, height, - bg, maxc-(int)l, height, - pnl ? "\n" : ""); + if(mode) + printf("%s %3d%% ^ib(1)^fg(%s)^ro(%dx%d)^p(%d)^fg(%s)^r(%dx%d)^p(%d)^ib(0)^fg()%s", + label ? label : "", rp, + bg, (int)maxc, height, -1*(maxc-1), + fg, (int)l, height-2, + maxc-(int)l-1, pnl ? "\n" : ""); + else + printf("%s %3d%% ^fg(%s)^r(%dx%d)^fg(%s)^r(%dx%d)^fg()%s", + label ? label : "", rp, + fg, (int)l, height, + bg, maxc-(int)l, height, + pnl ? "\n" : ""); fflush(stdout); } @@ -68,6 +75,7 @@ main(int argc, char *argv[]) char aval[MAXLEN], *endptr; /* defaults */ + int mode = 0; int barwidth = 80; int barheight = 10; double minval = 0; @@ -85,6 +93,9 @@ main(int argc, char *argv[]) if(++i < argc) barheight = atoi(argv[i]); } + else if(!strncmp(argv[i], "-o", 3)) { + mode = 1; + } else if(!strncmp(argv[i], "-fg", 4)) { if(++i < argc) fg = argv[i]; @@ -127,7 +138,7 @@ main(int argc, char *argv[]) print_nl = 0; } else { - fprintf(stderr, "usage: dbar [-w ] [-h ] [-fg ] [-bg ] [-min ] [-max ] [-l ] [-nonl]\n"); + fprintf(stderr, "usage: dbar [-w ] [-h ] [-fg ] [-bg ] [-min ] [-max ] [-l ] [-nonl] [-o]\n"); return EXIT_FAILURE; } } @@ -148,7 +159,7 @@ main(int argc, char *argv[]) minval = 0; } - pbar(label, (100*(val-minval))/(maxval-minval), barwidth, barheight, print_nl); + pbar(label, (100*(val-minval))/(maxval-minval), barwidth, barheight, print_nl, mode); } return EXIT_SUCCESS; -- cgit v1.2.3-54-g00ecf