From b94e96dd153ac91f7de6bd54c07c523df95e4e37 Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Thu, 25 Nov 2021 13:55:03 +0100 Subject: [PATCH] refactor(battery): remove legacy properties --- docs/docs/config-colors.md | 7 +- docs/docs/segment-battery.md | 30 +++-- src/segment_battery.go | 36 +---- src/segment_battery_test.go | 132 ------------------ src/segment_deprecated.go | 82 +++++++++-- src/segment_deprecated_test.go | 135 +++++++++++++++++++ src/segment_git.go | 8 +- src/testdata/jandedobbeleer-palette.omp.json | 90 ++++++------- src/testdata/jandedobbeleer.omp.json | 10 +- themes/atomic.omp.json | 10 +- themes/atomicBit.omp.json | 10 +- themes/blueish.omp.json | 10 +- themes/bubbles.omp.json | 13 +- themes/bubblesline.omp.json | 13 +- themes/huvix.omp.json | 13 +- themes/iterm2.omp.json | 10 +- themes/jandedobbeleer.omp.json | 10 +- themes/mojada.omp.json | 10 +- themes/negligible.omp.json | 8 +- themes/schema.json | 27 ---- 20 files changed, 340 insertions(+), 324 deletions(-) diff --git a/docs/docs/config-colors.md b/docs/docs/config-colors.md index aa96534a..a6866efb 100644 --- a/docs/docs/config-colors.md +++ b/docs/docs/config-colors.md @@ -128,14 +128,9 @@ _Color override_ ([Battery segment][battery]): "foreground": "p:white", "background": "p:black", "properties": { - "battery_icon": "<#ffa500> [II ]- ", // icon should always be orange - "discharging_icon": "- ", + "discharging_icon": "<#ffa500>- ", "charging_icon": "+ ", "charged_icon": "* ", - "color_background": true, - "charged_color": "#4caf50", // - "charging_color": "#40c4ff", // battery should use specific colors for status - "discharging_color": "#ff5722", // } }, ``` diff --git a/docs/docs/segment-battery.md b/docs/docs/segment-battery.md index f8b6f179..b16541eb 100644 --- a/docs/docs/segment-battery.md +++ b/docs/docs/segment-battery.md @@ -17,18 +17,17 @@ Battery displays the remaining power percentage for your battery. "powerline_symbol": "\uE0B0", "foreground": "#193549", "background": "#ffeb3b", + "background_templates": [ + "{{if eq \"Charging\" .State.String}}#40c4ff{{end}}", + "{{if eq \"Discharging\" .State.String}}#ff5722{{end}}", + "{{if eq \"Full\" .State.String}}#4caf50{{end}}" + ], "properties": { - "battery_icon": "", "discharging_icon": "\uE231 ", "charging_icon": "\uE234 ", "charged_icon": "\uE22F ", - "color_background": true, - "charged_color": "#4caf50", - "charging_color": "#40c4ff", - "discharging_color": "#ff5722", "postfix": "\uF295 ", - "display_charging": true, - "display_charged": true + "template": "{{ if not .Error }}{{.Icon}}{{.Percentage}}{{ end }}" } } ``` @@ -41,16 +40,19 @@ properties below - defaults to `{{.Icon}}{{ if not .Error }}{{.Percentage}}{{ en - 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 -- color_background: `boolean` - color the background or foreground for properties below - defaults to `false` -- 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) -- display_charged: `bool` - displays the battery status when charged (Full) ## Template Properties -- `.Battery`: `struct` - the [battery][battery] object, you can use any property it has e.g. `.Battery.State` +- `.State`: `struct` - the battery state, has a `.String` function +- `.Current`: `float64` - Current (momentary) charge rate (in mW). +- `.Full`: `float64` - Last known full capacity (in mWh) +- `.Design`: `float64` - Reported design capacity (in mWh) +- `.ChargeRate`: `float64` - Current (momentary) charge rate (in mW). It is always non-negative, consult .State +field to check whether it means charging or discharging +- `.Voltage`: `float64` - Current voltage (in V) +- `.DesignVoltage`: `float64` - Design voltage (in V). Some systems (e.g. macOS) do not provide a separate +value for this. In such cases, or if getting this fails, but getting `Voltage` succeeds, this field will have +the same value as `Voltage`, for convenience - `.Percentage`: `float64` - the current battery percentage - `.Error`: `string` - the error in case fetching the battery information failed - `.Icon`: `string` - the icon based on the battery state diff --git a/src/segment_battery.go b/src/segment_battery.go index 5e523c57..712de9b7 100644 --- a/src/segment_battery.go +++ b/src/segment_battery.go @@ -23,16 +23,6 @@ const ( DischargingIcon Property = "discharging_icon" // ChargedIcon to display when fully charged ChargedIcon Property = "charged_icon" - // ChargedColor to display when fully charged - ChargedColor Property = "charged_color" - // ChargingColor to display when charging - 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" - // DisplayCharged Hide the battery icon when it's charged - DisplayCharged Property = "display_charged" ) func (b *batt) enabled() bool { @@ -52,38 +42,24 @@ func (b *batt) enabled() bool { b.Battery.Full += bt.Full b.Battery.State = b.mapMostLogicalState(b.Battery.State, bt.State) } - - 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 - } - batteryPercentage := b.Battery.Current / b.Battery.Full * 100 b.Percentage = int(math.Min(100, batteryPercentage)) - var colorPorperty Property + + if !b.shouldDisplay() { + return false + } + switch b.Battery.State { case battery.Discharging, battery.NotCharging: - colorPorperty = DischargingColor b.Icon = b.props.getString(DischargingIcon, "") case battery.Charging: - colorPorperty = ChargingColor b.Icon = b.props.getString(ChargingIcon, "") case battery.Full: - colorPorperty = ChargedColor b.Icon = b.props.getString(ChargedIcon, "") case battery.Empty, battery.Unknown: return true } - colorBackground := b.props.getBool(ColorBackground, false) - if colorBackground { - b.props.background = b.props.getColor(colorPorperty, b.props.background) - } else { - b.props.foreground = b.props.getColor(colorPorperty, b.props.foreground) - } + b.colorSegment() return true } diff --git a/src/segment_battery_test.go b/src/segment_battery_test.go index 0c350708..35c14db7 100644 --- a/src/segment_battery_test.go +++ b/src/segment_battery_test.go @@ -1,7 +1,6 @@ package main import ( - "errors" "testing" "github.com/distatus/battery" @@ -14,137 +13,6 @@ const ( chargedColor = "#248644" ) -func TestBatterySegmentSingle(t *testing.T) { - cases := []struct { - Case string - Batteries []*battery.Battery - ExpectedString string - ExpectedEnabled bool - ExpectedColor string - ColorBackground bool - 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}, - {Case: "70% discharging", Batteries: []*battery.Battery{{Full: 100, State: battery.Discharging, Current: 70}}, ExpectedString: "going down 70", ExpectedEnabled: true}, - { - Case: "discharging background color", - Batteries: []*battery.Battery{{Full: 100, State: battery.Discharging, Current: 70}}, - ExpectedString: "going down 70", - ExpectedEnabled: true, - ColorBackground: true, - ExpectedColor: dischargingColor, - }, - { - Case: "charging background color", - Batteries: []*battery.Battery{{Full: 100, State: battery.Charging, Current: 70}}, - ExpectedString: "charging 70", - ExpectedEnabled: true, - ColorBackground: true, - ExpectedColor: chargingColor, - }, - { - Case: "charged background color", - Batteries: []*battery.Battery{{Full: 100, State: battery.Full, Current: 70}}, - ExpectedString: "charged 70", - ExpectedEnabled: true, - ColorBackground: true, - ExpectedColor: chargedColor, - }, - { - Case: "discharging foreground color", - Batteries: []*battery.Battery{{Full: 100, State: battery.Discharging, Current: 70}}, - ExpectedString: "going down 70", - ExpectedEnabled: true, - ExpectedColor: dischargingColor, - }, - { - Case: "charging foreground color", - Batteries: []*battery.Battery{{Full: 100, State: battery.Charging, Current: 70}}, - ExpectedString: "charging 70", - ExpectedEnabled: true, - ExpectedColor: chargingColor, - }, - { - Case: "charged foreground color", - Batteries: []*battery.Battery{{Full: 100, State: battery.Full, Current: 70}}, - ExpectedString: "charged 70", - ExpectedEnabled: true, - ExpectedColor: chargedColor, - }, - {Case: "battery error", DisplayError: true, Error: errors.New("oh snap"), ExpectedString: "oh snap", ExpectedEnabled: true}, - {Case: "battery error disabled", Error: errors.New("oh snap")}, - {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 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}}, - ExpectedString: "going down 70", - ExpectedEnabled: true, - DisableCharging: true, - }, - } - - for _, tc := range cases { - env := &MockedEnvironment{} - props := &properties{ - background: "#111111", - foreground: "#ffffff", - values: map[Property]interface{}{ - ChargingIcon: "charging ", - ChargedIcon: "charged ", - DischargingIcon: "going down ", - DischargingColor: dischargingColor, - ChargedColor: chargedColor, - ChargingColor: chargingColor, - ColorBackground: tc.ColorBackground, - 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, - env: env, - } - enabled := b.enabled() - assert.Equal(t, tc.ExpectedEnabled, enabled, tc.Case) - if !enabled { - continue - } - assert.Equal(t, tc.ExpectedString, b.string(), tc.Case) - if len(tc.ExpectedColor) == 0 { - continue - } - actualColor := b.props.foreground - if tc.ColorBackground { - actualColor = b.props.background - } - assert.Equal(t, tc.ExpectedColor, actualColor, tc.Case) - } -} - func TestGetBatteryColors(t *testing.T) { cases := []struct { Case string diff --git a/src/segment_deprecated.go b/src/segment_deprecated.go index d2213d0c..641dae74 100644 --- a/src/segment_deprecated.go +++ b/src/segment_deprecated.go @@ -4,8 +4,29 @@ import ( "bytes" "fmt" "strings" + + "github.com/distatus/battery" ) +// Properties + +func (p *properties) getOneOfBool(property, legacyProperty Property) bool { + _, found := p.values[legacyProperty] + if found { + return p.getBool(legacyProperty, false) + } + return p.getBool(property, false) +} + +func (p *properties) hasOneOf(properties ...Property) bool { + for _, property := range properties { + if _, found := p.values[property]; found { + return true + } + } + return false +} + // GIT Segement const ( @@ -45,14 +66,6 @@ const ( StatusSeparatorIcon Property = "status_separator_icon" ) -func (g *git) getBool(property, legacyProperty Property) bool { - _, found := g.props.values[legacyProperty] - if found { - return g.props.getBool(legacyProperty, false) - } - return g.props.getBool(property, false) -} - func (g *git) deprecatedString(statusColorsEnabled bool) string { if statusColorsEnabled { g.SetStatusColor() @@ -166,3 +179,56 @@ func (e *exit) deprecatedString() string { } return fmt.Sprintf("%s%s", errorIcon, e.Text) } + +// Battery segment + +const ( + // ChargedColor to display when fully charged + ChargedColor Property = "charged_color" + // ChargingColor to display when charging + 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" + // DisplayCharged Hide the battery icon when it's charged + DisplayCharged Property = "display_charged" +) + +func (b *batt) colorSegment() { + if !b.props.hasOneOf(ChargedColor, ChargingColor, DischargingColor) { + return + } + var colorProperty Property + switch b.Battery.State { + case battery.Discharging, battery.NotCharging: + colorProperty = DischargingColor + case battery.Charging: + colorProperty = ChargingColor + case battery.Full: + colorProperty = ChargedColor + case battery.Empty, battery.Unknown: + return + } + colorBackground := b.props.getBool(ColorBackground, false) + if colorBackground { + b.props.background = b.props.getColor(colorProperty, b.props.background) + } else { + b.props.foreground = b.props.getColor(colorProperty, b.props.foreground) + } +} + +func (b *batt) shouldDisplay() bool { + if !b.props.hasOneOf(DisplayCharged, DisplayCharging) { + return true + } + 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 + } + return true +} diff --git a/src/segment_deprecated_test.go b/src/segment_deprecated_test.go index eb9af49b..edc5375b 100644 --- a/src/segment_deprecated_test.go +++ b/src/segment_deprecated_test.go @@ -1,8 +1,10 @@ package main import ( + "errors" "testing" + "github.com/distatus/battery" "github.com/stretchr/testify/assert" ) @@ -301,3 +303,136 @@ func TestExitWriterDeprecatedString(t *testing.T) { assert.Equal(t, tc.Expected, e.string()) } } + +// Battery Segment + +func TestBatterySegmentSingle(t *testing.T) { + cases := []struct { + Case string + Batteries []*battery.Battery + ExpectedString string + ExpectedEnabled bool + ExpectedColor string + ColorBackground bool + 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}, + {Case: "70% discharging", Batteries: []*battery.Battery{{Full: 100, State: battery.Discharging, Current: 70}}, ExpectedString: "going down 70", ExpectedEnabled: true}, + { + Case: "discharging background color", + Batteries: []*battery.Battery{{Full: 100, State: battery.Discharging, Current: 70}}, + ExpectedString: "going down 70", + ExpectedEnabled: true, + ColorBackground: true, + ExpectedColor: dischargingColor, + }, + { + Case: "charging background color", + Batteries: []*battery.Battery{{Full: 100, State: battery.Charging, Current: 70}}, + ExpectedString: "charging 70", + ExpectedEnabled: true, + ColorBackground: true, + ExpectedColor: chargingColor, + }, + { + Case: "charged background color", + Batteries: []*battery.Battery{{Full: 100, State: battery.Full, Current: 70}}, + ExpectedString: "charged 70", + ExpectedEnabled: true, + ColorBackground: true, + ExpectedColor: chargedColor, + }, + { + Case: "discharging foreground color", + Batteries: []*battery.Battery{{Full: 100, State: battery.Discharging, Current: 70}}, + ExpectedString: "going down 70", + ExpectedEnabled: true, + ExpectedColor: dischargingColor, + }, + { + Case: "charging foreground color", + Batteries: []*battery.Battery{{Full: 100, State: battery.Charging, Current: 70}}, + ExpectedString: "charging 70", + ExpectedEnabled: true, + ExpectedColor: chargingColor, + }, + { + Case: "charged foreground color", + Batteries: []*battery.Battery{{Full: 100, State: battery.Full, Current: 70}}, + ExpectedString: "charged 70", + ExpectedEnabled: true, + ExpectedColor: chargedColor, + }, + {Case: "battery error", DisplayError: true, Error: errors.New("oh snap"), ExpectedString: "oh snap", ExpectedEnabled: true}, + {Case: "battery error disabled", Error: errors.New("oh snap")}, + {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 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}}, + ExpectedString: "going down 70", + ExpectedEnabled: true, + DisableCharging: true, + }, + } + + for _, tc := range cases { + env := &MockedEnvironment{} + props := &properties{ + background: "#111111", + foreground: "#ffffff", + values: map[Property]interface{}{ + ChargingIcon: "charging ", + ChargedIcon: "charged ", + DischargingIcon: "going down ", + DischargingColor: dischargingColor, + ChargedColor: chargedColor, + ChargingColor: chargingColor, + ColorBackground: tc.ColorBackground, + 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, + env: env, + } + enabled := b.enabled() + assert.Equal(t, tc.ExpectedEnabled, enabled, tc.Case) + if !enabled { + continue + } + assert.Equal(t, tc.ExpectedString, b.string(), tc.Case) + if len(tc.ExpectedColor) == 0 { + continue + } + actualColor := b.props.foreground + if tc.ColorBackground { + actualColor = b.props.background + } + assert.Equal(t, tc.ExpectedColor, actualColor, tc.Case) + } +} diff --git a/src/segment_git.go b/src/segment_git.go index 7fc6d460..f72ca35e 100644 --- a/src/segment_git.go +++ b/src/segment_git.go @@ -185,20 +185,20 @@ func (g *git) shouldIgnoreRootRepository(rootDir string) bool { func (g *git) string() string { statusColorsEnabled := g.props.getBool(StatusColorsEnabled, false) - displayStatus := g.getBool(FetchStatus, DisplayStatus) + displayStatus := g.props.getOneOfBool(FetchStatus, DisplayStatus) if !displayStatus { g.HEAD = g.getPrettyHEADName() } if displayStatus || statusColorsEnabled { g.setGitStatus() } - if g.Upstream != "" && g.getBool(FetchUpstreamIcon, DisplayUpstreamIcon) { + if g.Upstream != "" && g.props.getOneOfBool(FetchUpstreamIcon, DisplayUpstreamIcon) { g.UpstreamIcon = g.getUpstreamIcon() } - if g.getBool(FetchStashCount, DisplayStashCount) { + if g.props.getOneOfBool(FetchStashCount, DisplayStashCount) { g.StashCount = g.getStashContext() } - if g.getBool(FetchWorktreeCount, DisplayWorktreeCount) { + if g.props.getOneOfBool(FetchWorktreeCount, DisplayWorktreeCount) { g.WorktreeCount = g.getWorktreeContext() } // use template if available diff --git a/src/testdata/jandedobbeleer-palette.omp.json b/src/testdata/jandedobbeleer-palette.omp.json index 3c8bf8cd..61252309 100644 --- a/src/testdata/jandedobbeleer-palette.omp.json +++ b/src/testdata/jandedobbeleer-palette.omp.json @@ -38,8 +38,8 @@ { "type": "session", "style": "diamond", - "foreground": "palette:white", - "background": "palette:session", + "foreground": "p:white", + "background": "p:session", "leading_diamond": "", "trailing_diamond": "\uE0B0", "properties": { @@ -51,8 +51,8 @@ "type": "path", "style": "powerline", "powerline_symbol": "\uE0B0", - "foreground": "palette:white", - "background": "palette:path", + "foreground": "p:white", + "background": "p:path", "properties": { "prefix": "  ", "home_icon": "~", @@ -64,13 +64,13 @@ "type": "git", "style": "powerline", "powerline_symbol": "\uE0B0", - "foreground": "palette:git-foreground", - "background": "palette:git", + "foreground": "p:git-foreground", + "background": "p:git", "background_templates": [ - "{{ if or (.Working.Changed) (.Staging.Changed) }}palette:git-modified{{ end }}", - "{{ if and (gt .Ahead 0) (gt .Behind 0) }}palette:git-diverged{{ end }}", - "{{ if gt .Ahead 0 }}palette:git-ahead{{ end }}", - "{{ if gt .Behind 0 }}palette:git-behind{{ end }}" + "{{ if or (.Working.Changed) (.Staging.Changed) }}p:git-modified{{ end }}", + "{{ if and (gt .Ahead 0) (gt .Behind 0) }}p:git-diverged{{ end }}", + "{{ if gt .Ahead 0 }}p:git-ahead{{ end }}", + "{{ if gt .Behind 0 }}p:git-behind{{ end }}" ], "leading_diamond": "", "trailing_diamond": "", @@ -86,8 +86,8 @@ "type": "node", "style": "powerline", "powerline_symbol": "\uE0B0", - "foreground": "palette:white", - "background": "palette:node", + "foreground": "p:white", + "background": "p:node", "properties": { "prefix": " \uF898 ", "display_version": true @@ -97,8 +97,8 @@ "type": "go", "style": "powerline", "powerline_symbol": "\uE0B0", - "foreground": "palette:black", - "background": "palette:go", + "foreground": "p:black", + "background": "p:go", "properties": { "prefix": " \uE626 ", "display_version": true @@ -108,8 +108,8 @@ "type": "julia", "style": "powerline", "powerline_symbol": "\uE0B0", - "foreground": "palette:black", - "background": "palette:julia", + "foreground": "p:black", + "background": "p:julia", "properties": { "prefix": " \uE624 ", "display_version": true @@ -119,8 +119,8 @@ "type": "python", "style": "powerline", "powerline_symbol": "\uE0B0", - "foreground": "palette:black", - "background": "palette:python", + "foreground": "p:black", + "background": "p:python", "properties": { "prefix": " \uE235 ", "display_version": true, @@ -132,8 +132,8 @@ "type": "ruby", "style": "powerline", "powerline_symbol": "\uE0B0", - "foreground": "palette:white", - "background": "palette:ruby", + "foreground": "p:white", + "background": "p:ruby", "properties": { "prefix": " \uE791 ", "display_version": true, @@ -144,8 +144,8 @@ "type": "azfunc", "style": "powerline", "powerline_symbol": "\uE0B0", - "foreground": "palette:white", - "background": "palette:azfunc", + "foreground": "p:white", + "background": "p:azfunc", "properties": { "prefix": " \uf0e7", "display_version": false, @@ -156,10 +156,10 @@ "type": "aws", "style": "powerline", "powerline_symbol": "\uE0B0", - "foreground": "palette:white", + "foreground": "p:white", "background_templates": [ - "{{if contains \"default\" .Profile}}palette:aws-default{{end}}", - "{{if contains \"jan\" .Profile}}palette:aws-jan{{end}}" + "{{if contains \"default\" .Profile}}p:aws-default{{end}}", + "{{if contains \"jan\" .Profile}}p:aws-jan{{end}}" ], "properties": { "prefix": " \uE7AD ", @@ -170,8 +170,8 @@ "type": "root", "style": "powerline", "powerline_symbol": "\uE0B0", - "foreground": "palette:black", - "background": "palette:root", + "foreground": "p:black", + "background": "p:root", "properties": { "root_icon": "" } @@ -179,8 +179,8 @@ { "type": "executiontime", "style": "plain", - "foreground": "palette:white", - "background": "palette:executiontime", + "foreground": "p:white", + "background": "p:executiontime", "leading_diamond": "", "trailing_diamond": "", "properties": { @@ -192,10 +192,10 @@ { "type": "exit", "style": "diamond", - "foreground": "palette:white", - "background": "palette:exit", + "foreground": "p:white", + "background": "p:exit", "background_templates": [ - "{{ if gt .Code 0 }}palette:exit-red{{ end }}" + "{{ if gt .Code 0 }}p:exit-red{{ end }}" ], "leading_diamond": "", "trailing_diamond": "\uE0B4", @@ -213,8 +213,8 @@ { "type": "shell", "style": "plain", - "foreground": "palette:white", - "background": "palette:shell", + "foreground": "p:white", + "background": "p:shell", "properties": { "prefix": "<#0077c2,transparent>\uE0B6  ", "postfix": " \uE0B2" @@ -225,8 +225,8 @@ "style": "powerline", "powerline_symbol": "\uE0B2", "invert_powerline": true, - "foreground": "palette:black", - "background": "palette:ytm", + "foreground": "p:black", + "background": "p:ytm", "properties": { "prefix": " \uF167 ", "paused_icon": " ", @@ -238,17 +238,17 @@ "style": "powerline", "invert_powerline": true, "powerline_symbol": "\uE0B2", - "foreground": "palette:white", - "background": "palette:battery", + "foreground": "p:white", + "background": "p:battery", + "background_templates": [ + "{{if eq \"Charging\" .State.String}}p:battery-charging{{end}}", + "{{if eq \"Discharging\" .State.String}}p:battery-discharging{{end}}", + "{{if eq \"Full\" .State.String}}p:battery-charged{{end}}" + ], "properties": { - "battery_icon": "", "discharging_icon": " ", "charging_icon": " ", "charged_icon": " ", - "color_background": true, - "charged_color": "palette:battery-charged", - "charging_color": "palette:battery-charging", - "discharging_color": "palette:battery-discharging", "postfix": " " } }, @@ -258,8 +258,8 @@ "invert_powerline": true, "leading_diamond": "\uE0B2", "trailing_diamond": "\uE0B4", - "background": "palette:time", - "foreground": "palette:black" + "background": "p:time", + "foreground": "p:black" } ] } diff --git a/src/testdata/jandedobbeleer.omp.json b/src/testdata/jandedobbeleer.omp.json index 16b8988d..faf2700b 100644 --- a/src/testdata/jandedobbeleer.omp.json +++ b/src/testdata/jandedobbeleer.omp.json @@ -207,15 +207,15 @@ "powerline_symbol": "\uE0B2", "foreground": "#ffffff", "background": "#f36943", + "background_templates": [ + "{{if eq \"Charging\" .State.String}}#40c4ff{{end}}", + "{{if eq \"Discharging\" .State.String}}#ff5722{{end}}", + "{{if eq \"Full\" .State.String}}#4caf50{{end}}" + ], "properties": { - "battery_icon": "", "discharging_icon": " ", "charging_icon": " ", "charged_icon": " ", - "color_background": true, - "charged_color": "#4caf50", - "charging_color": "#40c4ff", - "discharging_color": "#ff5722", "postfix": " " } }, diff --git a/themes/atomic.omp.json b/themes/atomic.omp.json index e2b90d86..2ad9ab9f 100644 --- a/themes/atomic.omp.json +++ b/themes/atomic.omp.json @@ -266,15 +266,15 @@ "trailing_diamond": "", "foreground": "#262626", "background": "#f36943", + "background_templates": [ + "{{if eq \"Charging\" .State.String}}#b8e994{{end}}", + "{{if eq \"Discharging\" .State.String}}#fff34e{{end}}", + "{{if eq \"Full\" .State.String}}#33DD2D{{end}}" + ], "properties": { - "battery_icon": "", "discharging_icon": " ", "charging_icon": "\uf1e6 ", "charged_icon": "\uf58e ", - "color_background": true, - "charged_color": "#33DD2D", - "charging_color": "#b8e994", - "discharging_color": "#fff34e", "postfix": " <#262626>\uE0B2" } }, diff --git a/themes/atomicBit.omp.json b/themes/atomicBit.omp.json index 4647c2c4..dbf3c782 100644 --- a/themes/atomicBit.omp.json +++ b/themes/atomicBit.omp.json @@ -182,14 +182,16 @@ { "type": "battery", "style": "plain", + "foreground": "#ffffff", + "foreground_templates": [ + "{{if eq \"Charging\" .State.String}}#40c4ff{{end}}", + "{{if eq \"Discharging\" .State.String}}#FFFB38{{end}}", + "{{if eq \"Full\" .State.String}}#33DD2D{{end}}" + ], "properties": { "discharging_icon": " ", "charging_icon": "\uf1e6 ", "charged_icon": "\uf58e ", - "color_foreground": true, - "charged_color": "#33DD2D", - "charging_color": "#40c4ff", - "discharging_color": "#FFFB38", "prefix": "<#ffffff>[", "postfix": "%<#ffffff>]─" } diff --git a/themes/blueish.omp.json b/themes/blueish.omp.json index ff10404d..ebff24ae 100644 --- a/themes/blueish.omp.json +++ b/themes/blueish.omp.json @@ -30,12 +30,12 @@ "powerline_symbol": "\uE0B0", "foreground": "#193549", "background": "#a2beef", + "background_templates": [ + "{{if eq \"Charging\" .State.String}}#00D100{{end}}", + "{{if eq \"Discharging\" .State.String}}#FFCD58{{end}}", + "{{if eq \"Full\" .State.String}}#0476d0{{end}}" + ], "properties": { - "battery_icon": "\f583", - "color_background": true, - "charged_color": "#0476d0", - "charging_color": "#00D100", - "discharging_color": "#FFCD58", "postfix": "\uF295 \uf583 " } }, diff --git a/themes/bubbles.omp.json b/themes/bubbles.omp.json index 05d8e0f6..a4909205 100644 --- a/themes/bubbles.omp.json +++ b/themes/bubbles.omp.json @@ -130,18 +130,17 @@ "leading_diamond": " \uE0B6", "foreground": "#9B6BDF", "background": "#29315A", + "foreground_templates": [ + "{{if eq \"Charging\" .State.String}}#40c4ff{{end}}", + "{{if eq \"Discharging\" .State.String}}#ff5722{{end}}", + "{{if eq \"Full\" .State.String}}#4caf50{{end}}" + ], "properties": { - "battery_icon": "", "discharging_icon": "\u21E3 ", "charging_icon": "\u21E1 ", "charged_icon": "\u0095 ", - "color_background": false, - "charged_color": "#4caf50", - "charging_color": "#40c4ff", - "discharging_color": "#ff5722", "prefix": "", - "postfix": "", - "display_charging": true + "postfix": "" } } ] diff --git a/themes/bubblesline.omp.json b/themes/bubblesline.omp.json index 1ec5b97e..e9c74236 100644 --- a/themes/bubblesline.omp.json +++ b/themes/bubblesline.omp.json @@ -117,18 +117,17 @@ "leading_diamond": " \uE0B6", "foreground": "#9B6BDF", "background": "#424242", + "foreground_templates": [ + "{{if eq \"Charging\" .State.String}}#40c4ff{{end}}", + "{{if eq \"Discharging\" .State.String}}#ff5722{{end}}", + "{{if eq \"Full\" .State.String}}#4caf50{{end}}" + ], "properties": { - "battery_icon": "", "discharging_icon": "\u21E3 ", "charging_icon": "\u21E1 ", "charged_icon": "\u25CF ", - "color_background": false, - "charged_color": "#4caf50", - "charging_color": "#40c4ff", - "discharging_color": "#ff5722", "prefix": "", - "postfix": "", - "display_charging": true + "postfix": "" } } ] diff --git a/themes/huvix.omp.json b/themes/huvix.omp.json index a9ff94be..607fb7cd 100644 --- a/themes/huvix.omp.json +++ b/themes/huvix.omp.json @@ -76,18 +76,17 @@ "type": "battery", "style": "powerline", "foreground": "#193549", + "foreground_templates": [ + "{{if eq \"Charging\" .State.String}}#64B5F6{{end}}", + "{{if eq \"Discharging\" .State.String}}#E36464{{end}}", + "{{if eq \"Full\" .State.String}}#66BB6A{{end}}" + ], "properties": { - "battery_icon": "", "discharging_icon": "\uE231 ", "charging_icon": "\uE234 ", "charged_icon": "\uE22F ", - "color_background": false, - "charged_color": "#66BB6A", - "charging_color": "#64B5F6", - "discharging_color": "#E36464", "prefix": "\u005B", - "postfix": "\uF295\u005D", - "display_charging": true + "postfix": "\uF295\u005D" } } ] diff --git a/themes/iterm2.omp.json b/themes/iterm2.omp.json index 7c4d1580..3124efad 100644 --- a/themes/iterm2.omp.json +++ b/themes/iterm2.omp.json @@ -88,12 +88,12 @@ "powerline_symbol": "\uE0B2", "foreground": "#242424", "background": "#f36943", + "background_templates": [ + "{{if eq \"Charging\" .State.String}}#33DD2D{{end}}", + "{{if eq \"Discharging\" .State.String}}#FFCD58{{end}}", + "{{if eq \"Full\" .State.String}}#0476d0{{end}}" + ], "properties": { - "battery_icon": "\f583", - "color_background": true, - "charged_color": "#0476d0", - "charging_color": "#33DD2D", - "discharging_color": "#FFCD58", "postfix": "\uF295 \uf583 " } }, diff --git a/themes/jandedobbeleer.omp.json b/themes/jandedobbeleer.omp.json index 16b8988d..faf2700b 100644 --- a/themes/jandedobbeleer.omp.json +++ b/themes/jandedobbeleer.omp.json @@ -207,15 +207,15 @@ "powerline_symbol": "\uE0B2", "foreground": "#ffffff", "background": "#f36943", + "background_templates": [ + "{{if eq \"Charging\" .State.String}}#40c4ff{{end}}", + "{{if eq \"Discharging\" .State.String}}#ff5722{{end}}", + "{{if eq \"Full\" .State.String}}#4caf50{{end}}" + ], "properties": { - "battery_icon": "", "discharging_icon": " ", "charging_icon": " ", "charged_icon": " ", - "color_background": true, - "charged_color": "#4caf50", - "charging_color": "#40c4ff", - "discharging_color": "#ff5722", "postfix": " " } }, diff --git a/themes/mojada.omp.json b/themes/mojada.omp.json index 87bdf67d..a903bde1 100644 --- a/themes/mojada.omp.json +++ b/themes/mojada.omp.json @@ -123,15 +123,15 @@ "powerline_symbol": "\uE0B2", "foreground": "#ffffff", "background": "#f36943", + "background_templates": [ + "{{if eq \"Charging\" .State.String}}#40c4ff{{end}}", + "{{if eq \"Discharging\" .State.String}}#ff5722{{end}}", + "{{if eq \"Full\" .State.String}}#4caf50{{end}}" + ], "properties": { - "battery_icon": "", "discharging_icon": "\uF57D ", "charging_icon": "\uF588 ", "charged_icon": "\uF583 ", - "color_background": true, - "charged_color": "#4caf50", - "charging_color": "#40c4ff", - "discharging_color": "#ff5722", "postfix": "% " } }, diff --git a/themes/negligible.omp.json b/themes/negligible.omp.json index 93dfb12b..2db46427 100644 --- a/themes/negligible.omp.json +++ b/themes/negligible.omp.json @@ -78,12 +78,14 @@ "type": "battery", "style": "powerline", "invert_powerline": true, + "foreground_templates": [ + "{{if eq \"Charging\" .State.String}}#4caf50{{end}}", + "{{if eq \"Discharging\" .State.String}}#40c4ff{{end}}", + "{{if eq \"Full\" .State.String}}#ff0000{{end}}" + ], "properties": { "charging_icon": " ", "charged_icon": "\uf00d ", - "charged_color": "#ff0000", - "charging_color": "#4caf50", - "discharging_color": "#40c4ff", "prefix": "| ", "postfix": "  " } diff --git a/themes/schema.json b/themes/schema.json index 948afaac..0c4fd851 100644 --- a/themes/schema.json +++ b/themes/schema.json @@ -323,12 +323,6 @@ "properties": { "properties": { "properties": { - "battery_icon": { - "type": "string", - "title": "Battery Icon", - "description": "Text/icon to use as a prefix for the battery percentage", - "default": "" - }, "display_error": { "type": "boolean", "title": "Display Error", @@ -353,27 +347,6 @@ "description": "Text/icon to display on the left when fully charged", "default": "" }, - "color_background": { - "type": "boolean", - "title": "Color Background", - "description": "Color the background or foreground", - "default": false - }, - "charged_color": { "$ref": "#/definitions/color" }, - "charging_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)", - "default": true - }, - "display_charged": { - "type": "boolean", - "title": "Display when full", - "description": "displays the battery status when charged (Full)", - "default": true - }, "template": { "$ref": "#/definitions/template" }