1 // vim:ts=4:sw=4:expandtab
14 * Returns the correct color format for dzen (^fg(color)), xmobar (<fc=color>)
15 * or lemonbar (%{Fcolor})
18 char *color(const char *colorstr) {
19 static char colorbuf[32];
20 if (!cfg_getbool(cfg_general, "colors")) {
24 if (output_format == O_DZEN2)
25 (void)snprintf(colorbuf, sizeof(colorbuf), "^fg(%s)", cfg_getstr(cfg_general, colorstr));
26 else if (output_format == O_XMOBAR)
27 (void)snprintf(colorbuf, sizeof(colorbuf), "<fc=%s>", cfg_getstr(cfg_general, colorstr));
28 else if (output_format == O_LEMONBAR)
29 (void)snprintf(colorbuf, sizeof(colorbuf), "%%{F%s}", cfg_getstr(cfg_general, colorstr));
30 else if (output_format == O_TERM) {
31 /* The escape-sequence for color is <CSI><col>;1m (bright/bold
32 * output), where col is a 3-bit rgb-value with b in the
33 * least-significant bit. We round the given color to the
34 * nearist 3-bit-depth color and output the escape-sequence */
35 char *str = cfg_getstr(cfg_general, colorstr);
36 int col = strtol(str + 1, NULL, 16);
37 int r = (col & (0xFF << 0)) / 0x80;
38 int g = (col & (0xFF << 8)) / 0x8000;
39 int b = (col & (0xFF << 16)) / 0x800000;
40 col = (r << 2) | (g << 1) | b;
41 (void)snprintf(colorbuf, sizeof(colorbuf), "\033[3%d;1m", col);
47 * Some color formats (xmobar) require to terminate colors again
50 char *endcolor(void) {
51 if (output_format == O_XMOBAR)
53 else if (output_format == O_TERM)
59 void print_separator(const char *separator) {
60 if (output_format == O_I3BAR || strlen(separator) == 0)
63 if (output_format == O_DZEN2)
64 printf("^fg(%s)%s^fg()", cfg_getstr(cfg_general, "color_separator"), separator);
65 else if (output_format == O_XMOBAR)
66 printf("<fc=%s>%s</fc>", cfg_getstr(cfg_general, "color_separator"), separator);
67 else if (output_format == O_LEMONBAR)
68 printf("%%{F%s}%s%%{F-}", cfg_getstr(cfg_general, "color_separator"), separator);
69 else if (output_format == O_TERM)
70 printf("%s%s%s", color("color_separator"), separator, endcolor());
71 else if (output_format == O_NONE)
72 printf("%s", separator);
76 * The term-output hides the cursor. We call this on exit to reset that.
78 void reset_cursor(void) {