Simple output gathering design
[sysstatus.git] / src / status / temp.c
index e6763d08ebf5f63e06432539b44ef4b69b423a74..c102fcd776585c25de77759af53aa8e62fbf3ccf 100644 (file)
@@ -2,15 +2,22 @@
 #include <fcntl.h>
 #include <unistd.h>
 
-#include "status/temp.h"
+#include "common.h"
 #include "tools.h"
 
 
-void status_temp(char *title, char *sysfile)
+void status_temp(GlobalData *g, char *title, char *sysfile)
 {
+  StatusItem s;
+  char text[16] = { 0 };
+
   char stline[16];
   ssize_t stlen;
 
+
+  statusitem_init(&s);
+  s.text = text;
+
   stlen = fileRead(stline, sizeof(stline), sysfile);
   if (stlen <= 0) {
     return;
@@ -21,16 +28,14 @@ void status_temp(char *title, char *sysfile)
    * Sometimes we get garbage from sysfs...
    */
   if (stlen < 6 || stlen > 7) {
-    printf(" ^fg(red)%sERROR ", title);
-    return;
+    s.color = "red";
+    snprintf(text, sizeof(text), "%sERROR", title);
+  } else {
+    stline[stlen - 4] = '\0';
+
+    s.color = "#FF33FF";
+    snprintf(text, sizeof(text), "%s%s°C", title, stline);
   }
 
-  fputs(" ^fg(#FF33FF)", stdout);
-  fputs(title, stdout);
-  fwrite(stline, 1, stlen - 4, stdout);
-  /*
-  fputs(".", stdout);
-  fwrite(&stline[stlen - 3], 1, 1, stdout);
-  */
-  fputs("°C ", stdout);
+  line_append_item(g, &s);
 }