mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-25 11:04:04 -08:00
feat(battery): display_charged parameter added
display_charging splitted to two parameters instead of a single one BREAKING CHANGE: from now display_charging will handle the charging status only.
This commit is contained in:
parent
5de2c1ae68
commit
cb9a090ec7
|
@ -27,7 +27,8 @@ Battery displays the remaining power percentage for your battery.
|
|||
"charging_color": "#40c4ff",
|
||||
"discharging_color": "#ff5722",
|
||||
"postfix": "\uF295 ",
|
||||
"display_charging": true
|
||||
"display_charging": true,
|
||||
"display_charged": true
|
||||
}
|
||||
}
|
||||
```
|
||||
|
@ -44,7 +45,8 @@ properties below. Defaults to `{{.Icon}}{{ if not .Error }}{{.Percentage}}{{ end
|
|||
- charged_color: `string` [color][colors] - color to use when fully charged - defaults to segment color
|
||||
- charging_color: `string` [color][colors] - color to use when charging - defaults to segment color
|
||||
- discharging_color: `string` [color][colors] - color to use when discharging - defaults to segment color
|
||||
- display_charging: `bool` - displays the battery status while charging (Charging or Full)
|
||||
- display_charging: `bool` - displays the battery status while charging (Charging)
|
||||
- display_charged: `bool` - displays the battery status when charged (Full)
|
||||
|
||||
## Template Properties
|
||||
|
||||
|
|
|
@ -30,6 +30,8 @@ const (
|
|||
DischargingColor Property = "discharging_color"
|
||||
// DisplayCharging Hide the battery icon while it's charging
|
||||
DisplayCharging Property = "display_charging"
|
||||
// DisplayCharged Hide the battery icon when it's charged
|
||||
DisplayCharged Property = "display_charged"
|
||||
)
|
||||
|
||||
func (b *batt) enabled() bool {
|
||||
|
@ -51,8 +53,12 @@ func (b *batt) enabled() bool {
|
|||
b.Battery.State = b.mapMostLogicalState(b.Battery.State, bt.State)
|
||||
}
|
||||
|
||||
display := b.props.getBool(DisplayCharging, true)
|
||||
if !display && (b.Battery.State == battery.Charging || b.Battery.State == battery.Full) {
|
||||
displayCharged := b.props.getBool(DisplayCharged, true)
|
||||
if !displayCharged && (b.Battery.State == battery.Full) {
|
||||
return false
|
||||
}
|
||||
displayCharging := b.props.getBool(DisplayCharging, true)
|
||||
if !displayCharging && (b.Battery.State == battery.Charging) {
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ func TestBatterySegmentSingle(t *testing.T) {
|
|||
DisplayError bool
|
||||
Error error
|
||||
DisableCharging bool
|
||||
DisableCharged bool
|
||||
}{
|
||||
{Case: "80% charging", Batteries: []*battery.Battery{{Full: 100, State: battery.Charging, Current: 80}}, ExpectedString: "charging 80", ExpectedEnabled: true},
|
||||
{Case: "battery full", Batteries: []*battery.Battery{{Full: 100, State: battery.Full, Current: 100}}, ExpectedString: "charged 100", ExpectedEnabled: true},
|
||||
|
@ -79,7 +80,17 @@ func TestBatterySegmentSingle(t *testing.T) {
|
|||
{Case: "no batteries", DisplayError: true, Error: &noBatteryError{}},
|
||||
{Case: "no batteries without error"},
|
||||
{Case: "display charging disabled: charging", Batteries: []*battery.Battery{{Full: 100, State: battery.Charging}}, DisableCharging: true},
|
||||
{Case: "display charging disabled: charged", Batteries: []*battery.Battery{{Full: 100, State: battery.Full}}, DisableCharging: true},
|
||||
{Case: "display charged disabled: charged", Batteries: []*battery.Battery{{Full: 100, State: battery.Full}}, DisableCharged: true},
|
||||
{
|
||||
Case: "display charging disabled/display charged enabled: charging",
|
||||
Batteries: []*battery.Battery{{Full: 100, State: battery.Charging}},
|
||||
DisableCharging: true,
|
||||
DisableCharged: false},
|
||||
{
|
||||
Case: "display charged disabled/display charging enabled: charged",
|
||||
Batteries: []*battery.Battery{{Full: 100, State: battery.Full}},
|
||||
DisableCharged: true,
|
||||
DisableCharging: false},
|
||||
{
|
||||
Case: "display charging disabled: discharging",
|
||||
Batteries: []*battery.Battery{{Full: 100, State: battery.Discharging, Current: 70}},
|
||||
|
@ -105,9 +116,13 @@ func TestBatterySegmentSingle(t *testing.T) {
|
|||
DisplayError: tc.DisplayError,
|
||||
},
|
||||
}
|
||||
// default values
|
||||
if tc.DisableCharging {
|
||||
props.values[DisplayCharging] = false
|
||||
}
|
||||
if tc.DisableCharged {
|
||||
props.values[DisplayCharged] = false
|
||||
}
|
||||
env.On("getBatteryInfo", nil).Return(tc.Batteries, tc.Error)
|
||||
b := &batt{
|
||||
props: props,
|
||||
|
|
|
@ -367,7 +367,13 @@
|
|||
"display_charging": {
|
||||
"type": "boolean",
|
||||
"title": "Display while charging",
|
||||
"description": "displays the battery status while charging (Charging or Full)",
|
||||
"description": "displays the battery status while charging (Charging)",
|
||||
"default": true
|
||||
},
|
||||
"display_charged": {
|
||||
"type": "boolean",
|
||||
"title": "Display when full",
|
||||
"description": "displays the battery status when charged (Full)",
|
||||
"default": true
|
||||
},
|
||||
"template": {
|
||||
|
|
Loading…
Reference in a new issue