summaryrefslogtreecommitdiff
path: root/src/status/datetime.c
diff options
context:
space:
mode:
authornorly <ny-git@enpas.org>2013-02-15 03:21:26 +0000
committernorly <ny-git@enpas.org>2013-02-15 03:21:26 +0000
commit69497249f2f423b50b3385a83da3ac9a418166c9 (patch)
treeef4988bd7a59129f8aeb709c4fc9a9dced450bdc /src/status/datetime.c
parent430ce2a8749eb90ca0f8cdf18f5b217128c43e79 (diff)
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.
Diffstat (limited to 'src/status/datetime.c')
-rw-r--r--src/status/datetime.c61
1 files changed, 39 insertions, 22 deletions
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 <stdio.h>
#include <time.h>
-#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);
+ }
}