mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-03-05 20:49: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",
|
"charging_color": "#40c4ff",
|
||||||
"discharging_color": "#ff5722",
|
"discharging_color": "#ff5722",
|
||||||
"postfix": "\uF295 ",
|
"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
|
- 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
|
- 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
|
- 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
|
## Template Properties
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,8 @@ const (
|
||||||
DischargingColor Property = "discharging_color"
|
DischargingColor Property = "discharging_color"
|
||||||
// DisplayCharging Hide the battery icon while it's charging
|
// DisplayCharging Hide the battery icon while it's charging
|
||||||
DisplayCharging Property = "display_charging"
|
DisplayCharging Property = "display_charging"
|
||||||
|
// DisplayCharged Hide the battery icon when it's charged
|
||||||
|
DisplayCharged Property = "display_charged"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (b *batt) enabled() bool {
|
func (b *batt) enabled() bool {
|
||||||
|
@ -51,8 +53,12 @@ func (b *batt) enabled() bool {
|
||||||
b.Battery.State = b.mapMostLogicalState(b.Battery.State, bt.State)
|
b.Battery.State = b.mapMostLogicalState(b.Battery.State, bt.State)
|
||||||
}
|
}
|
||||||
|
|
||||||
display := b.props.getBool(DisplayCharging, true)
|
displayCharged := b.props.getBool(DisplayCharged, true)
|
||||||
if !display && (b.Battery.State == battery.Charging || b.Battery.State == battery.Full) {
|
if !displayCharged && (b.Battery.State == battery.Full) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
displayCharging := b.props.getBool(DisplayCharging, true)
|
||||||
|
if !displayCharging && (b.Battery.State == battery.Charging) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ func TestBatterySegmentSingle(t *testing.T) {
|
||||||
DisplayError bool
|
DisplayError bool
|
||||||
Error error
|
Error error
|
||||||
DisableCharging bool
|
DisableCharging bool
|
||||||
|
DisableCharged bool
|
||||||
}{
|
}{
|
||||||
{Case: "80% charging", Batteries: []*battery.Battery{{Full: 100, State: battery.Charging, Current: 80}}, ExpectedString: "charging 80", ExpectedEnabled: true},
|
{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},
|
{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", DisplayError: true, Error: &noBatteryError{}},
|
||||||
{Case: "no batteries without error"},
|
{Case: "no batteries without error"},
|
||||||
{Case: "display charging disabled: charging", Batteries: []*battery.Battery{{Full: 100, State: battery.Charging}}, DisableCharging: true},
|
{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",
|
Case: "display charging disabled: discharging",
|
||||||
Batteries: []*battery.Battery{{Full: 100, State: battery.Discharging, Current: 70}},
|
Batteries: []*battery.Battery{{Full: 100, State: battery.Discharging, Current: 70}},
|
||||||
|
@ -105,9 +116,13 @@ func TestBatterySegmentSingle(t *testing.T) {
|
||||||
DisplayError: tc.DisplayError,
|
DisplayError: tc.DisplayError,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
// default values
|
||||||
if tc.DisableCharging {
|
if tc.DisableCharging {
|
||||||
props.values[DisplayCharging] = false
|
props.values[DisplayCharging] = false
|
||||||
}
|
}
|
||||||
|
if tc.DisableCharged {
|
||||||
|
props.values[DisplayCharged] = false
|
||||||
|
}
|
||||||
env.On("getBatteryInfo", nil).Return(tc.Batteries, tc.Error)
|
env.On("getBatteryInfo", nil).Return(tc.Batteries, tc.Error)
|
||||||
b := &batt{
|
b := &batt{
|
||||||
props: props,
|
props: props,
|
||||||
|
|
|
@ -367,7 +367,13 @@
|
||||||
"display_charging": {
|
"display_charging": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"title": "Display while charging",
|
"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
|
"default": true
|
||||||
},
|
},
|
||||||
"template": {
|
"template": {
|
||||||
|
|
Loading…
Reference in a new issue