diff --git a/docs/config/README.md b/docs/config/README.md index 7b75b301..675906e6 100644 --- a/docs/config/README.md +++ b/docs/config/README.md @@ -348,7 +348,7 @@ 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). +The `display` configuration option is used to define when the battery indicator should be shown (threshold), which symbol would be used (symbol), and what it would like (style). If no `display` is provided. The default is as shown: ```toml @@ -357,25 +357,30 @@ threshold = 10 style = "bold red" ``` +The default value for the `charging_symbol` and `discharging_symbol` option is respectively the value of `battery`'s `charging_symbol` and `discharging_symbol` option. + #### Options The `display` option is an array of the following table. -| Option | Description | -| ----------- | ----------------------------------------------- | -| `threshold` | The upper bound for the display option. | -| `style` | The style used if the display option is in use. | +| Option | Default | Description | +| -------------------- | ---------- | ----------------------------------------------- | +| `threshold` | `10` | The upper bound for the display option. | +| `style` | `bold red` | The style used if the display option is in use. | +| `charging_symbol` | `-` | Optional symbol displayed if display option is in use, defaults to battery's `charging_symbol` option. | +| `discharging_symbol` | `-` | Optional symbol displayed if display option is in use, defaults to battery's `discharging_symbol` option. | #### Example ```toml -[[battery.display]] # "bold red" style when capacity is between 0% and 10% +[[battery.display]] # "bold red" style and discharging_symbol when capacity is between 0% and 10% threshold = 10 style = "bold red" -[[battery.display]] # "bold yellow" style when capacity is between 10% and 30% +[[battery.display]] # "bold yellow" style and 💦 symbol when capacity is between 10% and 30% threshold = 30 style = "bold yellow" +discharging_symbol = 💦 # when capacity is over 30%, the battery indicator will not be displayed diff --git a/src/configs/battery.rs b/src/configs/battery.rs index 56852546..817c2afe 100644 --- a/src/configs/battery.rs +++ b/src/configs/battery.rs @@ -24,17 +24,27 @@ impl<'a> Default for BatteryConfig<'a> { unknown_symbol: " ", empty_symbol: " ", format: "[$symbol$percentage]($style) ", - display: vec![BatteryDisplayConfig { - threshold: 10, - style: "red bold", - }], + display: vec![BatteryDisplayConfig::default()], disabled: false, } } } -#[derive(Clone, ModuleConfig, Default, Serialize)] +#[derive(Clone, ModuleConfig, Serialize)] pub struct BatteryDisplayConfig<'a> { pub threshold: i64, pub style: &'a str, + pub charging_symbol: Option<&'a str>, + pub discharging_symbol: Option<&'a str>, +} + +impl<'a> Default for BatteryDisplayConfig<'a> { + fn default() -> Self { + BatteryDisplayConfig { + threshold: 10, + style: "red bold", + charging_symbol: None, + discharging_symbol: None, + } + } } diff --git a/src/modules/battery.rs b/src/modules/battery.rs index 3f53573a..b4767729 100644 --- a/src/modules/battery.rs +++ b/src/modules/battery.rs @@ -33,8 +33,12 @@ pub fn module<'a>(context: &'a Context) -> Option> { .map_meta(|variable, _| match variable { "symbol" => match state { battery::State::Full => Some(config.full_symbol), - battery::State::Charging => Some(config.charging_symbol), - battery::State::Discharging => Some(config.discharging_symbol), + battery::State::Charging => display_style + .charging_symbol + .or(Some(config.charging_symbol)), + battery::State::Discharging => display_style + .discharging_symbol + .or(Some(config.discharging_symbol)), battery::State::Unknown => Some(config.unknown_symbol), battery::State::Empty => Some(config.empty_symbol), _ => {