*
*/
static int valid_color(const char *value) {
- if (strlen(value) != 7)
- return 0;
+ const int len = strlen(value);
+
+ if (output_format == O_LEMONBAR) {
+ /* lemonbar supports an optional alpha channel */
+ if (len != strlen("#rrggbb") && len != strlen("#aarrggbb")) {
+ return 0;
+ }
+ } else {
+ if (len != strlen("#rrggbb")) {
+ return 0;
+ }
+ }
if (value[0] != '#')
return 0;
- for (int i = 1; i < 7; ++i) {
+ for (int i = 1; i < len; ++i) {
if (value[i] >= '0' && value[i] <= '9')
continue;
if (value[i] >= 'a' && value[i] <= 'f')
output_format = O_XMOBAR;
else if (strcasecmp(output_str, "i3bar") == 0)
output_format = O_I3BAR;
+ else if (strcasecmp(output_str, "lemonbar") == 0)
+ output_format = O_LEMONBAR;
else if (strcasecmp(output_str, "term") == 0)
output_format = O_TERM;
else if (strcasecmp(output_str, "none") == 0)
const char *separator = cfg_getstr(cfg_general, "separator");
+ /* lemonbar needs % to be escaped with another % */
+ pct_mark = (output_format == O_LEMONBAR) ? "%%" : "%";
+
// if no custom separator has been provided, use the default one
if (strcasecmp(separator, "default") == 0)
separator = get_default_separator();
enum { O_DZEN2,
O_XMOBAR,
O_I3BAR,
+ O_LEMONBAR,
O_TERM,
O_NONE } output_format;
+char *pct_mark;
+
#include <stdbool.h>
#include <confuse.h>
#include <time.h>
== NAME
-i3status - Generates a status line for i3bar, dzen2 or xmobar
+i3status - Generates a status line for i3bar, dzen2, xmobar or lemonbar
== SYNOPSIS
== DESCRIPTION
i3status is a small program (about 1500 SLOC) for generating a status bar for
-i3bar, dzen2, xmobar or similar programs. It is designed to be very
+i3bar, dzen2, xmobar, lemonbar or similar programs. It is designed to be very
efficient by issuing a very small number of system calls, as one generally
wants to update such a status line every second. This ensures that even under
high load, your status bar is updated correctly. Also, it saves a bit of energy
xmobar::
xmobar is a minimalistic, text based, status bar. It was designed to work
with the xmonad Window Manager.
+lemonbar::
+lemonbar is a lightweight bar based entirely on XCB. It has full UTF-8 support
+and is EWMH compliant.
term::
Use ANSI Escape sequences to produce a terminal-output as close as possible to
the graphical outputs. This makes debugging your config file a little bit
#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) {
(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
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)
percentage_remaining = 100;
}
if (integer_battery_capacity) {
- (void)snprintf(percentagebuf, sizeof(percentagebuf), "%.00f%%", percentage_remaining);
+ (void)snprintf(percentagebuf, sizeof(percentagebuf), "%.00f%s", percentage_remaining, pct_mark);
} else {
- (void)snprintf(percentagebuf, sizeof(percentagebuf), "%.02f%%", percentage_remaining);
+ (void)snprintf(percentagebuf, sizeof(percentagebuf), "%.02f%s", percentage_remaining, pct_mark);
}
if (present_rate > 0) {
(void)snprintf(statusbuf, sizeof(statusbuf), "%s", BATT_STATUS_NAME(status));
- (void)snprintf(percentagebuf, sizeof(percentagebuf), "%02d%%",
- present_rate);
+ (void)snprintf(percentagebuf, sizeof(percentagebuf), "%02d%s",
+ present_rate, pct_mark);
if (state == 1) {
int hours, minutes;
(void)snprintf(statusbuf, sizeof(statusbuf), "%s", BATT_STATUS_NAME(status));
/* integer_battery_capacity is implied as battery_life is already in whole numbers. */
- (void)snprintf(percentagebuf, sizeof(percentagebuf), "%.00d%%", apm_info.battery_life);
+ (void)snprintf(percentagebuf, sizeof(percentagebuf), "%.00d%s", apm_info.battery_life, pct_mark);
if (status == CS_DISCHARGING && low_threshold > 0) {
if (strcasecmp(threshold_type, "percentage") == 0 && apm_info.battery_life < low_threshold) {
if (integer_battery_capacity)
(void)snprintf(percentagebuf,
sizeof(percentagebuf),
- "%d%%",
- (int)percentage_remaining);
+ "%d%s",
+ (int)percentage_remaining, pct_mark);
else
(void)snprintf(percentagebuf,
sizeof(percentagebuf),
- "%.02f%%",
- percentage_remaining);
+ "%.02f%s",
+ percentage_remaining, pct_mark);
/*
* Handle percentage low_threshold here, and time low_threshold when
}
if (BEGINS_WITH(walk + 1, "usage")) {
- outwalk += sprintf(outwalk, "%02d%%", diff_usage);
+ outwalk += sprintf(outwalk, "%02d%s", diff_usage, pct_mark);
walk += strlen("usage");
}
}
}
if (BEGINS_WITH(walk + 1, "percentage_free")) {
- outwalk += sprintf(outwalk, "%.01f%%", 100.0 * (double)buf.f_bfree / (double)buf.f_blocks);
+ outwalk += sprintf(outwalk, "%.01f%s", 100.0 * (double)buf.f_bfree / (double)buf.f_blocks, pct_mark);
walk += strlen("percentage_free");
}
if (BEGINS_WITH(walk + 1, "percentage_used_of_avail")) {
- outwalk += sprintf(outwalk, "%.01f%%", 100.0 * (double)(buf.f_blocks - buf.f_bavail) / (double)buf.f_blocks);
+ outwalk += sprintf(outwalk, "%.01f%s", 100.0 * (double)(buf.f_blocks - buf.f_bavail) / (double)buf.f_blocks, pct_mark);
walk += strlen("percentage_used_of_avail");
}
if (BEGINS_WITH(walk + 1, "percentage_used")) {
- outwalk += sprintf(outwalk, "%.01f%%", 100.0 * (double)(buf.f_blocks - buf.f_bfree) / (double)buf.f_blocks);
+ outwalk += sprintf(outwalk, "%.01f%s", 100.0 * (double)(buf.f_blocks - buf.f_bfree) / (double)buf.f_blocks, pct_mark);
walk += strlen("percentage_used");
}
if (BEGINS_WITH(walk + 1, "percentage_avail")) {
- outwalk += sprintf(outwalk, "%.01f%%", 100.0 * (double)buf.f_bavail / (double)buf.f_blocks);
+ outwalk += sprintf(outwalk, "%.01f%s", 100.0 * (double)buf.f_bavail / (double)buf.f_blocks, pct_mark);
walk += strlen("percentage_avail");
}
}
continue;
}
if (BEGINS_WITH(walk + 1, "%")) {
- outwalk += sprintf(outwalk, "%%");
+ outwalk += sprintf(outwalk, "%s", pct_mark);
walk += strlen("%");
}
if (BEGINS_WITH(walk + 1, "volume")) {
- outwalk += sprintf(outwalk, "%d%%", ivolume);
+ outwalk += sprintf(outwalk, "%d%s", ivolume, pct_mark);
walk += strlen("volume");
}
}
if (BEGINS_WITH(walk + 1, "quality")) {
if (info.flags & WIRELESS_INFO_FLAG_HAS_QUALITY) {
if (info.quality_max)
- outwalk += sprintf(outwalk, "%03d%%", PERCENT_VALUE(info.quality, info.quality_max));
+ outwalk += sprintf(outwalk, "%03d%s", PERCENT_VALUE(info.quality, info.quality_max), pct_mark);
else
outwalk += sprintf(outwalk, "%d", info.quality);
} else {
if (BEGINS_WITH(walk + 1, "signal")) {
if (info.flags & WIRELESS_INFO_FLAG_HAS_SIGNAL) {
if (info.signal_level_max)
- outwalk += sprintf(outwalk, "%03d%%", PERCENT_VALUE(info.signal_level, info.signal_level_max));
+ outwalk += sprintf(outwalk, "%03d%s", PERCENT_VALUE(info.signal_level, info.signal_level_max), pct_mark);
else
outwalk += sprintf(outwalk, "%d dBm", info.signal_level);
} else {
if (BEGINS_WITH(walk + 1, "noise")) {
if (info.flags & WIRELESS_INFO_FLAG_HAS_NOISE) {
if (info.noise_level_max)
- outwalk += sprintf(outwalk, "%03d%%", PERCENT_VALUE(info.noise_level, info.noise_level_max));
+ outwalk += sprintf(outwalk, "%03d%s", PERCENT_VALUE(info.noise_level, info.noise_level_max), pct_mark);
else
outwalk += sprintf(outwalk, "%d dBm", info.noise_level);
} else {