summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2020-05-07 18:47:28 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2020-05-08 11:26:03 +0200
commitc01ef54f7f63ea3d3194a7b91b0a30768e64e7bd (patch)
tree4937796d513dc03230c1e1915294e9d03e4e9b89
parenthwdb: Fix accel orientation quirk for Medion Akoya E2215T MD60198 (diff)
downloadsystemd-c01ef54f7f63ea3d3194a7b91b0a30768e64e7bd.tar.xz
systemd-c01ef54f7f63ea3d3194a7b91b0a30768e64e7bd.zip
homectl: color disk free output if low on free space
-rw-r--r--src/shared/user-record-show.c22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/shared/user-record-show.c b/src/shared/user-record-show.c
index d8b46f2db2..de04859a2f 100644
--- a/src/shared/user-record-show.c
+++ b/src/shared/user-record-show.c
@@ -356,12 +356,30 @@ void user_record_show(UserRecord *hr, bool show_full_group_info) {
char buf[FORMAT_BYTES_MAX];
if (hr->disk_size != UINT64_MAX) {
+ const char *color_on, *color_off;
unsigned permille;
permille = (unsigned) ((hr->disk_free * 1000U) / hr->disk_size); /* Round down! */
- printf(" Disk Free: %s (= %u.%01u%%)\n",
+
+ /* Color the output red or yellow if we are below 10% resp. 25% free. Because 10% and
+ * 25% can be a lot of space still, let's additionally make some absolute
+ * restrictions: 1G and 2G */
+ if (permille <= 100U &&
+ hr->disk_free < 1024U*1024U*1024U /* 1G */) {
+ color_on = ansi_highlight_red();
+ color_off = ansi_normal();
+ } else if (permille <= 250U &&
+ hr->disk_free < 2U*1024U*1024U*1024U /* 2G */) {
+ color_on = ansi_highlight_yellow();
+ color_off = ansi_normal();
+ } else
+ color_on = color_off = "";
+
+ printf(" Disk Free: %s%s (= %u.%01u%%)%s\n",
+ color_on,
format_bytes(buf, sizeof(buf), hr->disk_free),
- permille / 10, permille % 10);
+ permille / 10, permille % 10,
+ color_off);
} else
printf(" Disk Free: %s\n", format_bytes(buf, sizeof(buf), hr->disk_free));
}