From 69497249f2f423b50b3385a83da3ac9a418166c9 Mon Sep 17 00:00:00 2001 From: norly Date: Fri, 15 Feb 2013 03:21:26 +0000 Subject: Simple output gathering design Buffer all output up using snprintf() before printing an entire line at once. Modularizes the output format so alternatives to dzen2 can be used. ALSA volume status loses clickability. --- src/status/datetime.c | 61 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 22 deletions(-) (limited to 'src/status/datetime.c') diff --git a/src/status/datetime.c b/src/status/datetime.c index a25d411..d7d9d0a 100644 --- a/src/status/datetime.c +++ b/src/status/datetime.c @@ -1,36 +1,53 @@ #include #include -#include "status/datetime.h" +#include "common.h" #include "config.h" -void status_datetime() +void status_datetime(GlobalData *g) { + StatusItem s; + char text[32] = { 0 }; + time_t nows = 0; struct tm *nowtm; + + statusitem_init(&s); + s.text = text; + nows = time(NULL); if (nows == ((time_t) -1)) { - printf(" ^fg(red)ERROR: DATETIME"); - return; - } + s.color = "red"; + s.text = "ERROR: DATETIME"; - nowtm = localtime(&nows); - - printf(" ^fg(#666666)%d.%d.%d ^fg(grey)%d:%.2d" - #ifdef SHOW_SECONDS - ":%.2d" - #endif - " " - ,nowtm -> tm_mday, - (nowtm -> tm_mon) + 1, - (nowtm -> tm_year) + 1900, - nowtm -> tm_hour, - nowtm -> tm_min - - #ifdef SHOW_SECONDS - ,nowtm -> tm_sec - #endif - ); + line_append_item(g, &s); + } else { + nowtm = localtime(&nows); + + s.color = "#666666"; + snprintf(text, sizeof(text), + "%d.%d.%d", + nowtm->tm_mday, + (nowtm->tm_mon) + 1, + (nowtm->tm_year) + 1900 + ); + line_append_item(g, &s); + + s.color = "grey"; + snprintf(text, sizeof(text), + "%d:%.2d" + #ifdef SHOW_SECONDS + ":%.2d" + #endif + ,nowtm->tm_hour, + nowtm->tm_min + + #ifdef SHOW_SECONDS + ,nowtm -> tm_sec + #endif + ); + line_append_item(g, &s); + } } -- cgit v1.2.3