From 572c96d63ed41bfc83d7378454f3ae4505ad9601 Mon Sep 17 00:00:00 2001 From: MK13 Date: Sat, 26 Oct 2019 15:32:32 +0200 Subject: Introduce memory options 'unit' and 'decimals' Previously the format placeholders were auto-converted to the maximum possible unit, e.g. /proc/meminfo reports MemTotal of 16307104kB which will get converted to 15.6GiB. It is now possible to specifiy the target unit, e.g. Mi, which will be used for the conversion - in the example it would lead to 15924.9MiB. The resulting number can now be further formatted via the decimal option. It allows to specify the number of decimals to use, e.g. 15.6GiB vs. 15GiB or 15924.9MiB vs. 15925MiB. --- i3status.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'i3status.c') diff --git a/i3status.c b/i3status.c index 1ab8400..4423917 100644 --- a/i3status.c +++ b/i3status.c @@ -431,6 +431,8 @@ int main(int argc, char *argv[]) { CFG_STR("threshold_degraded", NULL, CFGF_NONE), CFG_STR("threshold_critical", NULL, CFGF_NONE), CFG_STR("memory_used_method", "classical", CFGF_NONE), + CFG_STR("unit", "auto", CFGF_NONE), + CFG_INT("decimals", 1, CFGF_NONE), CFG_CUSTOM_ALIGN_OPT, CFG_CUSTOM_COLOR_OPTS, CFG_CUSTOM_MIN_WIDTH_OPT, @@ -763,7 +765,7 @@ int main(int argc, char *argv[]) { CASE_SEC("memory") { SEC_OPEN_MAP("memory"); - print_memory(json_gen, buffer, cfg_getstr(sec, "format"), cfg_getstr(sec, "format_degraded"), cfg_getstr(sec, "threshold_degraded"), cfg_getstr(sec, "threshold_critical"), cfg_getstr(sec, "memory_used_method")); + print_memory(json_gen, buffer, cfg_getstr(sec, "format"), cfg_getstr(sec, "format_degraded"), cfg_getstr(sec, "threshold_degraded"), cfg_getstr(sec, "threshold_critical"), cfg_getstr(sec, "memory_used_method"), cfg_getstr(sec, "unit"), cfg_getint(sec, "decimals")); SEC_CLOSE_MAP; } -- cgit v1.2.3