]> git.sur5r.net Git - i3/i3status/blobdiff - src/output.c
Merge pull request #201 from jasperla/openbsd_bat_info
[i3/i3status] / src / output.c
index b2fb1dd758f05a9b9265771305b577b00b6593eb..1c8c415ada6b4bf714e9e92caf8f52d36f0cc65b 100644 (file)
@@ -11,7 +11,8 @@
 #include "i3status.h"
 
 /*
- * Returns the correct color format for dzen (^fg(color)) or xmobar (<fc=color>)
+ * Returns the correct color format for dzen (^fg(color)), xmobar (<fc=color>)
+ * or lemonbar (%{Fcolor})
  *
  */
 char *color(const char *colorstr) {
@@ -24,6 +25,8 @@ char *color(const char *colorstr) {
         (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_LEMONBAR)
+        (void)snprintf(colorbuf, sizeof(colorbuf), "%%{F%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
@@ -61,6 +64,8 @@ void print_separator(const char *separator) {
         printf("^fg(%s)%s^fg()", cfg_getstr(cfg_general, "color_separator"), separator);
     else if (output_format == O_XMOBAR)
         printf("<fc=%s>%s</fc>", cfg_getstr(cfg_general, "color_separator"), separator);
+    else if (output_format == O_LEMONBAR)
+        printf("%%{F%s}%s%%{F-}", cfg_getstr(cfg_general, "color_separator"), separator);
     else if (output_format == O_TERM)
         printf("%s%s%s", color("color_separator"), separator, endcolor());
     else if (output_format == O_NONE)
@@ -73,3 +78,46 @@ void print_separator(const char *separator) {
 void reset_cursor(void) {
     printf("\033[?25h");
 }
+
+/*
+ * Escapes ampersand, less-than, greater-than, single-quote, and double-quote
+ * characters with the corresponding Pango markup strings if markup is enabled.
+ * See the glib implementation:
+ * https://git.gnome.org/browse/glib/tree/glib/gmarkup.c?id=03db1f455b4265654e237d2ad55464b4113cba8a#n2142
+ *
+ */
+void maybe_escape_markup(char *text, char **buffer) {
+    if (markup_format == M_NONE) {
+        *buffer += sprintf(*buffer, "%s", text);
+        return;
+    }
+    for (; *text != '\0'; text++) {
+        switch (*text) {
+            case '&':
+                *buffer += sprintf(*buffer, "%s", "&amp;");
+                break;
+            case '<':
+                *buffer += sprintf(*buffer, "%s", "&lt;");
+                break;
+            case '>':
+                *buffer += sprintf(*buffer, "%s", "&gt;");
+                break;
+            case '\'':
+                *buffer += sprintf(*buffer, "%s", "&apos;");
+                break;
+            case '"':
+                *buffer += sprintf(*buffer, "%s", "&quot;");
+                break;
+            default:
+                if ((0x1 <= *text && *text <= 0x8) ||
+                    (0xb <= *text && *text <= 0xc) ||
+                    (0xe <= *text && *text <= 0x1f) ||
+                    (0x7f <= *text && *text <= 0x84) ||
+                    (0x86 <= *text && *text <= 0x9f))
+                    *buffer += sprintf(*buffer, "&#x%x;", *text);
+                else
+                    *(*buffer)++ = *text;
+                break;
+        }
+    }
+}