]> git.sur5r.net Git - i3/i3status/commitdiff
able to print percentage 297/head
authorFelix Buehler <account@buehler.rocks>
Sat, 2 Jun 2018 00:32:25 +0000 (02:32 +0200)
committerFelix Buehler <account@buehler.rocks>
Fri, 13 Jul 2018 13:03:31 +0000 (15:03 +0200)
its now possible to have percentage before and after a variable. except
for the date. But percentage with dates does not make much sense to me, so
i skipped it.

13 files changed:
src/print_battery_info.c
src/print_cpu_temperature.c
src/print_cpu_usage.c
src/print_disk_info.c
src/print_eth_info.c
src/print_ipv6_addr.c
src/print_load.c
src/print_mem.c
src/print_path_exists.c
src/print_run_watch.c
src/print_time.c
src/print_volume.c
src/print_wireless_info.c

index db4d7bd33f9ae74611b273504ce90a6e9afbe348..8c85192f20f916b6544921e2740b0e0ce0424f58 100644 (file)
@@ -622,10 +622,8 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char
 
         if (*walk != '%') {
             *(outwalk++) = *walk;
-            continue;
-        }
 
-        if (BEGINS_WITH(walk + 1, "status")) {
+        } else if (BEGINS_WITH(walk + 1, "status")) {
             const char *statusstr;
             switch (batt_info.status) {
                 case CS_CHARGING:
@@ -643,6 +641,7 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char
 
             outwalk += sprintf(outwalk, "%s", statusstr);
             walk += strlen("status");
+
         } else if (BEGINS_WITH(walk + 1, "percentage")) {
             if (integer_battery_capacity) {
                 outwalk += sprintf(outwalk, "%.00f%s", batt_info.percentage_remaining, pct_mark);
@@ -650,6 +649,7 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char
                 outwalk += sprintf(outwalk, "%.02f%s", batt_info.percentage_remaining, pct_mark);
             }
             walk += strlen("percentage");
+
         } else if (BEGINS_WITH(walk + 1, "remaining")) {
             if (batt_info.seconds_remaining >= 0) {
                 int seconds, hours, minutes;
@@ -668,6 +668,7 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char
             }
             walk += strlen("remaining");
             EAT_SPACE_FROM_OUTPUT_IF_NO_OUTPUT();
+
         } else if (BEGINS_WITH(walk + 1, "emptytime")) {
             if (batt_info.seconds_remaining >= 0) {
                 time_t empty_time = time(NULL) + batt_info.seconds_remaining;
@@ -683,12 +684,16 @@ void print_battery_info(yajl_gen json_gen, char *buffer, int number, const char
             }
             walk += strlen("emptytime");
             EAT_SPACE_FROM_OUTPUT_IF_NO_OUTPUT();
+
         } else if (BEGINS_WITH(walk + 1, "consumption")) {
             if (batt_info.present_rate >= 0)
                 outwalk += sprintf(outwalk, "%1.2fW", batt_info.present_rate / 1e6);
 
             walk += strlen("consumption");
             EAT_SPACE_FROM_OUTPUT_IF_NO_OUTPUT();
+
+        } else {
+            *(outwalk++) = '%';
         }
     }
 
index feae3ec8a8cb388fc3e8717554d4f851303d65ef..569ea6064e4aa234a2e157f68037610ffd01517a 100644 (file)
@@ -250,11 +250,13 @@ void print_cpu_temperature_info(yajl_gen json_gen, char *buffer, int zone, const
     for (walk = selected_format; *walk != '\0'; walk++) {
         if (*walk != '%') {
             *(outwalk++) = *walk;
-            continue;
-        }
-        if (BEGINS_WITH(walk + 1, "degrees")) {
+
+        } else if (BEGINS_WITH(walk + 1, "degrees")) {
             outwalk += sprintf(outwalk, "%s", temperature.formatted_value);
             walk += strlen("degrees");
+
+        } else {
+            *(outwalk++) = '%';
         }
     }
 
index c1ea3fd4b1576cfa0c5a0d69014f7d25dfc0d971..615fe5dc276140a196070972d91ed98b16b47a78 100644 (file)
@@ -144,15 +144,13 @@ void print_cpu_usage(yajl_gen json_gen, char *buffer, const char *format, const
     for (walk = selected_format; *walk != '\0'; walk++) {
         if (*walk != '%') {
             *(outwalk++) = *walk;
-            continue;
-        }
 
-        if (BEGINS_WITH(walk + 1, "usage")) {
+        } else if (BEGINS_WITH(walk + 1, "usage")) {
             outwalk += sprintf(outwalk, "%02d%s", diff_usage, pct_mark);
             walk += strlen("usage");
         }
 #if defined(LINUX)
-        if (BEGINS_WITH(walk + 1, "cpu")) {
+        else if (BEGINS_WITH(walk + 1, "cpu")) {
             int number = 0;
             sscanf(walk + 1, "cpu%d", &number);
             if (number < 0 || number >= cpu_count) {
@@ -172,6 +170,9 @@ void print_cpu_usage(yajl_gen json_gen, char *buffer, const char *format, const
             walk += strlen("cpu") + padding;
         }
 #endif
+        else {
+            *(outwalk++) = '%';
+        }
     }
 
     for (int i = 0; i < cpu_count; i++)
index 770e7186840959198efd89b114e7fc809b3bd2cf..bc43da0348bd5081946e712190bd459760a44715 100644 (file)
@@ -172,47 +172,41 @@ void print_disk_info(yajl_gen json_gen, char *buffer, const char *path, const ch
     for (walk = selected_format; *walk != '\0'; walk++) {
         if (*walk != '%') {
             *(outwalk++) = *walk;
-            continue;
-        }
 
-        if (BEGINS_WITH(walk + 1, "free")) {
+        } else if (BEGINS_WITH(walk + 1, "free")) {
             outwalk += print_bytes_human(outwalk, (uint64_t)buf.f_bsize * (uint64_t)buf.f_bfree, prefix_type);
             walk += strlen("free");
-        }
 
-        if (BEGINS_WITH(walk + 1, "used")) {
+        } else if (BEGINS_WITH(walk + 1, "used")) {
             outwalk += print_bytes_human(outwalk, (uint64_t)buf.f_bsize * ((uint64_t)buf.f_blocks - (uint64_t)buf.f_bfree), prefix_type);
             walk += strlen("used");
-        }
 
-        if (BEGINS_WITH(walk + 1, "total")) {
+        } else if (BEGINS_WITH(walk + 1, "total")) {
             outwalk += print_bytes_human(outwalk, (uint64_t)buf.f_bsize * (uint64_t)buf.f_blocks, prefix_type);
             walk += strlen("total");
-        }
 
-        if (BEGINS_WITH(walk + 1, "avail")) {
+        } else if (BEGINS_WITH(walk + 1, "avail")) {
             outwalk += print_bytes_human(outwalk, (uint64_t)buf.f_bsize * (uint64_t)buf.f_bavail, prefix_type);
             walk += strlen("avail");
-        }
 
-        if (BEGINS_WITH(walk + 1, "percentage_free")) {
+        } else if (BEGINS_WITH(walk + 1, "percentage_free")) {
             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")) {
+        } else if (BEGINS_WITH(walk + 1, "percentage_used_of_avail")) {
             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")) {
+        } else if (BEGINS_WITH(walk + 1, "percentage_used")) {
             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")) {
+        } else if (BEGINS_WITH(walk + 1, "percentage_avail")) {
             outwalk += sprintf(outwalk, "%.01f%s", 100.0 * (double)buf.f_bavail / (double)buf.f_blocks, pct_mark);
             walk += strlen("percentage_avail");
+
+        } else {
+            *(outwalk++) = '%';
         }
     }
 
index 996ce3b6606eea86e6d89de5a6fd005182ae32b3..2fc25a180b30f5134b23064049335054fd0ed9e5 100644 (file)
@@ -175,15 +175,17 @@ void print_eth_info(yajl_gen json_gen, char *buffer, const char *interface, cons
     for (walk = format_up; *walk != '\0'; walk++) {
         if (*walk != '%') {
             *(outwalk++) = *walk;
-            continue;
-        }
 
-        if (BEGINS_WITH(walk + 1, "ip")) {
+        } else if (BEGINS_WITH(walk + 1, "ip")) {
             outwalk += sprintf(outwalk, "%s", ip_address);
             walk += strlen("ip");
+
         } else if (BEGINS_WITH(walk + 1, "speed")) {
             outwalk += print_eth_speed(outwalk, interface);
             walk += strlen("speed");
+
+        } else {
+            *(outwalk++) = '%';
         }
     }
 
index a24119f74797a5414653745043a73c49114595fd..a50bf398e8ef1e5080abb3bae299b0cc92928d2e 100644 (file)
@@ -133,12 +133,13 @@ void print_ipv6_info(yajl_gen json_gen, char *buffer, const char *format_up, con
     for (walk = format_up; *walk != '\0'; walk++) {
         if (*walk != '%') {
             *(outwalk++) = *walk;
-            continue;
-        }
 
-        if (BEGINS_WITH(walk + 1, "ip")) {
+        } else if (BEGINS_WITH(walk + 1, "ip")) {
             outwalk += sprintf(outwalk, "%s", addr_string);
             walk += strlen("ip");
+
+        } else {
+            *(outwalk++) = '%';
         }
     }
     END_COLOR;
index 6da2519c3d58496e58ecfac1491b767dd7fd17d3..e0ba6771f710b1bbaa1d8d2694b7c7318be6b4a9 100644 (file)
@@ -29,21 +29,21 @@ void print_load(yajl_gen json_gen, char *buffer, const char *format, const char
     for (walk = selected_format; *walk != '\0'; walk++) {
         if (*walk != '%') {
             *(outwalk++) = *walk;
-            continue;
-        }
-        if (BEGINS_WITH(walk + 1, "1min")) {
+
+        } else if (BEGINS_WITH(walk + 1, "1min")) {
             outwalk += sprintf(outwalk, "%1.2f", loadavg[0]);
             walk += strlen("1min");
-        }
 
-        if (BEGINS_WITH(walk + 1, "5min")) {
+        } else if (BEGINS_WITH(walk + 1, "5min")) {
             outwalk += sprintf(outwalk, "%1.2f", loadavg[1]);
             walk += strlen("5min");
-        }
 
-        if (BEGINS_WITH(walk + 1, "15min")) {
+        } else if (BEGINS_WITH(walk + 1, "15min")) {
             outwalk += sprintf(outwalk, "%1.2f", loadavg[2]);
             walk += strlen("15min");
+
+        } else {
+            *(outwalk++) = '%';
         }
     }
 
index a37fa2905c142fd9c65925b0cd83ca86e5faded8..f9284f35c6c92fa6724f91d653136dc99fe94fc5 100644 (file)
@@ -159,51 +159,45 @@ void print_memory(yajl_gen json_gen, char *buffer, const char *format, const cha
     for (walk = selected_format; *walk != '\0'; walk++) {
         if (*walk != '%') {
             *(outwalk++) = *walk;
-            continue;
-        }
-        if (BEGINS_WITH(walk + 1, "total")) {
+
+        } else if (BEGINS_WITH(walk + 1, "total")) {
             outwalk += print_bytes_human(outwalk, ram_total);
             walk += strlen("total");
-        }
 
-        if (BEGINS_WITH(walk + 1, "used")) {
+        } else if (BEGINS_WITH(walk + 1, "used")) {
             outwalk += print_bytes_human(outwalk, ram_used);
             walk += strlen("used");
-        }
 
-        if (BEGINS_WITH(walk + 1, "free")) {
+        } else if (BEGINS_WITH(walk + 1, "free")) {
             outwalk += print_bytes_human(outwalk, ram_free);
             walk += strlen("free");
-        }
 
-        if (BEGINS_WITH(walk + 1, "available")) {
+        } else if (BEGINS_WITH(walk + 1, "available")) {
             outwalk += print_bytes_human(outwalk, ram_available);
             walk += strlen("available");
-        }
 
-        if (BEGINS_WITH(walk + 1, "shared")) {
+        } else if (BEGINS_WITH(walk + 1, "shared")) {
             outwalk += print_bytes_human(outwalk, ram_shared);
             walk += strlen("shared");
-        }
 
-        if (BEGINS_WITH(walk + 1, "percentage_free")) {
+        } else if (BEGINS_WITH(walk + 1, "percentage_free")) {
             outwalk += sprintf(outwalk, "%.01f%s", 100.0 * ram_free / ram_total, pct_mark);
             walk += strlen("percentage_free");
-        }
 
-        if (BEGINS_WITH(walk + 1, "percentage_available")) {
+        } else if (BEGINS_WITH(walk + 1, "percentage_available")) {
             outwalk += sprintf(outwalk, "%.01f%s", 100.0 * ram_available / ram_total, pct_mark);
             walk += strlen("percentage_available");
-        }
 
-        if (BEGINS_WITH(walk + 1, "percentage_used")) {
+        } else if (BEGINS_WITH(walk + 1, "percentage_used")) {
             outwalk += sprintf(outwalk, "%.01f%s", 100.0 * ram_used / ram_total, pct_mark);
             walk += strlen("percentage_used");
-        }
 
-        if (BEGINS_WITH(walk + 1, "percentage_shared")) {
+        } else if (BEGINS_WITH(walk + 1, "percentage_shared")) {
             outwalk += sprintf(outwalk, "%.01f%s", 100.0 * ram_shared / ram_total, pct_mark);
             walk += strlen("percentage_shared");
+
+        } else {
+            *(outwalk++) = '%';
         }
     }
 
index 65bc9c85028a35aa7283f9bea31afd90c0b98d85..7bdbe30cf4b392421baa6c92a36764d8e231037f 100644 (file)
@@ -25,15 +25,17 @@ void print_path_exists(yajl_gen json_gen, char *buffer, const char *title, const
     for (; *walk != '\0'; walk++) {
         if (*walk != '%') {
             *(outwalk++) = *walk;
-            continue;
-        }
 
-        if (BEGINS_WITH(walk + 1, "title")) {
+        } else if (BEGINS_WITH(walk + 1, "title")) {
             outwalk += sprintf(outwalk, "%s", title);
             walk += strlen("title");
+
         } else if (BEGINS_WITH(walk + 1, "status")) {
             outwalk += sprintf(outwalk, "%s", (exists ? "yes" : "no"));
             walk += strlen("status");
+
+        } else {
+            *(outwalk++) = '%';
         }
     }
 
index b108f8fef85b728ac2d388b6055744c6c13bd400..0887521f5b71c8cd5da0b78168595b72f1755ae3 100644 (file)
@@ -23,15 +23,17 @@ void print_run_watch(yajl_gen json_gen, char *buffer, const char *title, const c
     for (; *walk != '\0'; walk++) {
         if (*walk != '%') {
             *(outwalk++) = *walk;
-            continue;
-        }
 
-        if (BEGINS_WITH(walk + 1, "title")) {
+        } else if (BEGINS_WITH(walk + 1, "title")) {
             outwalk += sprintf(outwalk, "%s", title);
             walk += strlen("title");
+
         } else if (BEGINS_WITH(walk + 1, "status")) {
             outwalk += sprintf(outwalk, "%s", (running ? "yes" : "no"));
             walk += strlen("status");
+
+        } else {
+            *(outwalk++) = '%';
         }
     }
 
index 3ed32b0157ca15810e830c6af38ead375ae73d63..3a6c4cc0752757aa77170500baf4b9e6e1aa2b37 100644 (file)
@@ -57,13 +57,14 @@ void print_time(yajl_gen json_gen, char *buffer, const char *title, const char *
         for (walk = format; *walk != '\0'; walk++) {
             if (*walk != '%') {
                 *(outwalk++) = *walk;
-                continue;
-            }
 
-            if (BEGINS_WITH(walk + 1, "time")) {
+            } else if (BEGINS_WITH(walk + 1, "time")) {
                 strftime(timebuf, sizeof(timebuf), format_time, &tm);
                 maybe_escape_markup(timebuf, &outwalk);
                 walk += strlen("time");
+
+            } else {
+                *(outwalk++) = '%';
             }
         }
     }
index e28a132fdb3ba5ad76710f6c4c342315c19aa4ae..c5cf55b6420b7c477122ee0abcf5939779c7b151 100644 (file)
@@ -35,15 +35,17 @@ static char *apply_volume_format(const char *fmt, char *outwalk, int ivolume) {
     for (; *walk != '\0'; walk++) {
         if (*walk != '%') {
             *(outwalk++) = *walk;
-            continue;
-        }
-        if (BEGINS_WITH(walk + 1, "%")) {
+
+        } else if (BEGINS_WITH(walk + 1, "%")) {
             outwalk += sprintf(outwalk, "%s", pct_mark);
             walk += strlen("%");
-        }
-        if (BEGINS_WITH(walk + 1, "volume")) {
+
+        } else if (BEGINS_WITH(walk + 1, "volume")) {
             outwalk += sprintf(outwalk, "%d%s", ivolume, pct_mark);
             walk += strlen("volume");
+
+        } else {
+            *(outwalk++) = '%';
         }
     }
     return outwalk;
index dcfde528a0a846cc04a63235775f4724a5e0b2ed..d495b47eeb76dfa49fe347d841cabbf7bab3fb63 100644 (file)
@@ -534,10 +534,8 @@ void print_wireless_info(yajl_gen json_gen, char *buffer, const char *interface,
     for (; *walk != '\0'; walk++) {
         if (*walk != '%') {
             *(outwalk++) = *walk;
-            continue;
-        }
 
-        if (BEGINS_WITH(walk + 1, "quality")) {
+        } else if (BEGINS_WITH(walk + 1, "quality")) {
             if (info.flags & WIRELESS_INFO_FLAG_HAS_QUALITY) {
                 if (info.quality_max)
                     outwalk += sprintf(outwalk, format_quality, PERCENT_VALUE(info.quality, info.quality_max), pct_mark);
@@ -547,9 +545,8 @@ void print_wireless_info(yajl_gen json_gen, char *buffer, const char *interface,
                 *(outwalk++) = '?';
             }
             walk += strlen("quality");
-        }
 
-        if (BEGINS_WITH(walk + 1, "signal")) {
+        } else if (BEGINS_WITH(walk + 1, "signal")) {
             if (info.flags & WIRELESS_INFO_FLAG_HAS_SIGNAL) {
                 if (info.signal_level_max)
                     outwalk += sprintf(outwalk, "%3d%s", PERCENT_VALUE(info.signal_level, info.signal_level_max), pct_mark);
@@ -559,9 +556,8 @@ void print_wireless_info(yajl_gen json_gen, char *buffer, const char *interface,
                 *(outwalk++) = '?';
             }
             walk += strlen("signal");
-        }
 
-        if (BEGINS_WITH(walk + 1, "noise")) {
+        } else if (BEGINS_WITH(walk + 1, "noise")) {
             if (info.flags & WIRELESS_INFO_FLAG_HAS_NOISE) {
                 if (info.noise_level_max)
                     outwalk += sprintf(outwalk, "%3d%s", PERCENT_VALUE(info.noise_level, info.noise_level_max), pct_mark);
@@ -571,9 +567,8 @@ void print_wireless_info(yajl_gen json_gen, char *buffer, const char *interface,
                 *(outwalk++) = '?';
             }
             walk += strlen("noise");
-        }
 
-        if (BEGINS_WITH(walk + 1, "essid")) {
+        } else if (BEGINS_WITH(walk + 1, "essid")) {
 #ifdef IW_ESSID_MAX_SIZE
             if (info.flags & WIRELESS_INFO_FLAG_HAS_ESSID)
                 maybe_escape_markup(info.essid, &outwalk);
@@ -581,23 +576,20 @@ void print_wireless_info(yajl_gen json_gen, char *buffer, const char *interface,
 #endif
                 *(outwalk++) = '?';
             walk += strlen("essid");
-        }
 
-        if (BEGINS_WITH(walk + 1, "frequency")) {
+        } else if (BEGINS_WITH(walk + 1, "frequency")) {
             if (info.flags & WIRELESS_INFO_FLAG_HAS_FREQUENCY)
                 outwalk += sprintf(outwalk, "%1.1f GHz", info.frequency / 1e9);
             else
                 *(outwalk++) = '?';
             walk += strlen("frequency");
-        }
 
-        if (BEGINS_WITH(walk + 1, "ip")) {
+        } else if (BEGINS_WITH(walk + 1, "ip")) {
             outwalk += sprintf(outwalk, "%s", ip_address);
             walk += strlen("ip");
         }
-
 #ifdef LINUX
-        if (BEGINS_WITH(walk + 1, "bitrate")) {
+        else if (BEGINS_WITH(walk + 1, "bitrate")) {
             char br_buffer[128];
 
             print_bitrate(br_buffer, sizeof(br_buffer), info.bitrate);
@@ -606,6 +598,9 @@ void print_wireless_info(yajl_gen json_gen, char *buffer, const char *interface,
             walk += strlen("bitrate");
         }
 #endif
+        else {
+            *(outwalk++) = '%';
+        }
     }
 
 out: