mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-27 11:59:40 -08:00
parent
b152e9df29
commit
6d3e05e4e0
|
@ -34,7 +34,7 @@ Battery displays the remaining power percentage for your battery.
|
|||
## Properties
|
||||
|
||||
- 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
|
||||
- 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
|
||||
|
|
|
@ -34,9 +34,10 @@ const (
|
|||
|
||||
func (b *batt) enabled() bool {
|
||||
bt, err := b.env.getBatteryInfo()
|
||||
displayError := b.props.getBool(DisplayError, true)
|
||||
displayError := b.props.getBool(DisplayError, false)
|
||||
if err != nil && !displayError {
|
||||
return false
|
||||
b.percentageText = "100%"
|
||||
return true
|
||||
}
|
||||
if err != nil {
|
||||
b.percentageText = "BATT ERR"
|
||||
|
|
|
@ -119,8 +119,12 @@ func TestBatteryError(t *testing.T) {
|
|||
err := errors.New("oh snap")
|
||||
env.On("getBatteryInfo", nil).Return(&battery.Battery{}, err)
|
||||
b := &batt{
|
||||
props: nil,
|
||||
env: env,
|
||||
props: &properties{
|
||||
values: map[Property]interface{}{
|
||||
DisplayError: true,
|
||||
},
|
||||
},
|
||||
env: env,
|
||||
}
|
||||
assert.True(t, b.enabled())
|
||||
assert.Equal(t, "BATT ERR", b.string())
|
||||
|
@ -130,15 +134,14 @@ func TestBatteryErrorHidden(t *testing.T) {
|
|||
env := &MockedEnvironment{}
|
||||
err := errors.New("oh snap")
|
||||
env.On("getBatteryInfo", nil).Return(&battery.Battery{}, err)
|
||||
props := &properties{
|
||||
values: map[Property]interface{}{
|
||||
DisplayError: false,
|
||||
},
|
||||
}
|
||||
b := &batt{
|
||||
props: props,
|
||||
env: env,
|
||||
props: &properties{
|
||||
values: map[Property]interface{}{
|
||||
DisplayError: false,
|
||||
},
|
||||
},
|
||||
env: env,
|
||||
}
|
||||
assert.False(t, b.enabled())
|
||||
assert.Equal(t, "", b.string())
|
||||
assert.True(t, b.enabled())
|
||||
assert.Equal(t, "100%", b.string())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue