mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-28 04:19:41 -08:00
parent
b152e9df29
commit
6d3e05e4e0
|
@ -34,7 +34,7 @@ Battery displays the remaining power percentage for your battery.
|
||||||
## Properties
|
## Properties
|
||||||
|
|
||||||
- battery_icon: `string` - the icon to use as a prefix for the battery percentage - defaults to empty
|
- battery_icon: `string` - the icon to use as a prefix for the battery percentage - defaults to empty
|
||||||
- display_error: `boolean` - show the error context when failing to retrieve the battery information - defaults to `true`
|
- display_error: `boolean` - show the error context when failing to retrieve the battery information - defaults to `false`
|
||||||
- charging_icon: `string` - icon to display on the left when charging - defaults to empty
|
- charging_icon: `string` - icon to display on the left when charging - defaults to empty
|
||||||
- discharging_icon: `string` - icon to display on the left when discharging - defaults to empty
|
- discharging_icon: `string` - icon to display on the left when discharging - defaults to empty
|
||||||
- charged_icon: `string` - icon to display on the left when fully charged - defaults to empty
|
- charged_icon: `string` - icon to display on the left when fully charged - defaults to empty
|
||||||
|
|
|
@ -34,9 +34,10 @@ const (
|
||||||
|
|
||||||
func (b *batt) enabled() bool {
|
func (b *batt) enabled() bool {
|
||||||
bt, err := b.env.getBatteryInfo()
|
bt, err := b.env.getBatteryInfo()
|
||||||
displayError := b.props.getBool(DisplayError, true)
|
displayError := b.props.getBool(DisplayError, false)
|
||||||
if err != nil && !displayError {
|
if err != nil && !displayError {
|
||||||
return false
|
b.percentageText = "100%"
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
b.percentageText = "BATT ERR"
|
b.percentageText = "BATT ERR"
|
||||||
|
|
|
@ -119,8 +119,12 @@ func TestBatteryError(t *testing.T) {
|
||||||
err := errors.New("oh snap")
|
err := errors.New("oh snap")
|
||||||
env.On("getBatteryInfo", nil).Return(&battery.Battery{}, err)
|
env.On("getBatteryInfo", nil).Return(&battery.Battery{}, err)
|
||||||
b := &batt{
|
b := &batt{
|
||||||
props: nil,
|
props: &properties{
|
||||||
env: env,
|
values: map[Property]interface{}{
|
||||||
|
DisplayError: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
env: env,
|
||||||
}
|
}
|
||||||
assert.True(t, b.enabled())
|
assert.True(t, b.enabled())
|
||||||
assert.Equal(t, "BATT ERR", b.string())
|
assert.Equal(t, "BATT ERR", b.string())
|
||||||
|
@ -130,15 +134,14 @@ func TestBatteryErrorHidden(t *testing.T) {
|
||||||
env := &MockedEnvironment{}
|
env := &MockedEnvironment{}
|
||||||
err := errors.New("oh snap")
|
err := errors.New("oh snap")
|
||||||
env.On("getBatteryInfo", nil).Return(&battery.Battery{}, err)
|
env.On("getBatteryInfo", nil).Return(&battery.Battery{}, err)
|
||||||
props := &properties{
|
|
||||||
values: map[Property]interface{}{
|
|
||||||
DisplayError: false,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
b := &batt{
|
b := &batt{
|
||||||
props: props,
|
props: &properties{
|
||||||
env: env,
|
values: map[Property]interface{}{
|
||||||
|
DisplayError: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
env: env,
|
||||||
}
|
}
|
||||||
assert.False(t, b.enabled())
|
assert.True(t, b.enabled())
|
||||||
assert.Equal(t, "", b.string())
|
assert.Equal(t, "100%", b.string())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue