]> git.sur5r.net Git - i3/i3status/blobdiff - src/output.c
Add support for path_exists directive.
[i3/i3status] / src / output.c
index d4d8c2f441d3ff02c91425a3827e7c98ec98c7b5..4473ca505fdf744317d3df3132231d13ee7ec3d7 100644 (file)
@@ -20,11 +20,23 @@ char *color(const char *colorstr) {
                 colorbuf[0] = '\0';
                 return colorbuf;
         }
-#ifdef DZEN
-        (void)snprintf(colorbuf, sizeof(colorbuf), "^fg(%s)", colorstr);
-#elif XMOBAR
-        (void)snprintf(colorbuf, sizeof(colorbuf), "<fc=%s>", colorstr);
-#endif
+        if (output_format == O_DZEN2)
+                (void)snprintf(colorbuf, sizeof(colorbuf), "^fg(%s)", cfg_getstr(cfg_general, colorstr));
+        else if (output_format == O_XMOBAR)
+                (void)snprintf(colorbuf, sizeof(colorbuf), "<fc=%s>", cfg_getstr(cfg_general, colorstr));
+        else if (output_format == O_TERM) {
+                /* The escape-sequence for color is <CSI><col>;1m (bright/bold
+                 * output), where col is a 3-bit rgb-value with b in the
+                 * least-significant bit. We round the given color to the
+                 * nearist 3-bit-depth color and output the escape-sequence */
+                char *str = cfg_getstr(cfg_general, colorstr);
+                int col = strtol(str + 1, NULL, 16);
+                int r = (col & (0xFF << 0)) / 0x80;
+                int g = (col & (0xFF << 8)) / 0x8000;
+                int b = (col & (0xFF << 16)) / 0x800000;
+                col = (r << 2) | (g << 1) | b;
+                (void)snprintf(colorbuf, sizeof(colorbuf), "\033[3%d;1m", col);
+        }
         return colorbuf;
 }
 
@@ -32,16 +44,28 @@ char *color(const char *colorstr) {
  * Some color formats (xmobar) require to terminate colors again
  *
  */
-char *endcolor() {
-#ifdef XMOBAR
-        return "</fc>";
-#else
-        return "";
-#endif
+char *endcolor(void) {
+        if (output_format == O_XMOBAR)
+                return "</fc>";
+        else if (output_format == O_TERM)
+                return "\033[0m";
+        else return "";
+}
+
+void print_seperator(void) {
+        if (output_format == O_DZEN2)
+                printf("^fg(%s)^p(5;-2)^ro(2)^p()^fg()^p(5)", cfg_getstr(cfg_general, "color_separator"));
+        else if (output_format == O_XMOBAR)
+                printf("<fc=%s> | </fc>", cfg_getstr(cfg_general, "color_separator"));
+        else if (output_format == O_TERM)
+                printf(" %s|%s ", color("color_separator"), endcolor());
+        else if (output_format == O_NONE)
+                printf(" | ");
 }
 
-void print_seperator() {
-#if defined(DZEN) || defined(XMOBAR)
-        printf("%s", BAR);
-#endif
+/*
+ * The term-output hides the cursor. We call this on exit to reset that.
+ */
+void reset_cursor(void) {
+        printf("\033[?25h");
 }