diff --git a/docs/config/README.md b/docs/config/README.md index 3a5c47bcf..ce97a1fac 100644 --- a/docs/config/README.md +++ b/docs/config/README.md @@ -109,13 +109,13 @@ The module is only visible when the device's battery is below 10%. ### Options -| Variable | Default | Description | -| -------------------- | ------------ | ------------------------------------------------- | -| `full_symbol` | `"•"` | The symbol shown when the battery is full. | -| `charging_symbol` | `"⇡"` | The symbol shown when the battery is charging. | -| `discharging_symbol` | `"⇣"` | The symbol shown when the battery is discharging. | -| `style` | `"bold red"` | The style for the module. | -| `disabled` | `false` | Disables the `battery` module. | +| Variable | Default | Description | +| -------------------- | ------------------------ | ------------------------------------------------- | +| `full_symbol` | `"•"` | The symbol shown when the battery is full. | +| `charging_symbol` | `"⇡"` | The symbol shown when the battery is charging. | +| `discharging_symbol` | `"⇣"` | The symbol shown when the battery is discharging. | +| `display` | [link](#battery-display) | Display threshold and style for the module. | +| `disabled` | `false` | Disables the `battery` module. | ### Example @@ -128,6 +128,41 @@ charging_symbol = "⚡️" discharging_symbol = "💀" ``` +### Battery Display + +The `display` configuration option is used to define when the battery indicator should be shown (threshold) and what it looks like (style). +If no `display` is provided. The default is as shown: + +```toml +[[battery.display]] +threshold = 10 +style = "bold red" +``` + +#### Options + +The `display` option is an array of the following table. + +| Variable | Description | +|-------------|-------------------------------------------------| +| `threshold` | The upper bound for the display option. | +| `style` | The style used if the display option is in use. | + +#### Example + +```toml +[[battery.display]] # "bold red" style when capacity is between 0% and 10% +threshold = 10 +style = "bold red" + +[[battery.display]] # "bold yellow" style when capacity is between 10% and 30% +threshold = 30 +style = "bold yellow" + +# when capacity is over 30%, the battery indicator will not be displayed + +``` + ## Character The `character` module shows a character (usually an arrow) beside where the text diff --git a/src/module.rs b/src/module.rs index 04233578a..c2f4580e1 100644 --- a/src/module.rs +++ b/src/module.rs @@ -145,6 +145,11 @@ impl<'a> Module<'a> { pub fn config_value_style(&self, key: &str) -> Option