diff options
Diffstat (limited to 'src/status/uptime.c')
-rw-r--r-- | src/status/uptime.c | 83 |
1 files changed, 48 insertions, 35 deletions
diff --git a/src/status/uptime.c b/src/status/uptime.c index 106051c..ef5b2e5 100644 --- a/src/status/uptime.c +++ b/src/status/uptime.c @@ -3,57 +3,70 @@ #include <unistd.h> #include <stdlib.h> -#include "status/uptime.h" +#include "common.h" #include "tools.h" #include "config.h" -void status_uptime() +void status_uptime(GlobalData *g) { + StatusItem s; + char text[16] = { 0 }; + char stline[16]; ssize_t stlen; int i; int upts, uptm, upth, uptd; - fputs(" ^fg(#AAAAAA)up: ", stdout); + + statusitem_init(&s); + s.text = text; stlen = fileRead(stline, sizeof(stline), "/proc/uptime"); if (stlen < 0) { - fputs(" ^fg(red)ERROR ", stdout); - return; - } + s.color = "red"; + s.text = "up: ERROR"; + } else { + unsigned textlen = 0; - /* Cut first element */ - for(i = 0; i < stlen; i++) { - if (stline[i] == ' ') { - stline[i] = '\0'; - break; + /* Cut first element */ + for(i = 0; i < stlen; i++) { + if (stline[i] == ' ') { + stline[i] = '\0'; + break; + } } - } - // Split time into days, hours, mins, secs - upts = atoi(stline); - uptd = upts / (24 * 60 * 60); - upts -= uptd * (24 * 60 * 60); - upth = upts / (60 * 60); - upts -= upth * (60 * 60); - uptm = upts / (60); - upts -= uptm * (60); - - if (uptd > 0) { - printf("%dd ", uptd); - } + // Split time into days, hours, mins, secs + upts = atoi(stline); + uptd = upts / (24 * 60 * 60); + upts -= uptd * (24 * 60 * 60); + upth = upts / (60 * 60); + upts -= upth * (60 * 60); + uptm = upts / (60); + upts -= uptm * (60); - printf("%d:%.2d" - #ifdef SHOW_SECONDS - ":%.2d" - #endif + s.color = "#AAAAAA"; + textlen = snprintf(text, sizeof(text), "up: "); + if (uptd > 0) { + textlen += snprintf(&text[textlen], sizeof(text) - textlen, "%dd ", uptd); + } + + + snprintf(&text[textlen], sizeof(text) - textlen, + "%d:%.2d" + #ifdef SHOW_SECONDS + ":%.2d" + #endif - " " - ,upth - ,uptm + "" + ,upth + ,uptm - #ifdef SHOW_SECONDS - ,upts - #endif - ); + #ifdef SHOW_SECONDS + ,upts + #endif + ); + + line_append_item(g, &s); + } } |