From a63bc849184c99a74ab2b5aacf062999749e9b0a Mon Sep 17 00:00:00 2001 From: Benjamin Cheng Date: Wed, 4 Sep 2019 14:43:52 -0400 Subject: [PATCH 1/2] Add configurable time display for battery module Adds a `format-time` configuration for the battery module so that users can configure how they want their remaining time to be displayed. The default format remains the same as before, i.e. `{H} h {M} min`, but users can choose something like `{H}:{M:02d}` to give an output like `4:29` if wanted. --- src/modules/battery.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/modules/battery.cpp b/src/modules/battery.cpp index e3d7c9b8..31190edb 100644 --- a/src/modules/battery.cpp +++ b/src/modules/battery.cpp @@ -141,7 +141,11 @@ const std::string waybar::modules::Battery::formatTimeRemaining(float hoursRemai hoursRemaining = std::fabs(hoursRemaining); uint16_t full_hours = static_cast(hoursRemaining); uint16_t minutes = static_cast(60 * (hoursRemaining - full_hours)); - return std::to_string(full_hours) + " h " + std::to_string(minutes) + " min"; + auto format = std::string("{H} h {M} min"); + if (config_["format-time"].isString()) { + format = config_["format-time"].asString(); + } + return fmt::format(format, fmt::arg("H", full_hours), fmt::arg("M", minutes)); } auto waybar::modules::Battery::update() -> void { From dc93fa821807c94873b67264245b08c7b8367428 Mon Sep 17 00:00:00 2001 From: Benjamin Cheng Date: Fri, 6 Sep 2019 14:53:43 -0400 Subject: [PATCH 2/2] Documentation for `format-time` --- man/waybar-battery.5.scd | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/man/waybar-battery.5.scd b/man/waybar-battery.5.scd index 3d23a4cb..94a99e4f 100644 --- a/man/waybar-battery.5.scd +++ b/man/waybar-battery.5.scd @@ -32,6 +32,11 @@ The *battery* module displays the current capacity and state (eg. charging) of y default: {capacity}% ++ The format, how the time should be displayed. +*format-time* ++ + typeof: string ++ + default: {H} h {M} min ++ + The format, how the time should be displayed. + *format-icons* typeof: array/object Based on the current capacity, the corresponding icon gets selected. ++ @@ -78,6 +83,14 @@ The *battery* module displays the current capacity and state (eg. charging) of y *{time}*: Estimate of time until full or empty. Note that this is based on the power draw at the last refresh time, not an average. +# TIME FORMAT + +The *battery* module allows you to define how time should be formatted via *format-time*. + +The two arguments are: +*{H}*: Hours +*{M}*: Minutes + # CUSTOM FORMATS The *battery* module allows to define custom formats based on up to two factors. The best fitting format will be selected.