[wiki] [sites] [slstatus][patches][limit] use different format for values above set limit || Peter Valach

From: <git_AT_suckless.org>
Date: Tue, 10 Feb 2026 17:46:07 +0100

commit 099ce388993818f600c4e41172f71e20520dce7e
Author: Peter Valach <pvx_AT_gmx.net>
Date: Tue Feb 10 17:45:51 2026 +0100

    [slstatus][patches][limit] use different format for values above set limit
    
    Adds a numeric limit and alternate format string to the configuration.
    When the returned numeric value exceeds this limit, the alternate format
    is used instead of the default one. Useful for visual alerts such as
    high CPU/memory usage or low battery, e.g. by changing colors in status
    bars that support it (such as dwm with color patches).

diff --git a/tools.suckless.org/slstatus/patches/limit/index.md b/tools.suckless.org/slstatus/patches/limit/index.md
new file mode 100644
index 00000000..afabd95d
--- /dev/null
+++ b/tools.suckless.org/slstatus/patches/limit/index.md
_AT_@ -0,0 +1,21 @@
+limit
+=====
+
+Description
+-----------
+This diff makes it possible to highlight values in status bar in a simple
+and fully customizable way.
+
+Adds a numeric limit and alternate format string to the configuration.
+When the returned numeric value exceeds the limit, the alternate format
+is used instead of the default one. Useful for visual alerts such as high
+CPU/memory usage or low battery, e.g. by changing colors in status bars
+that support it (such as dwm with color patches).
+
+Download
+--------
+* [slstatus-limit-20260203-49d8b5a.diff](slstatus-limit-20260203-49d8b5a.diff)
+
+Authors
+-------
+* Peter Valach <pvx_AT_gmx.net>
diff --git a/tools.suckless.org/slstatus/patches/limit/slstatus-limit-20260203-49d8b5a.diff b/tools.suckless.org/slstatus/patches/limit/slstatus-limit-20260203-49d8b5a.diff
new file mode 100644
index 00000000..41a5c330
--- /dev/null
+++ b/tools.suckless.org/slstatus/patches/limit/slstatus-limit-20260203-49d8b5a.diff
_AT_@ -0,0 +1,70 @@
+From 49d8b5ad876401a92efbd604d15abe1f54f79790 Mon Sep 17 00:00:00 2001
+From: Peter Valach <pvx_AT_gmx.net>
+Date: Tue, 3 Feb 2026 19:35:03 +0100
+Subject: [slstatus-limit][PATCH] add second format for values above given limit
+
+---
+ config.def.h | 8 ++++++--
+ slstatus.c | 14 +++++++++++++-
+ 2 files changed, 19 insertions(+), 3 deletions(-)
+
+diff --git a/config.def.h b/config.def.h
+index 100093e..655d713 100644
+--- a/config.def.h
++++ b/config.def.h
+_AT_@ -65,6 +65,10 @@ static const char unknown_str[] = "n/a";
+ * wifi_perc WiFi signal in percent interface name (wlan0)
+ */
+ static const struct arg args[] = {
+- /* function format argument */
+- { datetime, "%s", "%F %T" },
++ /* function format argument limit limit_format */
++ { datetime, "%s", "%F %T", 0, NULL },
++
++ /* example of different format above limit (both format strings can contain anything your status supports, including icons and colors)
++ { ram_perc, "RAM: %s%%", "", 90, "RAM OVER LIMIT: %s%%" },
++ */
+ };
+diff --git a/slstatus.c b/slstatus.c
+index 16d88fe..7e6f670 100644
+--- a/slstatus.c
++++ b/slstatus.c
+_AT_@ -15,6 +15,8 @@ struct arg {
+ const char *(*func)(const char *);
+ const char *fmt;
+ const char *args;
++ long limit;
++ const char *limit_fmt;
+ };
+
+ char buf[1024];
+_AT_@ -49,6 +51,8 @@ main(int argc, char *argv[])
+ {
+ struct sigaction act;
+ struct timespec start, current, diff, intspec, wait;
++ long val;
++ const char *fmt;
+ size_t i, len;
+ int sflag, ret;
+ char status[MAXLEN];
+_AT_@ -91,8 +95,16 @@ main(int argc, char *argv[])
+ if (!(res = args[i].func(args[i].args)))
+ res = unknown_str;
+
++ if (args[i].limit &&
++ (val = strtol(res, NULL, 10)) > args[i].limit &&
++ args[i].limit_fmt) {
++ fmt = args[i].limit_fmt;
++ } else {
++ fmt = args[i].fmt;
++ }
++
+ if ((ret = esnprintf(status + len, sizeof(status) - len,
+- args[i].fmt, res)) < 0)
++ fmt, res)) < 0)
+ break;
+
+ len += ret;
+--
+2.43.0
+
Received on Tue Feb 10 2026 - 17:46:07 CET

This archive was generated by hypermail 2.3.0 : Tue Feb 10 2026 - 17:48:45 CET