diff --git a/docs/docs/contributing-segment.md b/docs/docs/contributing-segment.md index 695a66d4..fb020d2d 100644 --- a/docs/docs/contributing-segment.md +++ b/docs/docs/contributing-segment.md @@ -15,7 +15,7 @@ You can use the following template as a guide. package main type new struct { - props *properties + props properties env environmentInfo Text string @@ -48,7 +48,7 @@ func (n *new) string() string { return text } -func (n *new) init(props *properties, env environmentInfo) { +func (n *new) init(props properties, env environmentInfo) { n.props = props n.env = env } diff --git a/src/properties.go b/src/properties.go index a8baeead..e7bd2a0a 100644 --- a/src/properties.go +++ b/src/properties.go @@ -37,17 +37,10 @@ const ( DisplayDefault Property = "display_default" ) -type properties struct { - values map[Property]interface{} - foreground string - background string -} +type properties map[Property]interface{} -func (p *properties) getString(property Property, defaultValue string) string { - if p == nil || p.values == nil { - return defaultValue - } - val, found := p.values[property] +func (p properties) getString(property Property, defaultValue string) string { + val, found := p[property] if !found { return defaultValue } @@ -62,11 +55,8 @@ func parseString(value interface{}, defaultValue string) string { return stringValue } -func (p *properties) getColor(property Property, defaultValue string) string { - if p == nil || p.values == nil { - return defaultValue - } - val, found := p.values[property] +func (p properties) getColor(property Property, defaultValue string) string { + val, found := p[property] if !found { return defaultValue } @@ -81,11 +71,8 @@ func (p *properties) getColor(property Property, defaultValue string) string { return defaultValue } -func (p *properties) getBool(property Property, defaultValue bool) bool { - if p == nil || p.values == nil { - return defaultValue - } - val, found := p.values[property] +func (p properties) getBool(property Property, defaultValue bool) bool { + val, found := p[property] if !found { return defaultValue } @@ -96,11 +83,8 @@ func (p *properties) getBool(property Property, defaultValue bool) bool { return boolValue } -func (p *properties) getFloat64(property Property, defaultValue float64) float64 { - if p == nil || p.values == nil { - return defaultValue - } - val, found := p.values[property] +func (p properties) getFloat64(property Property, defaultValue float64) float64 { + val, found := p[property] if !found { return defaultValue } @@ -113,11 +97,8 @@ func (p *properties) getFloat64(property Property, defaultValue float64) float64 return floatValue } -func (p *properties) getInt(property Property, defaultValue int) int { - if p == nil || p.values == nil { - return defaultValue - } - val, found := p.values[property] +func (p properties) getInt(property Property, defaultValue int) int { + val, found := p[property] if !found { return defaultValue } @@ -135,11 +116,8 @@ func (p *properties) getInt(property Property, defaultValue int) int { return int(intValue) } -func (p *properties) getKeyValueMap(property Property, defaultValue map[string]string) map[string]string { - if p == nil || p.values == nil { - return defaultValue - } - val, found := p.values[property] +func (p properties) getKeyValueMap(property Property, defaultValue map[string]string) map[string]string { + val, found := p[property] if !found { return defaultValue } diff --git a/src/properties_test.go b/src/properties_test.go index 9e58c800..3a71be12 100644 --- a/src/properties_test.go +++ b/src/properties_test.go @@ -12,146 +12,101 @@ const ( ) func TestGetString(t *testing.T) { - values := map[Property]interface{}{TextProperty: expected} - properties := properties{ - values: values, - } + var properties properties = map[Property]interface{}{TextProperty: expected} value := properties.getString(TextProperty, "err") assert.Equal(t, expected, value) } func TestGetStringNoEntry(t *testing.T) { - values := map[Property]interface{}{} - properties := properties{ - values: values, - } + var properties properties = map[Property]interface{}{} value := properties.getString(TextProperty, expected) assert.Equal(t, expected, value) } func TestGetStringNoTextEntry(t *testing.T) { - values := map[Property]interface{}{TextProperty: true} - properties := properties{ - values: values, - } + var properties properties = map[Property]interface{}{TextProperty: true} value := properties.getString(TextProperty, expected) assert.Equal(t, expected, value) } func TestGetHexColor(t *testing.T) { expected := expectedColor - values := map[Property]interface{}{UserColor: expected} - properties := properties{ - values: values, - } + var properties properties = map[Property]interface{}{UserColor: expected} value := properties.getColor(UserColor, "#789123") assert.Equal(t, expected, value) } func TestGetColor(t *testing.T) { expected := "yellow" - values := map[Property]interface{}{UserColor: expected} - properties := properties{ - values: values, - } + var properties properties = map[Property]interface{}{UserColor: expected} value := properties.getColor(UserColor, "#789123") assert.Equal(t, expected, value) } func TestDefaultColorWithInvalidColorCode(t *testing.T) { expected := expectedColor - values := map[Property]interface{}{UserColor: "invalid"} - properties := properties{ - values: values, - } + var properties properties = map[Property]interface{}{UserColor: "invalid"} value := properties.getColor(UserColor, expected) assert.Equal(t, expected, value) } func TestDefaultColorWithUnavailableProperty(t *testing.T) { expected := expectedColor - values := map[Property]interface{}{} - properties := properties{ - values: values, - } + var properties properties = map[Property]interface{}{} value := properties.getColor(UserColor, expected) assert.Equal(t, expected, value) } func TestGetPaletteColor(t *testing.T) { expected := "p:red" - values := map[Property]interface{}{Background: expected} - properties := properties{ - values: values, - } + var properties properties = map[Property]interface{}{Background: expected} value := properties.getColor(Background, "white") assert.Equal(t, expected, value) } func TestGetBool(t *testing.T) { expected := true - values := map[Property]interface{}{DisplayHost: expected} - properties := properties{ - values: values, - } + var properties properties = map[Property]interface{}{DisplayHost: expected} value := properties.getBool(DisplayHost, false) assert.True(t, value) } func TestGetBoolPropertyNotInMap(t *testing.T) { - values := map[Property]interface{}{} - properties := properties{ - values: values, - } + var properties properties = map[Property]interface{}{} value := properties.getBool(DisplayHost, false) assert.False(t, value) } func TestGetBoolInvalidProperty(t *testing.T) { - values := map[Property]interface{}{DisplayHost: "borked"} - properties := properties{ - values: values, - } + var properties properties = map[Property]interface{}{DisplayHost: "borked"} value := properties.getBool(DisplayHost, false) assert.False(t, value) } func TestGetFloat64(t *testing.T) { expected := float64(1337) - values := map[Property]interface{}{"myfloat": expected} - properties := properties{ - values: values, - } + var properties properties = map[Property]interface{}{"myfloat": expected} value := properties.getFloat64("myfloat", 9001) assert.Equal(t, expected, value) } func TestGetFloat64PropertyNotInMap(t *testing.T) { expected := float64(1337) - values := map[Property]interface{}{} - properties := properties{ - values: values, - } + var properties properties = map[Property]interface{}{} value := properties.getFloat64(ThresholdProperty, expected) assert.Equal(t, expected, value) } func TestGetFloat64InvalidStringProperty(t *testing.T) { expected := float64(1337) - values := map[Property]interface{}{ThresholdProperty: "invalid"} - properties := properties{ - values: values, - } + var properties properties = map[Property]interface{}{ThresholdProperty: "invalid"} value := properties.getFloat64(ThresholdProperty, expected) assert.Equal(t, expected, value) } func TestGetFloat64InvalidBoolProperty(t *testing.T) { expected := float64(1337) - values := map[Property]interface{}{ThresholdProperty: true} - properties := properties{ - values: values, - } + var properties properties = map[Property]interface{}{ThresholdProperty: true} value := properties.getFloat64(ThresholdProperty, expected) assert.Equal(t, expected, value) } diff --git a/src/segment.go b/src/segment.go index 667d26ca..c018d451 100644 --- a/src/segment.go +++ b/src/segment.go @@ -9,19 +9,18 @@ import ( // Segment represent a single segment and it's configuration type Segment struct { - Type SegmentType `config:"type"` - Tips []string `config:"tips"` - Style SegmentStyle `config:"style"` - PowerlineSymbol string `config:"powerline_symbol"` - InvertPowerline bool `config:"invert_powerline"` - Foreground string `config:"foreground"` - ForegroundTemplates []string `config:"foreground_templates"` - Background string `config:"background"` - BackgroundTemplates []string `config:"background_templates"` - LeadingDiamond string `config:"leading_diamond"` - TrailingDiamond string `config:"trailing_diamond"` - Properties map[Property]interface{} `config:"properties"` - props *properties + Type SegmentType `config:"type"` + Tips []string `config:"tips"` + Style SegmentStyle `config:"style"` + PowerlineSymbol string `config:"powerline_symbol"` + InvertPowerline bool `config:"invert_powerline"` + Foreground string `config:"foreground"` + ForegroundTemplates []string `config:"foreground_templates"` + Background string `config:"background"` + BackgroundTemplates []string `config:"background_templates"` + LeadingDiamond string `config:"leading_diamond"` + TrailingDiamond string `config:"trailing_diamond"` + Properties properties `config:"properties"` writer SegmentWriter stringValue string active bool @@ -42,7 +41,7 @@ type SegmentTiming struct { type SegmentWriter interface { enabled() bool string() string - init(props *properties, env environmentInfo) + init(props properties, env environmentInfo) } // SegmentStyle the syle of segment, for more information, see the constants @@ -215,18 +214,12 @@ func (segment *Segment) shouldInvokeWithTip(tip string) bool { } func (segment *Segment) foreground() string { - color := segment.Foreground - if segment.props != nil { - color = segment.props.foreground - } + color := segment.Properties.getColor(ForegroundOverride, segment.Foreground) return segment.getColor(segment.ForegroundTemplates, color) } func (segment *Segment) background() string { - color := segment.Background - if segment.props != nil { - color = segment.props.background - } + color := segment.Properties.getColor(BackgroundOverride, segment.Background) return segment.getColor(segment.BackgroundTemplates, color) } @@ -274,14 +267,8 @@ func (segment *Segment) mapSegmentWithWriter(env environmentInfo) error { WinReg: &winreg{}, } if writer, ok := functions[segment.Type]; ok { - props := &properties{ - values: segment.Properties, - foreground: segment.Foreground, - background: segment.Background, - } - writer.init(props, env) + writer.init(segment.Properties, env) segment.writer = writer - segment.props = props return nil } return errors.New("unable to map writer") diff --git a/src/segment_angular.go b/src/segment_angular.go index fd242ce8..1723a15b 100644 --- a/src/segment_angular.go +++ b/src/segment_angular.go @@ -8,7 +8,7 @@ func (a *angular) string() string { return a.language.string() } -func (a *angular) init(props *properties, env environmentInfo) { +func (a *angular) init(props properties, env environmentInfo) { a.language = &language{ env: env, props: props, diff --git a/src/segment_aws.go b/src/segment_aws.go index adbc5583..0290c37c 100644 --- a/src/segment_aws.go +++ b/src/segment_aws.go @@ -6,7 +6,7 @@ import ( ) type aws struct { - props *properties + props properties env environmentInfo Profile string Region string @@ -16,7 +16,7 @@ const ( defaultUser = "default" ) -func (a *aws) init(props *properties, env environmentInfo) { +func (a *aws) init(props properties, env environmentInfo) { a.props = props a.env = env } diff --git a/src/segment_aws_test.go b/src/segment_aws_test.go index ddd4d684..48950b8c 100644 --- a/src/segment_aws_test.go +++ b/src/segment_aws_test.go @@ -54,13 +54,11 @@ func TestAWSSegment(t *testing.T) { env.On("getenv", "AWS_CONFIG_FILE").Return(tc.ConfigFile) env.On("getFileContent", "/usr/home/.aws/config").Return("") env.On("homeDir", nil).Return("/usr/home") - props := &properties{ - values: map[Property]interface{}{ - DisplayDefault: tc.DisplayDefault, - }, + var props properties = map[Property]interface{}{ + DisplayDefault: tc.DisplayDefault, } if tc.Template != "" { - props.values[SegmentTemplate] = tc.Template + props[SegmentTemplate] = tc.Template } aws := &aws{ diff --git a/src/segment_az.go b/src/segment_az.go index 6e83ee99..7f1cfa3c 100644 --- a/src/segment_az.go +++ b/src/segment_az.go @@ -6,7 +6,7 @@ import ( ) type az struct { - props *properties + props properties env environmentInfo EnvironmentName string `json:"environmentName"` @@ -47,7 +47,7 @@ func (a *az) string() string { return text } -func (a *az) init(props *properties, env environmentInfo) { +func (a *az) init(props properties, env environmentInfo) { a.props = props a.env = env } @@ -92,8 +92,8 @@ func (a *az) getFromAzCli() bool { } if strings.Contains(output, updateConsentNeeded) { - a.props.foreground = updateForeground - a.props.background = updateBackground + a.props[ForegroundOverride] = updateForeground + a.props[BackgroundOverride] = updateBackground a.Name = updateMessage return true } diff --git a/src/segment_az_functions.go b/src/segment_az_functions.go index 8f2cf755..c6143cc9 100644 --- a/src/segment_az_functions.go +++ b/src/segment_az_functions.go @@ -8,7 +8,7 @@ func (az *azfunc) string() string { return az.language.string() } -func (az *azfunc) init(props *properties, env environmentInfo) { +func (az *azfunc) init(props properties, env environmentInfo) { az.language = &language{ env: env, props: props, diff --git a/src/segment_az_test.go b/src/segment_az_test.go index d4fec26b..311d653d 100644 --- a/src/segment_az_test.go +++ b/src/segment_az_test.go @@ -140,10 +140,8 @@ func TestAzSegment(t *testing.T) { }`, tc.CLIEnvironmentname, tc.CLISubscriptionID, tc.CLIAccountName, tc.CLIUserName), nil, ) - props := &properties{ - values: map[Property]interface{}{ - SegmentTemplate: tc.Template, - }, + var props properties = map[Property]interface{}{ + SegmentTemplate: tc.Template, } az := &az{ diff --git a/src/segment_battery.go b/src/segment_battery.go index 712de9b7..8449c616 100644 --- a/src/segment_battery.go +++ b/src/segment_battery.go @@ -7,7 +7,7 @@ import ( ) type batt struct { - props *properties + props properties env environmentInfo battery.Battery @@ -118,7 +118,7 @@ func (b *batt) string() string { return text } -func (b *batt) init(props *properties, env environmentInfo) { +func (b *batt) init(props properties, env environmentInfo) { b.props = props b.env = env } diff --git a/src/segment_command.go b/src/segment_command.go index bbc26ac0..261638de 100644 --- a/src/segment_command.go +++ b/src/segment_command.go @@ -3,7 +3,7 @@ package main import "strings" type command struct { - props *properties + props properties env environmentInfo value string } @@ -48,7 +48,7 @@ func (c *command) string() string { return c.value } -func (c *command) init(props *properties, env environmentInfo) { +func (c *command) init(props properties, env environmentInfo) { c.props = props c.env = env } diff --git a/src/segment_command_test.go b/src/segment_command_test.go index b9b4c44f..952ac783 100644 --- a/src/segment_command_test.go +++ b/src/segment_command_test.go @@ -14,10 +14,8 @@ func TestExecuteCommand(t *testing.T) { env.init(&args{ Debug: &debug, }) - props := &properties{ - values: map[Property]interface{}{ - Command: "echo hello", - }, + var props properties = map[Property]interface{}{ + Command: "echo hello", } c := &command{ props: props, @@ -34,10 +32,8 @@ func TestExecuteMultipleCommandsOrFirst(t *testing.T) { env.init(&args{ Debug: &debug, }) - props := &properties{ - values: map[Property]interface{}{ - Command: "exit 1 || echo hello", - }, + var props properties = map[Property]interface{}{ + Command: "exit 1 || echo hello", } c := &command{ props: props, @@ -54,10 +50,8 @@ func TestExecuteMultipleCommandsOrSecond(t *testing.T) { env.init(&args{ Debug: &debug, }) - props := &properties{ - values: map[Property]interface{}{ - Command: "echo hello || echo world", - }, + var props properties = map[Property]interface{}{ + Command: "echo hello || echo world", } c := &command{ props: props, @@ -74,10 +68,8 @@ func TestExecuteMultipleCommandsAnd(t *testing.T) { env.init(&args{ Debug: &debug, }) - props := &properties{ - values: map[Property]interface{}{ - Command: "echo hello && echo world", - }, + var props properties = map[Property]interface{}{ + Command: "echo hello && echo world", } c := &command{ props: props, @@ -94,10 +86,8 @@ func TestExecuteSingleCommandEmpty(t *testing.T) { env.init(&args{ Debug: &debug, }) - props := &properties{ - values: map[Property]interface{}{ - Command: "", - }, + var props properties = map[Property]interface{}{ + Command: "", } c := &command{ props: props, @@ -113,7 +103,7 @@ func TestExecuteSingleCommandNoCommandProperty(t *testing.T) { env.init(&args{ Debug: &debug, }) - props := &properties{} + var props properties c := &command{ props: props, env: env, @@ -129,10 +119,8 @@ func TestExecuteMultipleCommandsAndDisabled(t *testing.T) { env.init(&args{ Debug: &debug, }) - props := &properties{ - values: map[Property]interface{}{ - Command: "echo && echo", - }, + var props properties = map[Property]interface{}{ + Command: "echo && echo", } c := &command{ props: props, @@ -148,10 +136,8 @@ func TestExecuteMultipleCommandsOrDisabled(t *testing.T) { env.init(&args{ Debug: &debug, }) - props := &properties{ - values: map[Property]interface{}{ - Command: "echo|| echo", - }, + var props properties = map[Property]interface{}{ + Command: "echo|| echo", } c := &command{ props: props, diff --git a/src/segment_crystal.go b/src/segment_crystal.go index 3d08cc58..99a5ba0b 100644 --- a/src/segment_crystal.go +++ b/src/segment_crystal.go @@ -8,7 +8,7 @@ func (c *crystal) string() string { return c.language.string() } -func (c *crystal) init(props *properties, env environmentInfo) { +func (c *crystal) init(props properties, env environmentInfo) { c.language = &language{ env: env, props: props, diff --git a/src/segment_dart.go b/src/segment_dart.go index 80434c47..69683296 100644 --- a/src/segment_dart.go +++ b/src/segment_dart.go @@ -8,7 +8,7 @@ func (d *dart) string() string { return d.language.string() } -func (d *dart) init(props *properties, env environmentInfo) { +func (d *dart) init(props properties, env environmentInfo) { d.language = &language{ env: env, props: props, diff --git a/src/segment_deprecated.go b/src/segment_deprecated.go index 641dae74..334fdd08 100644 --- a/src/segment_deprecated.go +++ b/src/segment_deprecated.go @@ -8,19 +8,26 @@ import ( "github.com/distatus/battery" ) +// Segment + +const ( + BackgroundOverride Property = "background" + ForegroundOverride Property = "foreground" +) + // Properties -func (p *properties) getOneOfBool(property, legacyProperty Property) bool { - _, found := p.values[legacyProperty] +func (p properties) getOneOfBool(property, legacyProperty Property) bool { + _, found := p[legacyProperty] if found { return p.getBool(legacyProperty, false) } return p.getBool(property, false) } -func (p *properties) hasOneOf(properties ...Property) bool { +func (p properties) hasOneOf(properties ...Property) bool { for _, property := range properties { - if _, found := p.values[property]; found { + if _, found := p[property]; found { return true } } @@ -100,9 +107,9 @@ func (g *git) deprecatedString(statusColorsEnabled bool) string { func (g *git) SetStatusColor() { if g.props.getBool(ColorBackground, true) { - g.props.background = g.getStatusColor(g.props.background) + g.props[BackgroundOverride] = g.getStatusColor(g.props.getColor(BackgroundOverride, "")) } else { - g.props.foreground = g.getStatusColor(g.props.foreground) + g.props[ForegroundOverride] = g.getStatusColor(g.props.getColor(ForegroundOverride, "")) } } @@ -121,26 +128,25 @@ func (g *git) getStatusColor(defaultValue string) string { func (g *git) getStatusDetailString(status *GitStatus, color, icon Property, defaultIcon string) string { prefix := g.props.getString(icon, defaultIcon) - foregroundColor := g.props.getColor(color, g.props.foreground) - if !g.props.getBool(DisplayStatusDetail, true) { - return g.colorStatusString(prefix, "", foregroundColor) + foregroundColor := g.props.getColor(color, g.props.getColor(ForegroundOverride, "")) + detail := "" + if g.props.getBool(DisplayStatusDetail, true) { + detail = status.String() } - return g.colorStatusString(prefix, status.String(), foregroundColor) + statusStr := g.colorStatusString(prefix, detail, foregroundColor) + return strings.TrimSpace(statusStr) } func (g *git) colorStatusString(prefix, status, color string) string { - if color == g.props.foreground && len(status) == 0 { - return prefix - } - if color == g.props.foreground { + if len(color) == 0 { return fmt.Sprintf("%s %s", prefix, status) } - if strings.Contains(prefix, "") { - return fmt.Sprintf("%s <%s>%s", prefix, color, status) - } if len(status) == 0 { return fmt.Sprintf("<%s>%s", color, prefix) } + if strings.Contains(prefix, "") { + return fmt.Sprintf("%s <%s>%s", prefix, color, status) + } return fmt.Sprintf("<%s>%s %s", color, prefix, status) } @@ -162,10 +168,10 @@ const ( func (e *exit) deprecatedString() string { colorBackground := e.props.getBool(ColorBackground, false) if e.Code != 0 && !colorBackground { - e.props.foreground = e.props.getColor(ErrorColor, e.props.foreground) + e.props[ForegroundOverride] = e.props.getColor(ErrorColor, e.props.getColor(ForegroundOverride, "")) } if e.Code != 0 && colorBackground { - e.props.background = e.props.getColor(ErrorColor, e.props.background) + e.props[BackgroundOverride] = e.props.getColor(ErrorColor, e.props.getColor(BackgroundOverride, "")) } if e.Code == 0 { return e.props.getString(SuccessIcon, "") @@ -212,9 +218,9 @@ func (b *batt) colorSegment() { } colorBackground := b.props.getBool(ColorBackground, false) if colorBackground { - b.props.background = b.props.getColor(colorProperty, b.props.background) + b.props[BackgroundOverride] = b.props.getColor(colorProperty, b.props.getColor(BackgroundOverride, "")) } else { - b.props.foreground = b.props.getColor(colorProperty, b.props.foreground) + b.props[ForegroundOverride] = b.props.getColor(colorProperty, b.props.getColor(ForegroundOverride, "")) } } diff --git a/src/segment_deprecated_test.go b/src/segment_deprecated_test.go index edc5375b..7363c48e 100644 --- a/src/segment_deprecated_test.go +++ b/src/segment_deprecated_test.go @@ -16,11 +16,7 @@ func TestGetStatusDetailStringDefault(t *testing.T) { Changed: true, Added: 1, } - g := &git{ - props: &properties{ - foreground: "#111111", - }, - } + g := &git{} assert.Equal(t, expected, g.getStatusDetailString(status, WorkingColor, LocalWorkingIcon, "icon")) } @@ -30,13 +26,11 @@ func TestGetStatusDetailStringDefaultColorOverride(t *testing.T) { Changed: true, Added: 1, } + var props properties = map[Property]interface{}{ + WorkingColor: "#123456", + } g := &git{ - props: &properties{ - values: map[Property]interface{}{ - WorkingColor: "#123456", - }, - foreground: "#111111", - }, + props: props, } assert.Equal(t, expected, g.getStatusDetailString(status, WorkingColor, LocalWorkingIcon, "icon")) } @@ -47,14 +41,12 @@ func TestGetStatusDetailStringDefaultColorOverrideAndIconColorOverride(t *testin Changed: true, Added: 1, } + var props properties = map[Property]interface{}{ + WorkingColor: "#123456", + LocalWorkingIcon: "<#789123>work", + } g := &git{ - props: &properties{ - values: map[Property]interface{}{ - WorkingColor: "#123456", - LocalWorkingIcon: "<#789123>work", - }, - foreground: "#111111", - }, + props: props, } assert.Equal(t, expected, g.getStatusDetailString(status, WorkingColor, LocalWorkingIcon, "icon")) } @@ -65,14 +57,12 @@ func TestGetStatusDetailStringDefaultColorOverrideNoIconColorOverride(t *testing Changed: true, Added: 1, } + var props properties = map[Property]interface{}{ + WorkingColor: "#123456", + LocalWorkingIcon: "work", + } g := &git{ - props: &properties{ - values: map[Property]interface{}{ - WorkingColor: "#123456", - LocalWorkingIcon: "work", - }, - foreground: "#111111", - }, + props: props, } assert.Equal(t, expected, g.getStatusDetailString(status, WorkingColor, LocalWorkingIcon, "icon")) } @@ -83,13 +73,11 @@ func TestGetStatusDetailStringNoStatus(t *testing.T) { Changed: true, Added: 1, } + var props properties = map[Property]interface{}{ + DisplayStatusDetail: false, + } g := &git{ - props: &properties{ - values: map[Property]interface{}{ - DisplayStatusDetail: false, - }, - foreground: "#111111", - }, + props: props, } assert.Equal(t, expected, g.getStatusDetailString(status, WorkingColor, LocalWorkingIcon, "icon")) } @@ -100,26 +88,23 @@ func TestGetStatusDetailStringNoStatusColorOverride(t *testing.T) { Changed: true, Added: 1, } + var props properties = map[Property]interface{}{ + DisplayStatusDetail: false, + WorkingColor: "#123456", + } g := &git{ - props: &properties{ - values: map[Property]interface{}{ - DisplayStatusDetail: false, - WorkingColor: "#123456", - }, - foreground: "#111111", - }, + props: props, } assert.Equal(t, expected, g.getStatusDetailString(status, WorkingColor, LocalWorkingIcon, "icon")) } func TestGetStatusColorLocalChangesStaging(t *testing.T) { expected := changesColor + var props properties = map[Property]interface{}{ + LocalChangesColor: expected, + } g := &git{ - props: &properties{ - values: map[Property]interface{}{ - LocalChangesColor: expected, - }, - }, + props: props, Staging: &GitStatus{ Changed: true, }, @@ -129,120 +114,109 @@ func TestGetStatusColorLocalChangesStaging(t *testing.T) { func TestGetStatusColorLocalChangesWorking(t *testing.T) { expected := changesColor + var props properties = map[Property]interface{}{ + LocalChangesColor: expected, + } g := &git{ + props: props, Staging: &GitStatus{}, Working: &GitStatus{ Changed: true, }, - props: &properties{ - values: map[Property]interface{}{ - LocalChangesColor: expected, - }, - }, } assert.Equal(t, expected, g.getStatusColor("#fg1111")) } func TestGetStatusColorAheadAndBehind(t *testing.T) { expected := changesColor + var props properties = map[Property]interface{}{ + AheadAndBehindColor: expected, + } g := &git{ + props: props, Staging: &GitStatus{}, Working: &GitStatus{}, Ahead: 1, Behind: 3, - props: &properties{ - values: map[Property]interface{}{ - AheadAndBehindColor: expected, - }, - }, } assert.Equal(t, expected, g.getStatusColor("#fg1111")) } func TestGetStatusColorAhead(t *testing.T) { expected := changesColor + var props properties = map[Property]interface{}{ + AheadColor: expected, + } g := &git{ + props: props, Staging: &GitStatus{}, Working: &GitStatus{}, Ahead: 1, Behind: 0, - props: &properties{ - values: map[Property]interface{}{ - AheadColor: expected, - }, - }, } assert.Equal(t, expected, g.getStatusColor("#fg1111")) } func TestGetStatusColorBehind(t *testing.T) { expected := changesColor + var props properties = map[Property]interface{}{ + BehindColor: expected, + } g := &git{ + props: props, Staging: &GitStatus{}, Working: &GitStatus{}, Ahead: 0, Behind: 5, - props: &properties{ - values: map[Property]interface{}{ - BehindColor: expected, - }, - }, } assert.Equal(t, expected, g.getStatusColor("#fg1111")) } func TestGetStatusColorDefault(t *testing.T) { expected := changesColor + var props properties = map[Property]interface{}{ + BehindColor: changesColor, + } g := &git{ + props: props, Staging: &GitStatus{}, Working: &GitStatus{}, Ahead: 0, Behind: 0, - props: &properties{ - values: map[Property]interface{}{ - BehindColor: changesColor, - }, - }, } assert.Equal(t, expected, g.getStatusColor(expected)) } func TestSetStatusColorForeground(t *testing.T) { expected := changesColor + var props properties = map[Property]interface{}{ + LocalChangesColor: changesColor, + ColorBackground: false, + } g := &git{ + props: props, Staging: &GitStatus{ Changed: true, }, - props: &properties{ - values: map[Property]interface{}{ - LocalChangesColor: changesColor, - ColorBackground: false, - }, - foreground: "#ffffff", - background: "#111111", - }, } g.SetStatusColor() - assert.Equal(t, expected, g.props.foreground) + assert.Equal(t, expected, g.props[ForegroundOverride]) } func TestSetStatusColorBackground(t *testing.T) { expected := changesColor + var props properties = map[Property]interface{}{ + LocalChangesColor: changesColor, + ColorBackground: true, + } g := &git{ + props: props, Staging: &GitStatus{ Changed: true, }, - props: &properties{ - values: map[Property]interface{}{ - LocalChangesColor: changesColor, - ColorBackground: true, - }, - foreground: "#ffffff", - background: "#111111", - }, } g.SetStatusColor() - assert.Equal(t, expected, g.props.background) + assert.Equal(t, expected, g.props[BackgroundOverride]) } func TestStatusColorsWithoutDisplayStatus(t *testing.T) { @@ -251,15 +225,14 @@ func TestStatusColorsWithoutDisplayStatus(t *testing.T) { status: "## main...origin/main [ahead 33]\n M myfile", } g := setupHEADContextEnv(context) - g.props = &properties{ - values: map[Property]interface{}{ - DisplayStatus: false, - StatusColorsEnabled: true, - LocalChangesColor: expected, - }, + var props properties = map[Property]interface{}{ + DisplayStatus: false, + StatusColorsEnabled: true, + LocalChangesColor: expected, } + g.props = props g.string() - assert.Equal(t, expected, g.props.background) + assert.Equal(t, expected, g.props[BackgroundOverride]) } // EXIT Segement @@ -286,15 +259,11 @@ func TestExitWriterDeprecatedString(t *testing.T) { for _, tc := range cases { env := new(MockedEnvironment) env.On("lastErrorCode", nil).Return(tc.ExitCode) - props := &properties{ - foreground: "#111111", - background: "#ffffff", - values: map[Property]interface{}{ - SuccessIcon: tc.SuccessIcon, - ErrorIcon: tc.ErrorIcon, - DisplayExitCode: tc.DisplayExitCode, - AlwaysNumeric: tc.AlwaysNumeric, - }, + var props properties = map[Property]interface{}{ + SuccessIcon: tc.SuccessIcon, + ErrorIcon: tc.ErrorIcon, + DisplayExitCode: tc.DisplayExitCode, + AlwaysNumeric: tc.AlwaysNumeric, } e := &exit{ env: env, @@ -394,26 +363,22 @@ func TestBatterySegmentSingle(t *testing.T) { 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, - }, + var props properties = 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 + props[DisplayCharging] = false } if tc.DisableCharged { - props.values[DisplayCharged] = false + props[DisplayCharged] = false } env.On("getBatteryInfo", nil).Return(tc.Batteries, tc.Error) b := &batt{ @@ -429,9 +394,9 @@ func TestBatterySegmentSingle(t *testing.T) { if len(tc.ExpectedColor) == 0 { continue } - actualColor := b.props.foreground + actualColor := b.props[ForegroundOverride] if tc.ColorBackground { - actualColor = b.props.background + actualColor = b.props[BackgroundOverride] } assert.Equal(t, tc.ExpectedColor, actualColor, tc.Case) } diff --git a/src/segment_dotnet.go b/src/segment_dotnet.go index a03ca9d1..3217bc1b 100644 --- a/src/segment_dotnet.go +++ b/src/segment_dotnet.go @@ -21,7 +21,7 @@ func (d *dotnet) string() string { return version } -func (d *dotnet) init(props *properties, env environmentInfo) { +func (d *dotnet) init(props properties, env environmentInfo) { d.language = &language{ env: env, props: props, diff --git a/src/segment_dotnet_test.go b/src/segment_dotnet_test.go index e9985707..37d89bbb 100644 --- a/src/segment_dotnet_test.go +++ b/src/segment_dotnet_test.go @@ -28,11 +28,9 @@ func bootStrapDotnetTest(args *dotnetArgs) *dotnet { env.On("getPathSeperator", nil).Return("") env.On("getcwd", nil).Return("/usr/home/project") env.On("homeDir", nil).Return("/usr/home") - props := &properties{ - values: map[Property]interface{}{ - DisplayVersion: args.displayVersion, - UnsupportedDotnetVersionIcon: args.unsupportedIcon, - }, + var props properties = map[Property]interface{}{ + DisplayVersion: args.displayVersion, + UnsupportedDotnetVersionIcon: args.unsupportedIcon, } dotnet := &dotnet{} dotnet.init(props, env) diff --git a/src/segment_envar.go b/src/segment_envar.go index fbed8d22..74ab0f05 100644 --- a/src/segment_envar.go +++ b/src/segment_envar.go @@ -1,7 +1,7 @@ package main type envvar struct { - props *properties + props properties env environmentInfo Value string } @@ -34,7 +34,7 @@ func (e *envvar) string() string { return text } -func (e *envvar) init(props *properties, env environmentInfo) { +func (e *envvar) init(props properties, env environmentInfo) { e.props = props e.env = env } diff --git a/src/segment_envar_test.go b/src/segment_envar_test.go index 99c2bf64..866eb6cd 100644 --- a/src/segment_envar_test.go +++ b/src/segment_envar_test.go @@ -11,15 +11,12 @@ func TestEnvvarAvailable(t *testing.T) { expected := "derp" env := new(MockedEnvironment) env.On("getenv", name).Return(expected) - props := &properties{ - values: map[Property]interface{}{ + e := &envvar{ + env: env, + props: map[Property]interface{}{ VarName: name, }, } - e := &envvar{ - env: env, - props: props, - } assert.True(t, e.enabled()) assert.Equal(t, expected, e.string()) } @@ -29,14 +26,11 @@ func TestEnvvarNotAvailable(t *testing.T) { expected := "" env := new(MockedEnvironment) env.On("getenv", name).Return(expected) - props := &properties{ - values: map[Property]interface{}{ + e := &envvar{ + env: env, + props: map[Property]interface{}{ VarName: name, }, } - e := &envvar{ - env: env, - props: props, - } assert.False(t, e.enabled()) } diff --git a/src/segment_executiontime.go b/src/segment_executiontime.go index 439c7505..34eda796 100644 --- a/src/segment_executiontime.go +++ b/src/segment_executiontime.go @@ -9,7 +9,7 @@ import ( ) type executiontime struct { - props *properties + props properties env environmentInfo FormattedMs string @@ -63,7 +63,7 @@ func (t *executiontime) string() string { return t.FormattedMs } -func (t *executiontime) init(props *properties, env environmentInfo) { +func (t *executiontime) init(props properties, env environmentInfo) { t.props = props t.env = env } diff --git a/src/segment_executiontime_test.go b/src/segment_executiontime_test.go index b2cee41d..5e5edbf5 100644 --- a/src/segment_executiontime_test.go +++ b/src/segment_executiontime_test.go @@ -28,10 +28,8 @@ func TestExecutionTimeWriterDefaultThresholdDisabled(t *testing.T) { func TestExecutionTimeWriterCustomThresholdEnabled(t *testing.T) { env := new(MockedEnvironment) env.On("executionTime", nil).Return(99) - props := &properties{ - values: map[Property]interface{}{ - ThresholdProperty: float64(10), - }, + var props properties = map[Property]interface{}{ + ThresholdProperty: float64(10), } executionTime := &executiontime{ env: env, @@ -43,10 +41,8 @@ func TestExecutionTimeWriterCustomThresholdEnabled(t *testing.T) { func TestExecutionTimeWriterCustomThresholdDisabled(t *testing.T) { env := new(MockedEnvironment) env.On("executionTime", nil).Return(99) - props := &properties{ - values: map[Property]interface{}{ - ThresholdProperty: float64(100), - }, + var props properties = map[Property]interface{}{ + ThresholdProperty: float64(100), } executionTime := &executiontime{ env: env, diff --git a/src/segment_exit.go b/src/segment_exit.go index 2944523c..6395a779 100644 --- a/src/segment_exit.go +++ b/src/segment_exit.go @@ -3,7 +3,7 @@ package main import "strconv" type exit struct { - props *properties + props properties env environmentInfo Code int @@ -21,7 +21,7 @@ func (e *exit) string() string { return e.getFormattedText() } -func (e *exit) init(props *properties, env environmentInfo) { +func (e *exit) init(props properties, env environmentInfo) { e.props = props e.env = env } diff --git a/src/segment_exit_test.go b/src/segment_exit_test.go index 04f6d690..7fe1a6ed 100644 --- a/src/segment_exit_test.go +++ b/src/segment_exit_test.go @@ -76,10 +76,8 @@ func TestExitWriterTemplateString(t *testing.T) { for _, tc := range cases { env := new(MockedEnvironment) env.On("lastErrorCode", nil).Return(tc.ExitCode) - props := &properties{ - values: map[Property]interface{}{ - SegmentTemplate: tc.Template, - }, + var props properties = map[Property]interface{}{ + SegmentTemplate: tc.Template, } e := &exit{ env: env, diff --git a/src/segment_git.go b/src/segment_git.go index 2be71717..20df06f6 100644 --- a/src/segment_git.go +++ b/src/segment_git.go @@ -63,7 +63,7 @@ func (s *GitStatus) String() string { } type git struct { - props *properties + props properties env environmentInfo Working *GitStatus @@ -174,10 +174,7 @@ func (g *git) enabled() bool { } func (g *git) shouldIgnoreRootRepository(rootDir string) bool { - if g.props == nil || g.props.values == nil { - return false - } - value, ok := g.props.values[ExcludeFolders] + value, ok := g.props[ExcludeFolders] if !ok { return false } @@ -226,7 +223,7 @@ func (g *git) templateString(segmentTemplate string) string { return text } -func (g *git) init(props *properties, env environmentInfo) { +func (g *git) init(props properties, env environmentInfo) { g.props = props g.env = env } diff --git a/src/segment_git_test.go b/src/segment_git_test.go index 3d5da5af..1eb0411e 100644 --- a/src/segment_git_test.go +++ b/src/segment_git_test.go @@ -555,14 +555,12 @@ func TestGitUpstream(t *testing.T) { env.On("runCommand", "git", []string{"-C", "", "--no-optional-locks", "-c", "core.quotepath=false", "-c", "color.status=false", "remote", "get-url", "origin"}).Return(tc.Upstream, nil) env.On("getRuntimeGOOS", nil).Return("unix") - props := &properties{ - values: map[Property]interface{}{ - GithubIcon: "GH", - GitlabIcon: "GL", - BitbucketIcon: "BB", - AzureDevOpsIcon: "AD", - GitIcon: "G", - }, + var props properties = map[Property]interface{}{ + GithubIcon: "GH", + GitlabIcon: "GL", + BitbucketIcon: "BB", + AzureDevOpsIcon: "AD", + GitIcon: "G", } g := &git{ env: env, @@ -591,15 +589,14 @@ func TestGetBranchStatus(t *testing.T) { } for _, tc := range cases { + var props properties = map[Property]interface{}{ + BranchAheadIcon: "up", + BranchBehindIcon: "down", + BranchIdenticalIcon: "equal", + BranchGoneIcon: "gone", + } g := &git{ - props: &properties{ - values: map[Property]interface{}{ - BranchAheadIcon: "up", - BranchBehindIcon: "down", - BranchIdenticalIcon: "equal", - BranchGoneIcon: "gone", - }, - }, + props: props, Ahead: tc.Ahead, Behind: tc.Behind, Upstream: tc.Upstream, @@ -621,7 +618,7 @@ func TestShouldIgnoreRootRepository(t *testing.T) { } for _, tc := range cases { - props := map[Property]interface{}{ + var props properties = map[Property]interface{}{ ExcludeFolders: []string{ "/home/bill", "/home/gates.*", @@ -631,10 +628,8 @@ func TestShouldIgnoreRootRepository(t *testing.T) { env.On("homeDir", nil).Return("/home/bill") env.On("getRuntimeGOOS", nil).Return(windowsPlatform) git := &git{ - props: &properties{ - values: props, - }, - env: env, + props: props, + env: env, } got := git.shouldIgnoreRootRepository(tc.Dir) assert.Equal(t, tc.Expected, got, tc.Case) @@ -656,12 +651,11 @@ func TestTruncateBranch(t *testing.T) { } for _, tc := range cases { + var props properties = map[Property]interface{}{ + BranchMaxLength: tc.MaxLength, + } g := &git{ - props: &properties{ - values: map[Property]interface{}{ - BranchMaxLength: tc.MaxLength, - }, - }, + props: props, } assert.Equal(t, tc.Expected, g.truncateBranch(tc.Branch), tc.Case) } @@ -683,13 +677,12 @@ func TestTruncateBranchWithSymbol(t *testing.T) { } for _, tc := range cases { + var props properties = map[Property]interface{}{ + BranchMaxLength: tc.MaxLength, + TruncateSymbol: tc.TruncateSymbol, + } g := &git{ - props: &properties{ - values: map[Property]interface{}{ - BranchMaxLength: tc.MaxLength, - TruncateSymbol: tc.TruncateSymbol, - }, - }, + props: props, } assert.Equal(t, tc.Expected, g.truncateBranch(tc.Branch), tc.Case) } @@ -847,11 +840,10 @@ func TestGitTemplateString(t *testing.T) { } for _, tc := range cases { - tc.Git.props = &properties{ - values: map[Property]interface{}{ - FetchStatus: true, - }, + var props properties = map[Property]interface{}{ + FetchStatus: true, } + tc.Git.props = props assert.Equal(t, tc.Expected, tc.Git.templateString(tc.Template), tc.Case) } } diff --git a/src/segment_golang.go b/src/segment_golang.go index 2651065c..437354d6 100644 --- a/src/segment_golang.go +++ b/src/segment_golang.go @@ -8,7 +8,7 @@ func (g *golang) string() string { return g.language.string() } -func (g *golang) init(props *properties, env environmentInfo) { +func (g *golang) init(props properties, env environmentInfo) { g.language = &language{ env: env, props: props, diff --git a/src/segment_golang_test.go b/src/segment_golang_test.go index 4ac29f90..5391a915 100644 --- a/src/segment_golang_test.go +++ b/src/segment_golang_test.go @@ -14,17 +14,15 @@ type mockedLanguageParams struct { extension string } -func getMockedLanguageEnv(params *mockedLanguageParams) (*MockedEnvironment, *properties) { +func getMockedLanguageEnv(params *mockedLanguageParams) (*MockedEnvironment, properties) { env := new(MockedEnvironment) env.On("hasCommand", params.cmd).Return(true) env.On("runCommand", params.cmd, []string{params.versionParam}).Return(params.versionOutput, nil) env.On("hasFiles", params.extension).Return(true) env.On("getcwd", nil).Return("/usr/home/project") env.On("homeDir", nil).Return("/usr/home") - props := &properties{ - values: map[Property]interface{}{ - DisplayVersion: true, - }, + var props properties = map[Property]interface{}{ + DisplayVersion: true, } return env, props } diff --git a/src/segment_java.go b/src/segment_java.go index eb92f2db..b179a3c0 100644 --- a/src/segment_java.go +++ b/src/segment_java.go @@ -10,7 +10,7 @@ func (j *java) string() string { return j.language.string() } -func (j *java) init(props *properties, env environmentInfo) { +func (j *java) init(props properties, env environmentInfo) { javaRegex := `(?: JRE)(?: \(.*\))? \((?P(?P[0-9]+)(?:\.(?P[0-9]+))?(?:\.(?P[0-9]+))?).*\),` javaCmd := &cmd{ executable: "java", diff --git a/src/segment_java_test.go b/src/segment_java_test.go index 11729dcc..f3829153 100644 --- a/src/segment_java_test.go +++ b/src/segment_java_test.go @@ -66,10 +66,8 @@ func TestJava(t *testing.T) { } else { env.On("getenv", "JAVA_HOME").Return("") } - props := &properties{ - values: map[Property]interface{}{ - DisplayVersion: true, - }, + var props properties = map[Property]interface{}{ + DisplayVersion: true, } j := &java{} j.init(props, env) diff --git a/src/segment_julia.go b/src/segment_julia.go index 01a8b2fa..c49ee2f1 100644 --- a/src/segment_julia.go +++ b/src/segment_julia.go @@ -8,7 +8,7 @@ func (j *julia) string() string { return j.language.string() } -func (j *julia) init(props *properties, env environmentInfo) { +func (j *julia) init(props properties, env environmentInfo) { j.language = &language{ env: env, props: props, diff --git a/src/segment_kubectl.go b/src/segment_kubectl.go index ffa543b4..aa5478f9 100644 --- a/src/segment_kubectl.go +++ b/src/segment_kubectl.go @@ -5,7 +5,7 @@ import ( ) type kubectl struct { - props *properties + props properties env environmentInfo Context string Namespace string @@ -25,7 +25,7 @@ func (k *kubectl) string() string { return text } -func (k *kubectl) init(props *properties, env environmentInfo) { +func (k *kubectl) init(props properties, env environmentInfo) { k.props = props k.env = env } diff --git a/src/segment_kubectl_test.go b/src/segment_kubectl_test.go index 5b5d5f00..489f82c1 100644 --- a/src/segment_kubectl_test.go +++ b/src/segment_kubectl_test.go @@ -29,11 +29,9 @@ func bootStrapKubectlTest(args *kubectlArgs) *kubectl { env.On("runCommand", "kubectl", []string{"config", "view", "--minify", "--output", "jsonpath={..current-context},{..namespace}"}).Return(kubectlOut, kubectlErr) k := &kubectl{ env: env, - props: &properties{ - values: map[Property]interface{}{ - SegmentTemplate: args.template, - DisplayError: args.displayError, - }, + props: map[Property]interface{}{ + SegmentTemplate: args.template, + DisplayError: args.displayError, }, } return k diff --git a/src/segment_language.go b/src/segment_language.go index 3f2b5a70..37c951b0 100644 --- a/src/segment_language.go +++ b/src/segment_language.go @@ -65,7 +65,7 @@ func (c *cmd) buildVersionURL(text, template string) string { } type language struct { - props *properties + props properties env environmentInfo extensions []string commands []*cmd @@ -234,8 +234,8 @@ func (l *language) setVersionFileMismatch() { return } if l.props.getBool(ColorBackground, false) { - l.props.background = l.props.getColor(VersionMismatchColor, l.props.background) + l.props[BackgroundOverride] = l.props.getColor(VersionMismatchColor, l.props.getColor(BackgroundOverride, "")) return } - l.props.foreground = l.props.getColor(VersionMismatchColor, l.props.foreground) + l.props[ForegroundOverride] = l.props.getColor(VersionMismatchColor, l.props.getColor(ForegroundOverride, "")) } diff --git a/src/segment_language_test.go b/src/segment_language_test.go index a54c01fc..529f2d04 100644 --- a/src/segment_language_test.go +++ b/src/segment_language_test.go @@ -50,11 +50,8 @@ func bootStrapLanguageTest(args *languageArgs) *language { } env.On("getcwd", nil).Return(cwd) env.On("homeDir", nil).Return(home) - props := &properties{ - values: args.properties, - } l := &language{ - props: props, + props: args.properties, env: env, extensions: args.extensions, commands: args.commands, @@ -549,9 +546,9 @@ func TestLanguageVersionMismatch(t *testing.T) { assert.True(t, lang.enabled(), tc.Case) assert.Equal(t, universion, lang.string(), tc.Case) if tc.ColorBackground { - assert.Equal(t, tc.ExpectedColor, lang.props.background, tc.Case) + assert.Equal(t, tc.ExpectedColor, lang.props[BackgroundOverride], tc.Case) return } - assert.Equal(t, tc.ExpectedColor, lang.props.foreground, tc.Case) + assert.Equal(t, tc.ExpectedColor, lang.props.getColor(ForegroundOverride, ""), tc.Case) } } diff --git a/src/segment_nbgv.go b/src/segment_nbgv.go index cf83a01e..d4af63b9 100644 --- a/src/segment_nbgv.go +++ b/src/segment_nbgv.go @@ -5,7 +5,7 @@ import ( ) type nbgv struct { - props *properties + props properties env environmentInfo nbgv *versionInfo } @@ -52,7 +52,7 @@ func (n *nbgv) string() string { return text } -func (n *nbgv) init(props *properties, env environmentInfo) { +func (n *nbgv) init(props properties, env environmentInfo) { n.props = props n.env = env } diff --git a/src/segment_nbgv_test.go b/src/segment_nbgv_test.go index 12ce52fa..f55b1c52 100644 --- a/src/segment_nbgv_test.go +++ b/src/segment_nbgv_test.go @@ -62,10 +62,8 @@ func TestNbgv(t *testing.T) { env.On("runCommand", "nbgv", []string{"get-version", "--format=json"}).Return(tc.Response, tc.Error) nbgv := &nbgv{ env: env, - props: &properties{ - values: map[Property]interface{}{ - SegmentTemplate: tc.SegmentTemplate, - }, + props: map[Property]interface{}{ + SegmentTemplate: tc.SegmentTemplate, }, } enabled := nbgv.enabled() diff --git a/src/segment_nightscout.go b/src/segment_nightscout.go index f26d355e..521d6857 100644 --- a/src/segment_nightscout.go +++ b/src/segment_nightscout.go @@ -8,7 +8,7 @@ import ( // segment struct, makes templating easier type nightscout struct { - props *properties + props properties env environmentInfo NightscoutData @@ -148,7 +148,7 @@ func (ns *nightscout) getResult() (*NightscoutData, error) { return data, nil } -func (ns *nightscout) init(props *properties, env environmentInfo) { +func (ns *nightscout) init(props properties, env environmentInfo) { ns.props = props ns.env = env } diff --git a/src/segment_nightscout_test.go b/src/segment_nightscout_test.go index 3e5cb370..3117e42d 100644 --- a/src/segment_nightscout_test.go +++ b/src/segment_nightscout_test.go @@ -130,11 +130,9 @@ func TestNSSegment(t *testing.T) { for _, tc := range cases { env := &MockedEnvironment{} - props := &properties{ - values: map[Property]interface{}{ - CacheTimeout: tc.CacheTimeout, - URL: "FAKE", - }, + var props properties = map[Property]interface{}{ + CacheTimeout: tc.CacheTimeout, + URL: "FAKE", } cache := &MockedCache{} @@ -145,7 +143,7 @@ func TestNSSegment(t *testing.T) { env.On("cache", nil).Return(cache) if tc.Template != "" { - props.values[SegmentTemplate] = tc.Template + props[SegmentTemplate] = tc.Template } ns := &nightscout{ diff --git a/src/segment_node.go b/src/segment_node.go index d7436a06..bfef9ac1 100644 --- a/src/segment_node.go +++ b/src/segment_node.go @@ -21,7 +21,7 @@ func (n *node) string() string { return fmt.Sprintf("%s%s", version, n.packageManagerIcon) } -func (n *node) init(props *properties, env environmentInfo) { +func (n *node) init(props properties, env environmentInfo) { n.language = &language{ env: env, props: props, diff --git a/src/segment_node_test.go b/src/segment_node_test.go index 6b2a8f73..d8c974a0 100644 --- a/src/segment_node_test.go +++ b/src/segment_node_test.go @@ -68,12 +68,10 @@ func TestNodeInContext(t *testing.T) { node := &node{ language: &language{ env: env, - props: &properties{ - values: map[Property]interface{}{ - YarnIcon: "yarn", - NPMIcon: "npm", - DisplayPackageManager: tc.PkgMgrEnabled, - }, + props: map[Property]interface{}{ + YarnIcon: "yarn", + NPMIcon: "npm", + DisplayPackageManager: tc.PkgMgrEnabled, }, }, } diff --git a/src/segment_os.go b/src/segment_os.go index 5161a52c..37a31edf 100644 --- a/src/segment_os.go +++ b/src/segment_os.go @@ -5,7 +5,7 @@ import ( ) type osInfo struct { - props *properties + props properties env environmentInfo OS string } @@ -145,7 +145,7 @@ func (n *osInfo) getDistroName(distro, defaultName string) string { return n.props.getString(Linux, "\uF17C") } -func (n *osInfo) init(props *properties, env environmentInfo) { +func (n *osInfo) init(props properties, env environmentInfo) { n.props = props n.env = env } diff --git a/src/segment_os_test.go b/src/segment_os_test.go index 0cd54756..61565ed7 100644 --- a/src/segment_os_test.go +++ b/src/segment_os_test.go @@ -64,8 +64,9 @@ func TestOSInfo(t *testing.T) { env.On("getRuntimeGOOS", nil).Return(tc.GOOS) env.On("getenv", "WSL_DISTRO_NAME").Return(tc.WSLDistro) env.On("getPlatform", nil).Return(tc.Platform) - props := &properties{ - values: map[Property]interface{}{ + osInfo := &osInfo{ + env: env, + props: map[Property]interface{}{ WSL: "WSL", WSLSeparator: " at ", DisplayDistroName: tc.DisplayDistroName, @@ -73,10 +74,6 @@ func TestOSInfo(t *testing.T) { MacOS: "darwin", }, } - osInfo := &osInfo{ - env: env, - props: props, - } assert.Equal(t, tc.ExpectedString, osInfo.string(), tc.Case) if tc.WSLDistro != "" { assert.Equal(t, tc.WSLDistro, osInfo.OS, tc.Case) diff --git a/src/segment_owm.go b/src/segment_owm.go index 8c375634..ca1928f3 100644 --- a/src/segment_owm.go +++ b/src/segment_owm.go @@ -6,7 +6,7 @@ import ( ) type owm struct { - props *properties + props properties env environmentInfo Temperature float64 Weather string @@ -168,7 +168,7 @@ func (d *owm) setStatus() error { return nil } -func (d *owm) init(props *properties, env environmentInfo) { +func (d *owm) init(props properties, env environmentInfo) { d.props = props d.env = env } diff --git a/src/segment_owm_test.go b/src/segment_owm_test.go index 3c6b4fea..96183579 100644 --- a/src/segment_owm_test.go +++ b/src/segment_owm_test.go @@ -51,19 +51,17 @@ func TestOWMSegmentSingle(t *testing.T) { for _, tc := range cases { env := &MockedEnvironment{} - props := &properties{ - values: map[Property]interface{}{ - APIKey: "key", - Location: "AMSTERDAM,NL", - Units: "metric", - CacheTimeout: 0, - }, + var props properties = map[Property]interface{}{ + APIKey: "key", + Location: "AMSTERDAM,NL", + Units: "metric", + CacheTimeout: 0, } env.On("doGet", OWMAPIURL).Return([]byte(tc.JSONResponse), tc.Error) if tc.Template != "" { - props.values[SegmentTemplate] = tc.Template + props[SegmentTemplate] = tc.Template } o := &owm{ @@ -182,14 +180,6 @@ func TestOWMSegmentIcons(t *testing.T) { for _, tc := range cases { env := &MockedEnvironment{} - props := &properties{ - values: map[Property]interface{}{ - APIKey: "key", - Location: "AMSTERDAM,NL", - Units: "metric", - CacheTimeout: 0, - }, - } response := fmt.Sprintf(`{"weather":[{"icon":"%s"}],"main":{"temp":20}}`, tc.IconID) expectedString := fmt.Sprintf("%s (20°C)", tc.ExpectedIconString) @@ -197,8 +187,13 @@ func TestOWMSegmentIcons(t *testing.T) { env.On("doGet", OWMAPIURL).Return([]byte(response), nil) o := &owm{ - props: props, - env: env, + props: map[Property]interface{}{ + APIKey: "key", + Location: "AMSTERDAM,NL", + Units: "metric", + CacheTimeout: 0, + }, + env: env, } assert.Nil(t, o.setStatus()) @@ -208,26 +203,22 @@ func TestOWMSegmentIcons(t *testing.T) { // test with hyperlink enabled for _, tc := range cases { env := &MockedEnvironment{} - props := &properties{ - values: map[Property]interface{}{ - APIKey: "key", - Location: "AMSTERDAM,NL", - Units: "metric", - CacheTimeout: 0, - EnableHyperlink: true, - }, - } response := fmt.Sprintf(`{"weather":[{"icon":"%s"}],"main":{"temp":20}}`, tc.IconID) expectedString := fmt.Sprintf("[%s (20°C)](http://api.openweathermap.org/data/2.5/weather?q=AMSTERDAM,NL&units=metric&appid=key)", tc.ExpectedIconString) env.On("doGet", OWMAPIURL).Return([]byte(response), nil) - props.values[SegmentTemplate] = "[{{.Weather}} ({{.Temperature}}{{.UnitIcon}})]({{.URL}})" - o := &owm{ - props: props, - env: env, + props: map[Property]interface{}{ + APIKey: "key", + Location: "AMSTERDAM,NL", + Units: "metric", + CacheTimeout: 0, + EnableHyperlink: true, + SegmentTemplate: "[{{.Weather}} ({{.Temperature}}{{.UnitIcon}})]({{.URL}})", + }, + env: env, } assert.Nil(t, o.setStatus()) @@ -240,16 +231,13 @@ func TestOWMSegmentFromCache(t *testing.T) { env := &MockedEnvironment{} cache := &MockedCache{} - props := &properties{ - values: map[Property]interface{}{ + o := &owm{ + props: map[Property]interface{}{ APIKey: "key", Location: "AMSTERDAM,NL", Units: "metric", }, - } - o := &owm{ - props: props, - env: env, + env: env, } cache.On("get", "owm_response").Return(response, true) cache.On("get", "owm_url").Return("http://api.openweathermap.org/data/2.5/weather?q=AMSTERDAM,NL&units=metric&appid=key", true) @@ -266,20 +254,16 @@ func TestOWMSegmentFromCacheWithHyperlink(t *testing.T) { env := &MockedEnvironment{} cache := &MockedCache{} - props := &properties{ - values: map[Property]interface{}{ + + o := &owm{ + props: map[Property]interface{}{ APIKey: "key", Location: "AMSTERDAM,NL", Units: "metric", EnableHyperlink: true, + SegmentTemplate: "[{{.Weather}} ({{.Temperature}}{{.UnitIcon}})]({{.URL}})", }, - } - - props.values[SegmentTemplate] = "[{{.Weather}} ({{.Temperature}}{{.UnitIcon}})]({{.URL}})" - - o := &owm{ - props: props, - env: env, + env: env, } cache.On("get", "owm_response").Return(response, true) cache.On("get", "owm_url").Return("http://api.openweathermap.org/data/2.5/weather?q=AMSTERDAM,NL&units=metric&appid=key", true) diff --git a/src/segment_path.go b/src/segment_path.go index a7da427e..9a848c46 100644 --- a/src/segment_path.go +++ b/src/segment_path.go @@ -8,7 +8,7 @@ import ( ) type path struct { - props *properties + props properties env environmentInfo } @@ -100,7 +100,7 @@ func (pt *path) formatWindowsDrive(pwd string) string { return pwd + "\\" } -func (pt *path) init(props *properties, env environmentInfo) { +func (pt *path) init(props properties, env environmentInfo) { pt.props = props pt.env = env } diff --git a/src/segment_path_test.go b/src/segment_path_test.go index 91035dbc..f4c263d3 100644 --- a/src/segment_path_test.go +++ b/src/segment_path_test.go @@ -231,12 +231,6 @@ func TestRootLocationHome(t *testing.T) { {Expected: "DRIVE:", HomePath: "/home/bill/", Pwd: "/usr/error/what", Pswd: "DRIVE:", PathSeperator: "/"}, } for _, tc := range cases { - props := &properties{ - values: map[Property]interface{}{ - HomeIcon: tc.HomeIcon, - WindowsRegistryIcon: tc.RegistryIcon, - }, - } env := new(MockedEnvironment) env.On("homeDir", nil).Return(tc.HomePath) env.On("getcwd", nil).Return(tc.Pwd) @@ -247,8 +241,11 @@ func TestRootLocationHome(t *testing.T) { env.On("getPathSeperator", nil).Return(tc.PathSeperator) env.On("getRuntimeGOOS", nil).Return("") path := &path{ - env: env, - props: props, + env: env, + props: map[Property]interface{}{ + HomeIcon: tc.HomeIcon, + WindowsRegistryIcon: tc.RegistryIcon, + }, } got := path.rootLocation() assert.EqualValues(t, tc.Expected, got) @@ -396,12 +393,10 @@ func TestAgnosterPathStyles(t *testing.T) { env.On("getArgs", nil).Return(args) path := &path{ env: env, - props: &properties{ - values: map[Property]interface{}{ - FolderSeparatorIcon: tc.FolderSeparatorIcon, - Style: tc.Style, - MaxDepth: tc.MaxDepth, - }, + props: map[Property]interface{}{ + FolderSeparatorIcon: tc.FolderSeparatorIcon, + Style: tc.Style, + MaxDepth: tc.MaxDepth, }, } got := path.string() @@ -513,17 +508,15 @@ func TestGetFullPath(t *testing.T) { PSWD: &tc.Pswd, } env.On("getArgs", nil).Return(args) - props := &properties{ - values: map[Property]interface{}{ - Style: tc.Style, - StackCountEnabled: tc.StackCountEnabled, - }, + var props properties = map[Property]interface{}{ + Style: tc.Style, + StackCountEnabled: tc.StackCountEnabled, } if tc.FolderSeparatorIcon != "" { - props.values[FolderSeparatorIcon] = tc.FolderSeparatorIcon + props[FolderSeparatorIcon] = tc.FolderSeparatorIcon } if tc.DisableMappedLocations { - props.values[MappedLocationsEnabled] = false + props[MappedLocationsEnabled] = false } path := &path{ env: env, @@ -563,11 +556,9 @@ func TestGetFullPathCustomMappedLocations(t *testing.T) { env.On("getArgs", nil).Return(args) path := &path{ env: env, - props: &properties{ - values: map[Property]interface{}{ - MappedLocationsEnabled: false, - MappedLocations: tc.MappedLocations, - }, + props: map[Property]interface{}{ + MappedLocationsEnabled: false, + MappedLocations: tc.MappedLocations, }, } got := path.getFullPath() @@ -616,11 +607,9 @@ func TestGetFolderPathCustomMappedLocations(t *testing.T) { env.On("getArgs", nil).Return(args) path := &path{ env: env, - props: &properties{ - values: map[Property]interface{}{ - MappedLocations: map[string]string{ - "/a/b/c/d": "#", - }, + props: map[Property]interface{}{ + MappedLocations: map[string]string{ + "/a/b/c/d": "#", }, }, } @@ -654,13 +643,6 @@ func TestAgnosterPath(t *testing.T) { } for _, tc := range cases { - props := &properties{ - values: map[Property]interface{}{ - FolderSeparatorIcon: " > ", - FolderIcon: "f", - HomeIcon: "~", - }, - } env := new(MockedEnvironment) env.On("homeDir", nil).Return(tc.Home) env.On("getPathSeperator", nil).Return(tc.PathSeparator) @@ -671,8 +653,12 @@ func TestAgnosterPath(t *testing.T) { } env.On("getArgs", nil).Return(args) path := &path{ - env: env, - props: props, + env: env, + props: map[Property]interface{}{ + FolderSeparatorIcon: " > ", + FolderIcon: "f", + HomeIcon: "~", + }, } got := path.getAgnosterPath() assert.Equal(t, tc.Expected, got, tc.Case) @@ -716,12 +702,10 @@ func TestGetPwd(t *testing.T) { env.On("getArgs", nil).Return(args) path := &path{ env: env, - props: &properties{ - values: map[Property]interface{}{ - MappedLocationsEnabled: tc.MappedLocationsEnabled, - MappedLocations: map[string]string{ - "/a/b/c/d": "#", - }, + props: map[Property]interface{}{ + MappedLocationsEnabled: tc.MappedLocationsEnabled, + MappedLocations: map[string]string{ + "/a/b/c/d": "#", }, }, } @@ -751,10 +735,7 @@ func TestParseMappedLocations(t *testing.T) { var segment Segment err = config.BindStruct("", &segment) assert.NoError(t, err) - props := &properties{ - values: segment.Properties, - } - mappedLocations := props.getKeyValueMap(MappedLocations, make(map[string]string)) + mappedLocations := segment.Properties.getKeyValueMap(MappedLocations, make(map[string]string)) assert.Equal(t, "two", mappedLocations["folder2"]) } } diff --git a/src/segment_php.go b/src/segment_php.go index eca30264..d2a55198 100644 --- a/src/segment_php.go +++ b/src/segment_php.go @@ -8,7 +8,7 @@ func (n *php) string() string { return n.language.string() } -func (n *php) init(props *properties, env environmentInfo) { +func (n *php) init(props properties, env environmentInfo) { n.language = &language{ env: env, props: props, diff --git a/src/segment_posh_git.go b/src/segment_posh_git.go index 32ee1ef5..262dc142 100644 --- a/src/segment_posh_git.go +++ b/src/segment_posh_git.go @@ -3,7 +3,7 @@ package main import "strings" type poshgit struct { - props *properties + props properties env environmentInfo gitStatus string } @@ -22,7 +22,7 @@ func (p *poshgit) string() string { return p.gitStatus } -func (p *poshgit) init(props *properties, env environmentInfo) { +func (p *poshgit) init(props properties, env environmentInfo) { p.props = props p.env = env } diff --git a/src/segment_python.go b/src/segment_python.go index 23bbf24b..fd8e7b3d 100644 --- a/src/segment_python.go +++ b/src/segment_python.go @@ -23,7 +23,7 @@ func (p *python) string() string { return fmt.Sprintf("%s %s", p.venvName, version) } -func (p *python) init(props *properties, env environmentInfo) { +func (p *python) init(props properties, env environmentInfo) { p.language = &language{ env: env, props: props, diff --git a/src/segment_python_test.go b/src/segment_python_test.go index 6b28f2c2..e93992f7 100644 --- a/src/segment_python_test.go +++ b/src/segment_python_test.go @@ -39,12 +39,10 @@ func TestPythonVirtualEnv(t *testing.T) { env.On("getPathSeperator", nil).Return("") env.On("getcwd", nil).Return("/usr/home/project") env.On("homeDir", nil).Return("/usr/home") - props := &properties{ - values: map[Property]interface{}{ - DisplayVersion: tc.DisplayVersion, - DisplayVirtualEnv: true, - DisplayDefault: tc.DisplayDefault, - }, + var props properties = map[Property]interface{}{ + DisplayVersion: tc.DisplayVersion, + DisplayVirtualEnv: true, + DisplayDefault: tc.DisplayDefault, } python := &python{} python.init(props, env) diff --git a/src/segment_root.go b/src/segment_root.go index a844ef53..d16553a6 100644 --- a/src/segment_root.go +++ b/src/segment_root.go @@ -1,7 +1,7 @@ package main type root struct { - props *properties + props properties env environmentInfo } @@ -18,7 +18,7 @@ func (rt *root) string() string { return rt.props.getString(RootIcon, "\uF0E7") } -func (rt *root) init(props *properties, env environmentInfo) { +func (rt *root) init(props properties, env environmentInfo) { rt.props = props rt.env = env } diff --git a/src/segment_ruby.go b/src/segment_ruby.go index 383972ea..8178932f 100644 --- a/src/segment_ruby.go +++ b/src/segment_ruby.go @@ -13,7 +13,7 @@ func (r *ruby) string() string { return version } -func (r *ruby) init(props *properties, env environmentInfo) { +func (r *ruby) init(props properties, env environmentInfo) { r.language = &language{ env: env, props: props, diff --git a/src/segment_ruby_test.go b/src/segment_ruby_test.go index dbc3f8ec..cdcabd0e 100644 --- a/src/segment_ruby_test.go +++ b/src/segment_ruby_test.go @@ -98,10 +98,8 @@ func TestRuby(t *testing.T) { env.On("hasFiles", "Gemfile").Return(tc.HasGemFile) env.On("getcwd", nil).Return("/usr/home/project") env.On("homeDir", nil).Return("/usr/home") - props := &properties{ - values: map[Property]interface{}{ - DisplayVersion: tc.DisplayVersion, - }, + var props properties = map[Property]interface{}{ + DisplayVersion: tc.DisplayVersion, } ruby := &ruby{} ruby.init(props, env) diff --git a/src/segment_rust.go b/src/segment_rust.go index a0396cf5..730bf4ff 100644 --- a/src/segment_rust.go +++ b/src/segment_rust.go @@ -8,7 +8,7 @@ func (r *rust) string() string { return r.language.string() } -func (r *rust) init(props *properties, env environmentInfo) { +func (r *rust) init(props properties, env environmentInfo) { r.language = &language{ env: env, props: props, diff --git a/src/segment_session.go b/src/segment_session.go index 7a0b8e02..40ccb168 100644 --- a/src/segment_session.go +++ b/src/segment_session.go @@ -6,7 +6,7 @@ import ( ) type session struct { - props *properties + props properties env environmentInfo UserName string DefaultUserName string @@ -66,7 +66,7 @@ func (s *session) string() string { return s.getFormattedText() } -func (s *session) init(props *properties, env environmentInfo) { +func (s *session) init(props properties, env environmentInfo) { s.props = props s.env = env } @@ -83,8 +83,9 @@ func (s *session) getFormattedText() string { if s.SSHSession { sshIcon = s.props.getString(SSHIcon, "\uF817 ") } - userColor := s.props.getColor(UserColor, s.props.foreground) - hostColor := s.props.getColor(HostColor, s.props.foreground) + defaulColor := s.props.getColor(ForegroundOverride, "") + userColor := s.props.getColor(UserColor, defaulColor) + hostColor := s.props.getColor(HostColor, defaulColor) if len(userColor) > 0 && len(hostColor) > 0 { return fmt.Sprintf("%s<%s>%s%s<%s>%s", sshIcon, userColor, s.UserName, separator, hostColor, s.ComputerName) } diff --git a/src/segment_session_test.go b/src/segment_session_test.go index 5593b09e..d7fa05c3 100644 --- a/src/segment_session_test.go +++ b/src/segment_session_test.go @@ -179,17 +179,15 @@ func TestPropertySessionSegment(t *testing.T) { env.On("getenv", "SSH_CLIENT").Return(SSHSession) env.On("getenv", defaultUserEnvVar).Return(tc.DefaultUserNameEnv) env.On("isRunningAsRoot", nil).Return(tc.Root) - props := &properties{ - values: map[Property]interface{}{ - UserInfoSeparator: " at ", - SSHIcon: "ssh ", - DefaultUserName: tc.DefaultUserName, - DisplayDefault: tc.DisplayDefault, - DisplayUser: tc.DisplayUser, - DisplayHost: tc.DisplayHost, - HostColor: tc.HostColor, - UserColor: tc.UserColor, - }, + var props properties = map[Property]interface{}{ + UserInfoSeparator: " at ", + SSHIcon: "ssh ", + DefaultUserName: tc.DefaultUserName, + DisplayDefault: tc.DisplayDefault, + DisplayUser: tc.DisplayUser, + DisplayHost: tc.DisplayHost, + HostColor: tc.HostColor, + UserColor: tc.UserColor, } session := &session{ env: env, @@ -303,15 +301,12 @@ func TestSessionSegmentTemplate(t *testing.T) { env.On("getenv", "SSH_CLIENT").Return(SSHSession) env.On("isRunningAsRoot", nil).Return(tc.Root) env.On("getenv", defaultUserEnvVar).Return(tc.DefaultUserName) - props := &properties{ - values: map[Property]interface{}{ + session := &session{ + env: env, + props: map[Property]interface{}{ SegmentTemplate: tc.Template, }, } - session := &session{ - env: env, - props: props, - } assert.Equal(t, tc.ExpectedEnabled, session.enabled(), tc.Case) if tc.ExpectedEnabled { assert.Equal(t, tc.ExpectedString, session.string(), tc.Case) diff --git a/src/segment_shell.go b/src/segment_shell.go index 782433ed..7c60a1ff 100644 --- a/src/segment_shell.go +++ b/src/segment_shell.go @@ -3,7 +3,7 @@ package main import "strings" type shell struct { - props *properties + props properties env environmentInfo } @@ -28,7 +28,7 @@ func (s *shell) string() string { return shellName } -func (s *shell) init(props *properties, env environmentInfo) { +func (s *shell) init(props properties, env environmentInfo) { s.props = props s.env = env } diff --git a/src/segment_shell_test.go b/src/segment_shell_test.go index 278414cc..12dba9e9 100644 --- a/src/segment_shell_test.go +++ b/src/segment_shell_test.go @@ -10,10 +10,8 @@ func TestWriteCurrentShell(t *testing.T) { expected := "zsh" env := new(MockedEnvironment) env.On("getShellName", nil).Return(expected, nil) - props := &properties{} s := &shell{ - env: env, - props: props, + env: env, } assert.Equal(t, expected, s.string()) } @@ -32,10 +30,8 @@ func TestUseMappedShellNames(t *testing.T) { env.On("getShellName", nil).Return(tc.Expected, nil) s := &shell{ env: env, - props: &properties{ - values: map[Property]interface{}{ - MappedShellNames: map[string]string{"pwsh": "PS"}, - }, + props: map[Property]interface{}{ + MappedShellNames: map[string]string{"pwsh": "PS"}, }, } got := s.string() diff --git a/src/segment_spotify.go b/src/segment_spotify.go index 0d8e93af..307dad20 100644 --- a/src/segment_spotify.go +++ b/src/segment_spotify.go @@ -5,7 +5,7 @@ import ( ) type spotify struct { - props *properties + props properties env environmentInfo status string artist string @@ -39,7 +39,7 @@ func (s *spotify) string() string { return fmt.Sprintf("%s%s%s%s", icon, s.artist, separator, s.track) } -func (s *spotify) init(props *properties, env environmentInfo) { +func (s *spotify) init(props properties, env environmentInfo) { s.props = props s.env = env } diff --git a/src/segment_spotify_darwin_test.go b/src/segment_spotify_darwin_test.go index 81650891..ced85cae 100644 --- a/src/segment_spotify_darwin_test.go +++ b/src/segment_spotify_darwin_test.go @@ -22,10 +22,8 @@ func bootStrapSpotifyDarwinTest(args *spotifyArgs) *spotify { env.On("runCommand", "osascript", []string{"-e", "tell application \"Spotify\" to player state as string"}).Return(args.status, nil) env.On("runCommand", "osascript", []string{"-e", "tell application \"Spotify\" to artist of current track as string"}).Return(args.artist, nil) env.On("runCommand", "osascript", []string{"-e", "tell application \"Spotify\" to name of current track as string"}).Return(args.track, nil) - props := &properties{} s := &spotify{ - env: env, - props: props, + env: env, } return s } diff --git a/src/segment_spotify_windows_test.go b/src/segment_spotify_windows_test.go index 44d446ae..98568a65 100644 --- a/src/segment_spotify_windows_test.go +++ b/src/segment_spotify_windows_test.go @@ -17,10 +17,8 @@ type spotifyArgs struct { func bootStrapSpotifyWindowsTest(args *spotifyArgs) *spotify { env := new(MockedEnvironment) env.On("getWindowTitle", "spotify.exe").Return(args.title, args.runError) - props := &properties{} s := &spotify{ - env: env, - props: props, + env: env, } return s } diff --git a/src/segment_spotify_wsl_test.go b/src/segment_spotify_wsl_test.go index 2dca1286..c5de82f2 100644 --- a/src/segment_spotify_wsl_test.go +++ b/src/segment_spotify_wsl_test.go @@ -54,10 +54,8 @@ func TestSpotifyWsl(t *testing.T) { env := new(MockedEnvironment) env.On("isWsl", nil).Return(true) env.On("runCommand", "tasklist.exe", []string{"/V", "/FI", "Imagename eq Spotify.exe", "/FO", "CSV", "/NH"}).Return(tc.ExecOutput, nil) - props := &properties{} s := &spotify{ - env: env, - props: props, + env: env, } assert.Equal(t, tc.ExpectedEnabled, s.enabled(), fmt.Sprintf("Failed in case: %s", tc.Case)) assert.Equal(t, tc.ExpectedString, s.string(), fmt.Sprintf("Failed in case: %s", tc.Case)) diff --git a/src/segment_sysinfo.go b/src/segment_sysinfo.go index 398c9d51..3fab2aa6 100644 --- a/src/segment_sysinfo.go +++ b/src/segment_sysinfo.go @@ -7,7 +7,7 @@ import ( ) type sysinfo struct { - props *properties + props properties env environmentInfo Precision int // mem @@ -53,7 +53,7 @@ func (s *sysinfo) string() string { return text } -func (s *sysinfo) init(props *properties, env environmentInfo) { +func (s *sysinfo) init(props properties, env environmentInfo) { s.props = props s.env = env s.Precision = s.props.getInt(Precision, 2) diff --git a/src/segment_sysinfo_test.go b/src/segment_sysinfo_test.go index 1a876728..c30b5864 100644 --- a/src/segment_sysinfo_test.go +++ b/src/segment_sysinfo_test.go @@ -35,13 +35,11 @@ func TestSysInfo(t *testing.T) { for _, tc := range cases { tc.SysInfo.env = new(MockedEnvironment) - tc.SysInfo.props = &properties{ - values: map[Property]interface{}{ - Precision: tc.Precision, - }, + tc.SysInfo.props = map[Property]interface{}{ + Precision: tc.Precision, } if tc.Template != "" { - tc.SysInfo.props.values[SegmentTemplate] = tc.Template + tc.SysInfo.props[SegmentTemplate] = tc.Template } if tc.ExpectDisabled { assert.Equal(t, false, tc.SysInfo.enabled(), tc.Case) diff --git a/src/segment_terraform.go b/src/segment_terraform.go index be992fc8..9ded07ce 100644 --- a/src/segment_terraform.go +++ b/src/segment_terraform.go @@ -1,7 +1,7 @@ package main type terraform struct { - props *properties + props properties env environmentInfo WorkspaceName string } @@ -20,7 +20,7 @@ func (tf *terraform) string() string { return text } -func (tf *terraform) init(props *properties, env environmentInfo) { +func (tf *terraform) init(props properties, env environmentInfo) { tf.props = props tf.env = env } diff --git a/src/segment_terraform_test.go b/src/segment_terraform_test.go index a513a571..bf3d6ab5 100644 --- a/src/segment_terraform_test.go +++ b/src/segment_terraform_test.go @@ -19,8 +19,7 @@ func bootStrapTerraformTest(args *terraformArgs) *terraform { env.On("getcwd", nil).Return("") env.On("runCommand", "terraform", []string{"workspace", "show"}).Return(args.workspaceName, nil) k := &terraform{ - env: env, - props: &properties{}, + env: env, } return k } diff --git a/src/segment_test.go b/src/segment_test.go index 0807f0a6..9526e893 100644 --- a/src/segment_test.go +++ b/src/segment_test.go @@ -17,7 +17,6 @@ func TestMapSegmentWriterCanMap(t *testing.T) { } env := new(MockedEnvironment) err := sc.mapSegmentWithWriter(env) - assert.NotNil(t, sc.props) assert.NoError(t, err) assert.NotNil(t, sc.writer) } @@ -28,7 +27,6 @@ func TestMapSegmentWriterCannotMap(t *testing.T) { } env := new(MockedEnvironment) err := sc.mapSegmentWithWriter(env) - assert.Nil(t, sc.props) assert.Error(t, err) } diff --git a/src/segment_text.go b/src/segment_text.go index d41300d9..fb1c6573 100644 --- a/src/segment_text.go +++ b/src/segment_text.go @@ -1,7 +1,7 @@ package main type text struct { - props *properties + props properties env environmentInfo content string } @@ -26,7 +26,7 @@ func (t *text) string() string { return t.content } -func (t *text) init(props *properties, env environmentInfo) { +func (t *text) init(props properties, env environmentInfo) { t.props = props t.env = env } diff --git a/src/segment_text_test.go b/src/segment_text_test.go index 1385adfd..21932956 100644 --- a/src/segment_text_test.go +++ b/src/segment_text_test.go @@ -33,15 +33,12 @@ func TestTextSegment(t *testing.T) { env.On("getenv", "WORLD").Return("") env.On("getCurrentUser", nil).Return("Posh") env.On("getHostName", nil).Return("MyHost", nil) - props := &properties{ - values: map[Property]interface{}{ + txt := &text{ + env: env, + props: map[Property]interface{}{ TextProperty: tc.Text, }, } - txt := &text{ - env: env, - props: props, - } assert.Equal(t, tc.ExpectedDisabled, !txt.enabled(), tc.Case) assert.Equal(t, tc.ExpectedString, txt.string(), tc.Case) } diff --git a/src/segment_time.go b/src/segment_time.go index 1404d5c0..8f6a3227 100644 --- a/src/segment_time.go +++ b/src/segment_time.go @@ -3,7 +3,7 @@ package main import "time" type tempus struct { - props *properties + props properties env environmentInfo templateText string CurrentDate time.Time @@ -40,7 +40,7 @@ func (t *tempus) string() string { return t.getFormattedText() } -func (t *tempus) init(props *properties, env environmentInfo) { +func (t *tempus) init(props properties, env environmentInfo) { t.props = props t.env = env } diff --git a/src/segment_time_test.go b/src/segment_time_test.go index 02fe8cd1..f8e8f0ef 100644 --- a/src/segment_time_test.go +++ b/src/segment_time_test.go @@ -39,14 +39,11 @@ func TestTimeSegmentTemplate(t *testing.T) { for _, tc := range cases { env := new(MockedEnvironment) - props := &properties{ - values: map[Property]interface{}{ + tempus := &tempus{ + env: env, + props: map[Property]interface{}{ SegmentTemplate: tc.Template, }, - } - tempus := &tempus{ - env: env, - props: props, CurrentDate: currentDate, } assert.Equal(t, tc.ExpectedEnabled, tempus.enabled()) diff --git a/src/segment_wifi.go b/src/segment_wifi.go index 10e10f49..cce8cda6 100644 --- a/src/segment_wifi.go +++ b/src/segment_wifi.go @@ -7,7 +7,7 @@ import ( ) type wifi struct { - props *properties + props properties env environmentInfo Connected bool State string @@ -68,7 +68,7 @@ func (w *wifi) string() string { return text } -func (w *wifi) init(props *properties, env environmentInfo) { +func (w *wifi) init(props properties, env environmentInfo) { w.props = props w.env = env } diff --git a/src/segment_wifi_test.go b/src/segment_wifi_test.go index 5f2a1ab6..b7f474cd 100644 --- a/src/segment_wifi_test.go +++ b/src/segment_wifi_test.go @@ -120,18 +120,14 @@ func TestWiFiSegment(t *testing.T) { env.On("hasCommand", "netsh.exe").Return(!tc.CommandNotFound) env.On("runCommand", mock.Anything, mock.Anything).Return(tc.CommandOutput, tc.CommandError) - props := &properties{ - values: map[Property]interface{}{ + w := &wifi{ + env: env, + props: map[Property]interface{}{ DisplayError: tc.DisplayError, SegmentTemplate: tc.Template, }, } - w := &wifi{ - env: env, - props: props, - } - assert.Equal(t, tc.ExpectedEnabled, w.enabled(), tc.Case) assert.Equal(t, tc.ExpectedString, w.string(), tc.Case) } diff --git a/src/segment_winreg.go b/src/segment_winreg.go index b2ebe713..cfb4c575 100644 --- a/src/segment_winreg.go +++ b/src/segment_winreg.go @@ -1,7 +1,7 @@ package main type winreg struct { - props *properties + props properties env environmentInfo Value string @@ -16,7 +16,7 @@ const ( Fallback Property = "fallback" ) -func (wr *winreg) init(props *properties, env environmentInfo) { +func (wr *winreg) init(props properties, env environmentInfo) { wr.props = props wr.env = env } diff --git a/src/segment_winreg_test.go b/src/segment_winreg_test.go index 7021f5a9..f5189a4b 100644 --- a/src/segment_winreg_test.go +++ b/src/segment_winreg_test.go @@ -66,17 +66,14 @@ func TestRegQueryEnabled(t *testing.T) { env := new(MockedEnvironment) env.On("getRuntimeGOOS", nil).Return(windowsPlatform) env.On("getWindowsRegistryKeyValue", tc.Path, tc.Key).Return(tc.Output, tc.Err) - props := &properties{ - values: map[Property]interface{}{ + r := &winreg{ + env: env, + props: map[Property]interface{}{ RegistryPath: tc.Path, RegistryKey: tc.Key, Fallback: tc.Fallback, }, } - r := &winreg{ - env: env, - props: props, - } assert.Equal(t, tc.ExpectedSuccess, r.enabled(), tc.CaseDescription) assert.Equal(t, tc.ExpectedValue, r.string(), tc.CaseDescription) diff --git a/src/segment_ytm.go b/src/segment_ytm.go index 080fe0f8..fdf0e00c 100644 --- a/src/segment_ytm.go +++ b/src/segment_ytm.go @@ -6,7 +6,7 @@ import ( ) type ytm struct { - props *properties + props properties env environmentInfo status playStatus artist string @@ -39,7 +39,7 @@ func (y *ytm) enabled() bool { return err == nil } -func (y *ytm) init(props *properties, env environmentInfo) { +func (y *ytm) init(props properties, env environmentInfo) { y.props = props y.env = env } diff --git a/src/segment_ytm_test.go b/src/segment_ytm_test.go index c0f98bac..9547b72d 100644 --- a/src/segment_ytm_test.go +++ b/src/segment_ytm_test.go @@ -41,15 +41,12 @@ func bootstrapYTMDATest(json string, err error) *ytm { url := "http://127.0.0.1:9863" env := new(MockedEnvironment) env.On("doGet", url+"/query").Return([]byte(json), err) - props := &properties{ - values: map[Property]interface{}{ + ytm := &ytm{ + env: env, + props: map[Property]interface{}{ APIURL: url, }, } - ytm := &ytm{ - env: env, - props: props, - } return ytm }