跳转到主内容

电池

非官方测试版翻译

本页面由 PageTurner AI 翻译(测试版)。未经项目官方认可。 发现错误? 报告问题 →

功能

注意

检测到 WSL 1 时,该段落在 Windows 上不受支持并会自动禁用。在 WSL 2 下工作正常。

Battery 段落用于显示电池的剩余电量百分比。

示例配置

{
"type": "battery",
"style": "powerline",
"powerline_symbol": "",
"foreground": "#193549",
"background": "#ffeb3b",
"background_templates": [
"{{if eq \"Charging\" .State.String}}#40c4ff{{end}}",
"{{if eq \"Discharging\" .State.String}}#ff5722{{end}}",
"{{if eq \"Full\" .State.String}}#4caf50{{end}}"
],
"template": " {{ if not .Error }}{{ .Icon }}{{ .Percentage }}{{ end }} ",
"options": {
"discharging_icon": " ",
"charging_icon": " ",
"charged_icon": " "
}
}

选项

NameTypeDefaultDescription
display_errorbooleanfalseshow the error context when failing to retrieve the battery information
charging_iconstringicon to display when charging
discharging_iconstringicon to display when discharging
charged_iconstringicon to display when fully charged
not_charging_iconstringicon to display when fully charged

模板 (信息)

默认模板
 {{ if not .Error }}{{ .Icon }}{{ .Percentage }}{{ end }}{{ .Error }}

属性

NameTypeDescription
.Statestructthe battery state, has a .String function
.Currentfloat64Current (momentary) charge rate (in mW).
.Fullfloat64Last known full capacity (in mWh)
.Designfloat64Reported design capacity (in mWh)
.ChargeRatefloat64Current (momentary) charge rate (in mW). It is always non-negative, consult .State field to check whether it means charging or discharging (on some systems this might be always 0 if the battery doesn't support it)
.Voltagefloat64Current voltage (in V)
.DesignVoltagefloat64Design 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
.Percentagefloat64the current battery percentage
.Errorstringthe error in case fetching the battery information failed
.Iconstringthe icon based on the battery state