From 20beb5ca3e6b149f9883cd8728a4ccde19851581 Mon Sep 17 00:00:00 2001 From: Sravan Balaji Date: Sun, 2 Aug 2020 11:22:39 -0400 Subject: [PATCH] Checkupdates & Divider Functions - Add checkupdates function to count number of available updates - Add divider function to print divider symbol as argument - Update README with these modifications --- Makefile | 2 ++ README.md | 5 ++++- components/check_updates.c | 12 ++++++++++++ components/divider.c | 9 +++++++++ config.h | 32 ++++++++++++++++++++++---------- slstatus.h | 6 ++++++ 6 files changed, 55 insertions(+), 11 deletions(-) create mode 100644 components/check_updates.c create mode 100644 components/divider.c diff --git a/Makefile b/Makefile index 945b5e3..6183bc9 100644 --- a/Makefile +++ b/Makefile @@ -7,9 +7,11 @@ include config.mk REQ = util COM =\ components/battery\ + components/check_updates\ components/cpu\ components/datetime\ components/disk\ + components/divider\ components/entropy\ components/hostname\ components/ip\ diff --git a/README.md b/README.md index d26d301..3d6ef65 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ Cleaning up the whole codebase it the goal before thinking about a release. * Change unknown string to "?" * Customize Status Bar - * User + * Username * CPU Usage * RAM Usage * Disk Usage @@ -73,3 +73,6 @@ Cleaning up the whole codebase it the goal before thinking about a release. * Battery Stats * Date * Time +* Custom Functions + * **check_updates** uses **run_command** to get number of packages that need to be updated + * **divider** prints the *divider_symbol* via a separate function rather than in the format of another function diff --git a/components/check_updates.c b/components/check_updates.c new file mode 100644 index 0000000..c7ba5f7 --- /dev/null +++ b/components/check_updates.c @@ -0,0 +1,12 @@ +/* See LICENSE file for copyright and license details. */ +#include +#include + +#include "../slstatus.h" + +const char * +check_updates(void) +{ + const char *cmd = "checkupdates | wc -l"; + return run_command(cmd); +} diff --git a/components/divider.c b/components/divider.c new file mode 100644 index 0000000..5c516ac --- /dev/null +++ b/components/divider.c @@ -0,0 +1,9 @@ +/* See LICENSE file for copyright and license details. */ +#include +#include + +const char * +divider(const char *div) +{ + return div; +} diff --git a/config.h b/config.h index b699cfe..bbd810a 100644 --- a/config.h +++ b/config.h @@ -10,6 +10,7 @@ static const char unknown_str[] = "?"; #define MAXLEN 2048 static const char battery_name[] = "BAT0"; +static const char divider_symbol[] = "|"; /* * function description argument (example) @@ -20,6 +21,7 @@ static const char battery_name[] = "BAT0"; * NULL on OpenBSD/FreeBSD * battery_remaining battery remaining HH:MM battery name (BAT0) * NULL on OpenBSD/FreeBSD + * check_updates num available updates NULL * cpu_perc cpu usage in percent NULL * cpu_freq cpu frequency in MHz NULL * datetime date and time format string (%F %T) @@ -27,6 +29,7 @@ static const char battery_name[] = "BAT0"; * disk_perc disk usage in percent mountpoint path (/) * disk_total total disk space in GB mountpoint path (/") * disk_used used disk space in GB mountpoint path (/) + * divider insert divider divider symbol * entropy available entropy NULL * gid GID of current user NULL * hostname hostname NULL @@ -64,15 +67,24 @@ static const char battery_name[] = "BAT0"; * wifi_essid WiFi ESSID interface name (wlan0) */ static const struct arg args[] = { - /* function format argument */ - { username, "|  %s ", NULL }, - { cpu_perc, "|  %s%% ", NULL }, - { ram_perc, "|  %s%% ", NULL }, - { disk_perc, "|  %s%% ", "/home" }, - { run_command, "|  %s ", "checkupdates | wc -l" }, - { battery_state, "|  %s", battery_name }, + /* function format argument */ + { divider, "%s", divider_symbol }, + { username, " %s", NULL }, + { divider, "%s", divider_symbol }, + { cpu_perc, " %s%%", NULL }, + { divider, "%s", divider_symbol }, + { ram_perc, " %s%%", NULL }, + { divider, "%s", divider_symbol }, + { disk_perc, " %s%%", "/home" }, + { divider, "%s", divider_symbol }, + { check_updates, " %s", NULL }, + { divider, "%s", divider_symbol }, + { battery_state, " %s", battery_name }, { battery_perc, "%s%%", battery_name }, - { battery_remaining, " (%s) ", battery_name }, - { datetime, "|  %s ", "%a %x" }, - { datetime, "|  %s |", "%I:%M:%S %p" }, + { battery_remaining, " (%s)", battery_name }, + { divider, "%s", divider_symbol }, + { datetime, " %s", "%a %x" }, + { divider, "%s", divider_symbol }, + { datetime, " %s", "%I:%M:%S %p" }, + { divider, "%s", divider_symbol }, }; diff --git a/slstatus.h b/slstatus.h index 08f610a..b806e30 100644 --- a/slstatus.h +++ b/slstatus.h @@ -5,6 +5,9 @@ const char *battery_perc(const char *); const char *battery_state(const char *); const char *battery_remaining(const char *); +/* check updates */ +const char *check_updates(void); + /* cpu */ const char *cpu_freq(void); const char *cpu_perc(void); @@ -18,6 +21,9 @@ const char *disk_perc(const char *path); const char *disk_total(const char *path); const char *disk_used(const char *path); +/* divider */ +const char *divider(const char *div); + /* entropy */ const char *entropy(void);