feat(battery): make module behaviour more obvious (#1950)
This commit is contained in:
parent
f7a55dde8e
commit
6de4bb01f4
|
@ -316,26 +316,17 @@ The module is only visible when the device's battery is below 10%.
|
||||||
|
|
||||||
### Options
|
### Options
|
||||||
|
|
||||||
| Option | Default | Description |
|
| Option | Default | Description |
|
||||||
| -------------------- | --------------------------------- | ------------------------------------------------- |
|
| -------------------- | --------------------------------- | --------------------------------------------------- |
|
||||||
| `full_symbol` | `"•"` | The symbol shown when the battery is full. |
|
| `full_symbol` | `""` | The symbol shown when the battery is full. |
|
||||||
| `charging_symbol` | `"⇡"` | The symbol shown when the battery is charging. |
|
| `charging_symbol` | `""` | The symbol shown when the battery is charging. |
|
||||||
| `discharging_symbol` | `"⇣"` | The symbol shown when the battery is discharging. |
|
| `discharging_symbol` | `""` | The symbol shown when the battery is discharging. |
|
||||||
| `format` | `"[$symbol$percentage]($style) "` | The format for the module. |
|
| `unknown_symbol` | `""` | The symbol shown when the battery state is unknown. |
|
||||||
| `display` | [link](#battery-display) | Display threshold and style for the module. |
|
| `empty_symbol` | `""` | The symbol shown when the battery state is empty. |
|
||||||
| `disabled` | `false` | Disables the `battery` module. |
|
| `format` | `"[$symbol$percentage]($style) "` | The format for the module. |
|
||||||
|
| `display` | [link](#battery-display) | Display threshold and style for the module. |
|
||||||
|
| `disabled` | `false` | Disables the `battery` module. |
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>There are also options for some uncommon battery states.</summary>
|
|
||||||
|
|
||||||
| Variable | Description |
|
|
||||||
| ---------------- | --------------------------------------------------- |
|
|
||||||
| `unknown_symbol` | The symbol shown when the battery state is unknown. |
|
|
||||||
| `empty_symbol` | The symbol shown when the battery state is empty. |
|
|
||||||
|
|
||||||
Note: Battery indicator will be hidden if the status is `unknown` or `empty` unless you specify the option in the config.
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
|
|
|
@ -20,11 +20,6 @@ If emojis aren't your thing, this might catch your eye!
|
||||||
[aws]
|
[aws]
|
||||||
symbol = " "
|
symbol = " "
|
||||||
|
|
||||||
[battery]
|
|
||||||
full_symbol = ""
|
|
||||||
charging_symbol = ""
|
|
||||||
discharging_symbol = ""
|
|
||||||
|
|
||||||
[conda]
|
[conda]
|
||||||
symbol = " "
|
symbol = " "
|
||||||
|
|
||||||
|
|
|
@ -7,8 +7,8 @@ pub struct BatteryConfig<'a> {
|
||||||
pub full_symbol: &'a str,
|
pub full_symbol: &'a str,
|
||||||
pub charging_symbol: &'a str,
|
pub charging_symbol: &'a str,
|
||||||
pub discharging_symbol: &'a str,
|
pub discharging_symbol: &'a str,
|
||||||
pub unknown_symbol: Option<&'a str>,
|
pub unknown_symbol: &'a str,
|
||||||
pub empty_symbol: Option<&'a str>,
|
pub empty_symbol: &'a str,
|
||||||
pub display: Vec<BatteryDisplayConfig<'a>>,
|
pub display: Vec<BatteryDisplayConfig<'a>>,
|
||||||
pub disabled: bool,
|
pub disabled: bool,
|
||||||
pub format: &'a str,
|
pub format: &'a str,
|
||||||
|
@ -17,11 +17,11 @@ pub struct BatteryConfig<'a> {
|
||||||
impl<'a> RootModuleConfig<'a> for BatteryConfig<'a> {
|
impl<'a> RootModuleConfig<'a> for BatteryConfig<'a> {
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
BatteryConfig {
|
BatteryConfig {
|
||||||
full_symbol: "•",
|
full_symbol: "",
|
||||||
charging_symbol: "↑",
|
charging_symbol: "",
|
||||||
discharging_symbol: "↓",
|
discharging_symbol: "",
|
||||||
unknown_symbol: None,
|
unknown_symbol: "",
|
||||||
empty_symbol: None,
|
empty_symbol: "",
|
||||||
format: "[$symbol$percentage]($style) ",
|
format: "[$symbol$percentage]($style) ",
|
||||||
display: vec![BatteryDisplayConfig {
|
display: vec![BatteryDisplayConfig {
|
||||||
threshold: 10,
|
threshold: 10,
|
||||||
|
|
|
@ -35,8 +35,8 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||||
battery::State::Full => Some(config.full_symbol),
|
battery::State::Full => Some(config.full_symbol),
|
||||||
battery::State::Charging => Some(config.charging_symbol),
|
battery::State::Charging => Some(config.charging_symbol),
|
||||||
battery::State::Discharging => Some(config.discharging_symbol),
|
battery::State::Discharging => Some(config.discharging_symbol),
|
||||||
battery::State::Unknown => config.unknown_symbol,
|
battery::State::Unknown => Some(config.unknown_symbol),
|
||||||
battery::State::Empty => config.empty_symbol,
|
battery::State::Empty => Some(config.empty_symbol),
|
||||||
_ => {
|
_ => {
|
||||||
log::debug!("Unhandled battery state `{}`", state);
|
log::debug!("Unhandled battery state `{}`", state);
|
||||||
None
|
None
|
||||||
|
@ -85,7 +85,12 @@ fn get_battery_status() -> Option<BatteryStatus> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::warn!("Unable to access battery information:\n{}", &e);
|
let level = if cfg!(target_os = "linux") {
|
||||||
|
log::Level::Info
|
||||||
|
} else {
|
||||||
|
log::Level::Warn
|
||||||
|
};
|
||||||
|
log::log!(level, "Unable to access battery information:\n{}", &e);
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue