mirror of
https://github.com/Llewellynvdm/starship.git
synced 2024-11-24 21:57:41 +00:00
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
|
||||
|
||||
| Option | 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. |
|
||||
| `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. |
|
||||
| Option | 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. |
|
||||
| `unknown_symbol` | `""` | The symbol shown when the battery state is unknown. |
|
||||
| `empty_symbol` | `""` | The symbol shown when the battery state is empty. |
|
||||
| `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
|
||||
|
||||
|
@ -20,11 +20,6 @@ If emojis aren't your thing, this might catch your eye!
|
||||
[aws]
|
||||
symbol = " "
|
||||
|
||||
[battery]
|
||||
full_symbol = ""
|
||||
charging_symbol = ""
|
||||
discharging_symbol = ""
|
||||
|
||||
[conda]
|
||||
symbol = " "
|
||||
|
||||
|
@ -7,8 +7,8 @@ pub struct BatteryConfig<'a> {
|
||||
pub full_symbol: &'a str,
|
||||
pub charging_symbol: &'a str,
|
||||
pub discharging_symbol: &'a str,
|
||||
pub unknown_symbol: Option<&'a str>,
|
||||
pub empty_symbol: Option<&'a str>,
|
||||
pub unknown_symbol: &'a str,
|
||||
pub empty_symbol: &'a str,
|
||||
pub display: Vec<BatteryDisplayConfig<'a>>,
|
||||
pub disabled: bool,
|
||||
pub format: &'a str,
|
||||
@ -17,11 +17,11 @@ pub struct BatteryConfig<'a> {
|
||||
impl<'a> RootModuleConfig<'a> for BatteryConfig<'a> {
|
||||
fn new() -> Self {
|
||||
BatteryConfig {
|
||||
full_symbol: "•",
|
||||
charging_symbol: "↑",
|
||||
discharging_symbol: "↓",
|
||||
unknown_symbol: None,
|
||||
empty_symbol: None,
|
||||
full_symbol: "",
|
||||
charging_symbol: "",
|
||||
discharging_symbol: "",
|
||||
unknown_symbol: "",
|
||||
empty_symbol: "",
|
||||
format: "[$symbol$percentage]($style) ",
|
||||
display: vec![BatteryDisplayConfig {
|
||||
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::Charging => Some(config.charging_symbol),
|
||||
battery::State::Discharging => Some(config.discharging_symbol),
|
||||
battery::State::Unknown => config.unknown_symbol,
|
||||
battery::State::Empty => config.empty_symbol,
|
||||
battery::State::Unknown => Some(config.unknown_symbol),
|
||||
battery::State::Empty => Some(config.empty_symbol),
|
||||
_ => {
|
||||
log::debug!("Unhandled battery state `{}`", state);
|
||||
None
|
||||
@ -85,7 +85,12 @@ fn get_battery_status() -> Option<BatteryStatus> {
|
||||
})
|
||||
}
|
||||
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
|
||||
}
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user