commit - b9842c1e781fb0d4ccf07a8f9175c6c5e5e48c41
commit + 9edd225effe94b501a9283dba6bee3ed13d76663
blob - c1b40fd80f691ef4993d87e1fc71b3839045cfee
blob + a05a6860127d22842463716c8f8b1afbce6806e8
--- bedstatus/bedstatus.c
+++ bedstatus/bedstatus.c
#define SYM_BAT_FULL "\uf240 "
#define SYM_TMR "\uf253 "
+#define COLOR_NORMAL "\x01"
+#define COLOR_WARN "\x03"
+#define COLOR_URGENT "\x04"
+
static size_t pos;
static char buf[256];
static char *timerpath;
static int timer_ttl = 0;
+static const char *blink;
static void sig_reset (int sig)
{
static void format_bat (const struct status *st)
{
+ const char *reset = "";
+
if (!st->has_bat_charging && !st->has_bat_perc && !st->has_bat_rem && !st->has_power)
return;
+
+ if (st->has_bat_perc && (!st->has_bat_charging || !st->bat_charging)) {
+ reset = COLOR_NORMAL;
+ if (st->bat_perc < 10) {
+ append (blink);
+ } else if (st->bat_perc < 20) {
+ append (COLOR_URGENT);
+ } else if (st->bat_perc < 30) {
+ append (COLOR_WARN);
+ } else {
+ reset = "";
+ }
+ }
append ("[BAT ");
if (st->has_bat_perc && (st->has_bat_rem || st->has_power))
append (")");
- append ("] ");
+ append ("]%s ", reset);
}
static time_t fetch_timer (void)
static void format_timer (void)
{
time_t now, diff, timer = fetch_timer ();
+ const char *reset = COLOR_NORMAL;
if (timer == 0)
return;
now = time (NULL);
diff = timer - now;
+
+ if (diff < 30) {
+ append (blink);
+ } else if (diff < 60) {
+ append (COLOR_URGENT);
+ } else if (diff < 120) {
+ append (COLOR_WARN);
+ } else {
+ reset = "";
+ }
+
append ("[TMR " SYM_TMR);
if (diff >= 0) {
append ("%s", elapsed);
}
- append ("] ");
+ append ("]%s ", reset);
}
static void format_time (void)
while (1) {
struct status st;
+ blink = (time (NULL) & 1) ? COLOR_WARN : COLOR_URGENT;
+
update_status (&st);
pos = 0;
format_status (&st);