Simple output gathering design
[sysstatus.git] / src / status / fan.c
index 0e7cfdfa0d050e52a619c79d3d893c52fe510427..6b266784934ced88169db3ae2769d2480dc95c17 100644 (file)
@@ -2,15 +2,22 @@
 #include <fcntl.h>
 #include <unistd.h>
 
-#include "status/fan.h"
+#include "common.h"
 #include "tools.h"
 
 
-void status_fan(char *title, char *sysfile)
+void status_fan(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;
@@ -18,12 +25,14 @@ void status_fan(char *title, char *sysfile)
 
   // Read a valid value? Sometimes we get garbage from sysfs...
   if (stlen > 5) {
-    printf(" ^fg(red)%sERROR ", title);
-    return;
+    s.color = "red";
+    snprintf(text, sizeof(text), "%sERROR", title);
+  } else {
+    stline[stlen - 1] = '\0';
+
+    s.color = "#CCCCCC";
+    snprintf(text, sizeof(text), "%s%s rpm", title, stline);
   }
 
-  fputs(" ^fg(#CCCCCC)", stdout);
-  fputs(title, stdout);
-  fwrite(stline, 1, stlen - 1, stdout);
-  fputs(" rpm ", stdout);
+  line_append_item(g, &s);
 }