2020-10-05 02:33:12 -07:00
|
|
|
---
|
|
|
|
id: battery
|
|
|
|
title: Battery
|
|
|
|
sidebar_label: Battery
|
|
|
|
---
|
|
|
|
|
|
|
|
## What
|
|
|
|
|
2022-02-06 23:02:02 -08:00
|
|
|
:::caution
|
|
|
|
The segment is not supported and automatically disabled on windows when WSL 1 is detected. Works fine with WSL 2.
|
|
|
|
:::
|
|
|
|
|
2020-10-05 02:33:12 -07:00
|
|
|
Battery displays the remaining power percentage for your battery.
|
|
|
|
|
|
|
|
## Sample Configuration
|
|
|
|
|
|
|
|
```json
|
|
|
|
{
|
|
|
|
"type": "battery",
|
|
|
|
"style": "powerline",
|
2020-10-15 23:37:43 -07:00
|
|
|
"powerline_symbol": "\uE0B0",
|
2020-10-05 02:33:12 -07:00
|
|
|
"foreground": "#193549",
|
|
|
|
"background": "#ffeb3b",
|
2021-11-25 04:55:03 -08:00
|
|
|
"background_templates": [
|
|
|
|
"{{if eq \"Charging\" .State.String}}#40c4ff{{end}}",
|
|
|
|
"{{if eq \"Discharging\" .State.String}}#ff5722{{end}}",
|
|
|
|
"{{if eq \"Full\" .State.String}}#4caf50{{end}}"
|
|
|
|
],
|
2022-03-27 01:12:47 -07:00
|
|
|
"template": " {{ if not .Error }}{{ .Icon }}{{ .Percentage }}{{ end }}\uF295 ",
|
2020-10-05 02:33:12 -07:00
|
|
|
"properties": {
|
2020-10-16 01:18:22 -07:00
|
|
|
"discharging_icon": "\uE231 ",
|
|
|
|
"charging_icon": "\uE234 ",
|
2022-03-27 01:12:47 -07:00
|
|
|
"charged_icon": "\uE22F "
|
2020-10-05 02:33:12 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
## Properties
|
|
|
|
|
2020-11-11 09:51:56 -08:00
|
|
|
- display_error: `boolean` - show the error context when failing to retrieve the battery information - defaults to `false`
|
2022-05-09 22:25:05 -07:00
|
|
|
- charging_icon: `string` - icon to display when charging - defaults to empty
|
|
|
|
- discharging_icon: `string` - icon to display when discharging - defaults to empty
|
|
|
|
- charged_icon: `string` - icon to display when fully charged - defaults to empty
|
|
|
|
- not_charging_icon: `string` - icon to display when fully charged - defaults to empty
|
2020-10-05 02:33:12 -07:00
|
|
|
|
2022-02-01 03:10:46 -08:00
|
|
|
## Template ([info][templates])
|
|
|
|
|
|
|
|
:::note default template
|
|
|
|
|
|
|
|
``` template
|
|
|
|
{{ if not .Error }}{{ .Icon }}{{ .Percentage }}{{ end }}{{ .Error }}
|
|
|
|
```
|
|
|
|
|
|
|
|
:::
|
|
|
|
|
|
|
|
### Properties
|
2021-02-15 12:34:48 -08:00
|
|
|
|
2021-11-25 04:55:03 -08:00
|
|
|
- `.State`: `struct` - the battery state, has a `.String` function
|
|
|
|
- `.Current`: `float64` - Current (momentary) charge rate (in mW).
|
|
|
|
- `.Full`: `float64` - Last known full capacity (in mWh)
|
|
|
|
- `.Design`: `float64` - Reported design capacity (in mWh)
|
|
|
|
- `.ChargeRate`: `float64` - Current (momentary) charge rate (in mW). It is always non-negative, consult .State
|
2021-12-11 03:23:18 -08:00
|
|
|
field to check whether it means charging or discharging (on some systems this might be always `0` if the battery
|
|
|
|
doesn't support it)
|
2021-11-25 04:55:03 -08:00
|
|
|
- `.Voltage`: `float64` - Current voltage (in V)
|
|
|
|
- `.DesignVoltage`: `float64` - Design voltage (in V). Some systems (e.g. macOS) do not provide a separate
|
|
|
|
value for this. In such cases, or if getting this fails, but getting `Voltage` succeeds, this field will have
|
|
|
|
the same value as `Voltage`, for convenience
|
2021-02-15 12:34:48 -08:00
|
|
|
- `.Percentage`: `float64` - the current battery percentage
|
2021-03-28 07:15:21 -07:00
|
|
|
- `.Error`: `string` - the error in case fetching the battery information failed
|
|
|
|
- `.Icon`: `string` - the icon based on the battery state
|
2021-02-15 12:34:48 -08:00
|
|
|
|
2022-04-20 09:43:59 -07:00
|
|
|
[colors]: /docs/configuration/colors
|
2021-02-15 12:34:48 -08:00
|
|
|
[battery]: https://github.com/distatus/battery/blob/master/battery.go#L78
|
2022-04-20 09:43:59 -07:00
|
|
|
[templates]: /docs/configuration/templates
|