diff --git a/docs/docs/segment-battery.md b/docs/docs/segment-battery.md index 685bcb1249f6..8d62072477e4 100644 --- a/docs/docs/segment-battery.md +++ b/docs/docs/segment-battery.md @@ -26,7 +26,8 @@ Battery displays the remaining power percentage for your battery. "charged_color": "#4caf50", "charging_color": "#40c4ff", "discharging_color": "#ff5722", - "postfix": "\uF295 " + "postfix": "\uF295 ", + "display_charging": true } } ``` @@ -42,5 +43,6 @@ Battery displays the remaining power percentage for your battery. - 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) [colors]: /docs/configure#colors diff --git a/segment_battery.go b/segment_battery.go index 90bcea38d919..d77c708c165d 100644 --- a/segment_battery.go +++ b/segment_battery.go @@ -30,10 +30,18 @@ const ( ChargingColor Property = "charging_color" // DischargingColor to display when discharging DischargingColor Property = "discharging_color" + // DisplayCharging Hide the battery icon while it's charging + DisplayCharging Property = "display_charging" ) func (b *batt) enabled() bool { bt, err := b.env.getBatteryInfo() + + display := b.props.getBool(DisplayCharging, true) + if !display && (bt.State == battery.Charging || bt.State == battery.Full) { + return false + } + displayError := b.props.getBool(DisplayError, false) if err != nil && !displayError { b.percentageText = "100%" diff --git a/segment_battery_test.go b/segment_battery_test.go index b6d6f4a7c5a3..839a3358a2ff 100644 --- a/segment_battery_test.go +++ b/segment_battery_test.go @@ -149,3 +149,37 @@ func TestBatteryErrorHidden(t *testing.T) { assert.True(t, b.enabled()) assert.Equal(t, "100%", b.string()) } + +func TestBatteryDischargingAndDisplayChargingDisabled(t *testing.T) { + props := &properties{ + values: map[Property]interface{}{ + DischargingIcon: "going down ", + DisplayCharging: false, + }, + } + b := setupBatteryTests(battery.Discharging, 70, props) + assert.Equal(t, true, b.enabled()) + assert.Equal(t, "going down 70", b.string()) +} + +func TestBatteryChargingAndDisplayChargingDisabled(t *testing.T) { + props := &properties{ + values: map[Property]interface{}{ + ChargingIcon: "charging ", + DisplayCharging: false, + }, + } + b := setupBatteryTests(battery.Charging, 80, props) + assert.Equal(t, false, b.enabled()) +} + +func TestBatteryChargedAndDisplayChargingDisabled(t *testing.T) { + props := &properties{ + values: map[Property]interface{}{ + ChargedIcon: "charged ", + DisplayCharging: false, + }, + } + b := setupBatteryTests(battery.Full, 100, props) + assert.Equal(t, false, b.enabled()) +} diff --git a/themes/schema.json b/themes/schema.json index 9bf90f8a92c2..06a09ca10d78 100644 --- a/themes/schema.json +++ b/themes/schema.json @@ -277,7 +277,13 @@ }, "charged_color": { "$ref": "#/definitions/color" }, "charging_color": { "$ref": "#/definitions/color" }, - "discharging_color": { "$ref": "#/definitions/color" } + "discharging_color": { "$ref": "#/definitions/color" }, + "display_charging": { + "type": "boolean", + "title": "Display while charging", + "description": "displays the battery status while charging (Charging or Full)", + "default": true + } } } }