From be176269315a2d751510fb0348784a42f2a0d20a Mon Sep 17 00:00:00 2001 From: c0dev0id Date: Sat, 28 Jan 2023 21:55:28 +0100 Subject: [PATCH] Add color markup --- cbar.c | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/cbar.c b/cbar.c index 0f76f4b..72b7b27 100644 --- a/cbar.c +++ b/cbar.c @@ -3,7 +3,6 @@ #include #include #include - #include #include @@ -11,18 +10,15 @@ #include #include #include - #include - #include - -static char battery_percent[24]; -static char cpu_temp[24]; -static char fan_speed[24]; -static char cpu_base_speed[24]; -static char cpu_avg_speed[24]; -static char volume[24]; +static char battery_percent[32]; +static char cpu_temp[32]; +static char fan_speed[32]; +static char cpu_base_speed[32]; +static char cpu_avg_speed[32]; +static char volume[32]; void update_volume() { /* TODO: This should use sndiod and not the raw device */ @@ -48,7 +44,7 @@ void update_volume() { } if (output_master == -1) { fprintf(stderr, "Mixer control not found\n"); - snprintf(volume,sizeof(volume), "%lc N/A (mixerctl", ico_vol); + snprintf(volume,sizeof(volume), "%lc N/A", ico_vol); close(fd); return; } @@ -58,7 +54,7 @@ void update_volume() { ctl.dev = output_master; ctl.type = AUDIO_MIXER_VALUE; if (ioctl(fd, AUDIO_MIXER_READ, &ctl) == -1) { - snprintf(volume,sizeof(volume), "%lc N/A (value)", ico_vol); + snprintf(volume,sizeof(volume), "%lc N/A", ico_vol); close(fd); return; } @@ -124,7 +120,10 @@ void update_fan_speed() { if (sysctl(mib, 5, &sensor, &templen, NULL, 0) != -1) temp = sensor.value; - snprintf(fan_speed,sizeof(fan_speed), "%lc %dRPM", ico_fan, temp); + if(temp>4200) + snprintf(fan_speed,sizeof(fan_speed), "+@fg=1;%lc %dRPM+@fg=0;", ico_fan, temp); + else + snprintf(fan_speed,sizeof(fan_speed), "%lc %dRPM", ico_fan, temp); } void update_cpu_temp() { @@ -164,8 +163,11 @@ void update_cpu_temp() { ico_temp = ico_25; else ico_temp = ico_low; - snprintf(cpu_temp,sizeof(battery_percent), - "%lc %dC", ico_temp, temp); + + if(temp>70) + snprintf(cpu_temp,sizeof(battery_percent), "+@fg=1;%lc %dC+@fg=0;", ico_temp, temp); + else + snprintf(cpu_temp,sizeof(battery_percent), "%lc %dC", ico_temp, temp); } void update_battery() { @@ -231,7 +233,11 @@ void update_battery() { else ico_buf = ico_empty; - snprintf(battery_percent,sizeof(battery_percent), + if(pi.battery_life<10) + snprintf(battery_percent,sizeof(battery_percent), + "+@fg=1;%lc%lc %d%%+@fg=0;", ico_chr_buf, ico_buf, pi.battery_life); + else + snprintf(battery_percent,sizeof(battery_percent), "%lc%lc %d%%", ico_chr_buf, ico_buf, pi.battery_life); }