From 29e019511a91b7fd30d43af627f42760897c5966 Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Sat, 1 Jan 2022 20:08:08 +0100 Subject: [PATCH] refactor: move properties to interface --- docs/docs/contributing-segment.md | 2 +- src/config.go | 14 +++--- src/properties_test.go | 30 ++++++------ src/scm.go | 9 ++-- src/scm_test.go | 6 +-- src/segment.go | 17 ++++++- src/segment_angular.go | 2 +- src/segment_angular_test.go | 2 +- src/segment_aws.go | 4 +- src/segment_aws_test.go | 2 +- src/segment_az.go | 4 +- src/segment_az_functions.go | 2 +- src/segment_az_test.go | 2 +- src/segment_battery.go | 4 +- src/segment_brewfather.go | 4 +- src/segment_brewfather_test.go | 2 +- src/segment_command.go | 4 +- src/segment_command_test.go | 14 +++--- src/segment_crystal.go | 2 +- src/segment_dart.go | 2 +- src/segment_deprecated.go | 24 ++++++---- src/segment_deprecated_test.go | 71 +++++++++++++++-------------- src/segment_dotnet.go | 2 +- src/segment_dotnet_test.go | 2 +- src/segment_executiontime.go | 4 +- src/segment_executiontime_test.go | 16 ++++--- src/segment_exit.go | 4 +- src/segment_exit_test.go | 5 +- src/segment_git_test.go | 27 ++++++----- src/segment_golang.go | 2 +- src/segment_golang_test.go | 2 +- src/segment_ipify.go | 4 +- src/segment_ipify_test.go | 2 +- src/segment_java.go | 2 +- src/segment_java_test.go | 2 +- src/segment_julia.go | 2 +- src/segment_kubectl.go | 4 +- src/segment_kubectl_test.go | 2 +- src/segment_language.go | 2 +- src/segment_language_test.go | 27 ++++++----- src/segment_nbgv.go | 4 +- src/segment_nbgv_test.go | 2 +- src/segment_nightscout.go | 4 +- src/segment_nightscout_test.go | 2 +- src/segment_node.go | 2 +- src/segment_node_test.go | 2 +- src/segment_os.go | 4 +- src/segment_os_test.go | 2 +- src/segment_owm.go | 4 +- src/segment_owm_test.go | 10 ++-- src/segment_path.go | 4 +- src/segment_path_test.go | 16 +++---- src/segment_php.go | 2 +- src/segment_plastic.go | 2 +- src/segment_plastic_test.go | 11 +++-- src/segment_posh_git.go | 4 +- src/segment_python.go | 2 +- src/segment_python_test.go | 4 +- src/segment_root.go | 4 +- src/segment_ruby.go | 2 +- src/segment_ruby_test.go | 2 +- src/segment_rust.go | 2 +- src/segment_session.go | 4 +- src/segment_session_test.go | 2 +- src/segment_shell.go | 4 +- src/segment_shell_test.go | 5 +- src/segment_spotify.go | 4 +- src/segment_spotify_darwin_test.go | 3 +- src/segment_spotify_test.go | 3 ++ src/segment_spotify_windows_test.go | 3 +- src/segment_spotify_wsl_test.go | 3 +- src/segment_sysinfo.go | 4 +- src/segment_sysinfo_test.go | 4 +- src/segment_terraform.go | 4 +- src/segment_terraform_test.go | 3 +- src/segment_test.go | 6 +-- src/segment_text.go | 4 +- src/segment_text_test.go | 2 +- src/segment_time.go | 4 +- src/segment_time_test.go | 2 +- src/segment_wakatime.go | 4 +- src/segment_wakatime_test.go | 2 +- src/segment_wifi.go | 4 +- src/segment_wifi_test.go | 2 +- src/segment_winreg.go | 4 +- src/segment_winreg_test.go | 2 +- src/segment_ytm.go | 4 +- src/segment_ytm_test.go | 5 +- 88 files changed, 283 insertions(+), 233 deletions(-) diff --git a/docs/docs/contributing-segment.md b/docs/docs/contributing-segment.md index fb020d2d..44849fd3 100644 --- a/docs/docs/contributing-segment.md +++ b/docs/docs/contributing-segment.md @@ -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/config.go b/src/config.go index 8a48c93c..7d4d0937 100644 --- a/src/config.go +++ b/src/config.go @@ -188,7 +188,7 @@ func getDefaultConfig(info string) *Config { PowerlineSymbol: "\uE0B0", Background: "#ff479c", Foreground: "#ffffff", - Properties: map[Property]interface{}{ + Properties: properties{ Prefix: " \uE5FF ", Style: "folder", }, @@ -199,7 +199,7 @@ func getDefaultConfig(info string) *Config { PowerlineSymbol: "\uE0B0", Background: "#fffb38", Foreground: "#193549", - Properties: map[Property]interface{}{ + Properties: properties{ FetchStashCount: true, FetchUpstreamIcon: true, }, @@ -210,7 +210,7 @@ func getDefaultConfig(info string) *Config { PowerlineSymbol: "\uE0B0", Background: "#f36943", Foreground: "#193549", - Properties: map[Property]interface{}{ + Properties: properties{ ColorBackground: true, ChargedColor: "#4caf50", ChargingColor: "#40c4ff", @@ -224,7 +224,7 @@ func getDefaultConfig(info string) *Config { PowerlineSymbol: "\uE0B0", Background: "#6CA35E", Foreground: "#ffffff", - Properties: map[Property]interface{}{ + Properties: properties{ Prefix: " \uE718", FetchVersion: false, }, @@ -235,7 +235,7 @@ func getDefaultConfig(info string) *Config { PowerlineSymbol: "\uE0B0", Background: "#0077c2", Foreground: "#ffffff", - Properties: map[Property]interface{}{ + Properties: properties{ Prefix: " \uFCB5 ", }, }, @@ -252,7 +252,7 @@ func getDefaultConfig(info string) *Config { PowerlineSymbol: "\uE0B0", Background: "#ffffff", Foreground: "#111111", - Properties: map[Property]interface{}{ + Properties: properties{ TextProperty: info, }, }, @@ -263,7 +263,7 @@ func getDefaultConfig(info string) *Config { Foreground: "#ffffff", LeadingDiamond: "\uE0B0", TrailingDiamond: "\uE0B4", - Properties: map[Property]interface{}{ + Properties: properties{ DisplayExitCode: false, AlwaysEnabled: true, ErrorColor: "#f1184c", diff --git a/src/properties_test.go b/src/properties_test.go index 3a71be12..ac2bd8ab 100644 --- a/src/properties_test.go +++ b/src/properties_test.go @@ -12,101 +12,101 @@ const ( ) func TestGetString(t *testing.T) { - var properties properties = map[Property]interface{}{TextProperty: expected} + var properties properties = properties{TextProperty: expected} value := properties.getString(TextProperty, "err") assert.Equal(t, expected, value) } func TestGetStringNoEntry(t *testing.T) { - var properties properties = map[Property]interface{}{} + var properties properties = properties{} value := properties.getString(TextProperty, expected) assert.Equal(t, expected, value) } func TestGetStringNoTextEntry(t *testing.T) { - var properties properties = map[Property]interface{}{TextProperty: true} + var properties properties = properties{TextProperty: true} value := properties.getString(TextProperty, expected) assert.Equal(t, expected, value) } func TestGetHexColor(t *testing.T) { expected := expectedColor - var properties properties = map[Property]interface{}{UserColor: expected} + var properties properties = properties{UserColor: expected} value := properties.getColor(UserColor, "#789123") assert.Equal(t, expected, value) } func TestGetColor(t *testing.T) { expected := "yellow" - var properties properties = map[Property]interface{}{UserColor: expected} + var properties properties = properties{UserColor: expected} value := properties.getColor(UserColor, "#789123") assert.Equal(t, expected, value) } func TestDefaultColorWithInvalidColorCode(t *testing.T) { expected := expectedColor - var properties properties = map[Property]interface{}{UserColor: "invalid"} + var properties properties = properties{UserColor: "invalid"} value := properties.getColor(UserColor, expected) assert.Equal(t, expected, value) } func TestDefaultColorWithUnavailableProperty(t *testing.T) { expected := expectedColor - var properties properties = map[Property]interface{}{} + var properties properties = properties{} value := properties.getColor(UserColor, expected) assert.Equal(t, expected, value) } func TestGetPaletteColor(t *testing.T) { expected := "p:red" - var properties properties = map[Property]interface{}{Background: expected} + var properties properties = properties{Background: expected} value := properties.getColor(Background, "white") assert.Equal(t, expected, value) } func TestGetBool(t *testing.T) { expected := true - var properties properties = map[Property]interface{}{DisplayHost: expected} + var properties properties = properties{DisplayHost: expected} value := properties.getBool(DisplayHost, false) assert.True(t, value) } func TestGetBoolPropertyNotInMap(t *testing.T) { - var properties properties = map[Property]interface{}{} + var properties properties = properties{} value := properties.getBool(DisplayHost, false) assert.False(t, value) } func TestGetBoolInvalidProperty(t *testing.T) { - var properties properties = map[Property]interface{}{DisplayHost: "borked"} + var properties properties = properties{DisplayHost: "borked"} value := properties.getBool(DisplayHost, false) assert.False(t, value) } func TestGetFloat64(t *testing.T) { expected := float64(1337) - var properties properties = map[Property]interface{}{"myfloat": expected} + var properties properties = properties{"myfloat": expected} value := properties.getFloat64("myfloat", 9001) assert.Equal(t, expected, value) } func TestGetFloat64PropertyNotInMap(t *testing.T) { expected := float64(1337) - var properties properties = map[Property]interface{}{} + var properties properties = properties{} value := properties.getFloat64(ThresholdProperty, expected) assert.Equal(t, expected, value) } func TestGetFloat64InvalidStringProperty(t *testing.T) { expected := float64(1337) - var properties properties = map[Property]interface{}{ThresholdProperty: "invalid"} + var properties properties = properties{ThresholdProperty: "invalid"} value := properties.getFloat64(ThresholdProperty, expected) assert.Equal(t, expected, value) } func TestGetFloat64InvalidBoolProperty(t *testing.T) { expected := float64(1337) - var properties properties = map[Property]interface{}{ThresholdProperty: true} + var properties properties = properties{ThresholdProperty: true} value := properties.getFloat64(ThresholdProperty, expected) assert.Equal(t, expected, value) } diff --git a/src/scm.go b/src/scm.go index b3aa581e..99237ff0 100644 --- a/src/scm.go +++ b/src/scm.go @@ -35,7 +35,7 @@ func (s *ScmStatus) String() string { } type scm struct { - props properties + props Properties env environmentInfo } @@ -48,7 +48,7 @@ const ( FullBranchPath Property = "full_branch_path" ) -func (s *scm) init(props properties, env environmentInfo) { +func (s *scm) init(props Properties, env environmentInfo) { s.props = props s.env = env } @@ -68,11 +68,10 @@ func (s *scm) truncateBranch(branch string) string { } func (s *scm) shouldIgnoreRootRepository(rootDir string) bool { - value, ok := s.props[ExcludeFolders] - if !ok { + excludedFolders := s.props.getStringArray(ExcludeFolders, []string{}) + if len(excludedFolders) == 0 { return false } - excludedFolders := parseStringArray(value) return dirMatchesOneOf(s.env, rootDir, excludedFolders) } diff --git a/src/scm_test.go b/src/scm_test.go index e0836eee..cc58e0d0 100644 --- a/src/scm_test.go +++ b/src/scm_test.go @@ -104,7 +104,7 @@ func TestTruncateBranch(t *testing.T) { } for _, tc := range cases { - var props properties = map[Property]interface{}{ + props := properties{ BranchMaxLength: tc.MaxLength, FullBranchPath: tc.FullBranch, } @@ -140,7 +140,7 @@ func TestTruncateBranchWithSymbol(t *testing.T) { } for _, tc := range cases { - var props properties = map[Property]interface{}{ + props := properties{ BranchMaxLength: tc.MaxLength, TruncateSymbol: tc.TruncateSymbol, FullBranchPath: tc.FullBranch, @@ -167,7 +167,7 @@ func TestScmShouldIgnoreRootRepository(t *testing.T) { } for _, tc := range cases { - var props properties = map[Property]interface{}{ + props := properties{ ExcludeFolders: []string{ "/home/bill", "/home/gates.*", diff --git a/src/segment.go b/src/segment.go index 2cdb8eee..4c7478db 100644 --- a/src/segment.go +++ b/src/segment.go @@ -37,11 +37,26 @@ type SegmentTiming struct { stringDuration time.Duration } +type Properties interface { + getColor(property Property, defaultColor string) string + getBool(property Property, defaultValue bool) bool + getString(property Property, defaultValue string) string + getFloat64(property Property, defaultValue float64) float64 + getInt(property Property, defaultValue int) int + getKeyValueMap(property Property, defaultValue map[string]string) map[string]string + getStringArray(property Property, defaultValue []string) []string + // for legacy purposes + getOneOfBool(property, legacyProperty Property, defaultValue bool) bool + getOneOfString(property, legacyProperty Property, defaultValue string) string + hasOneOf(properties ...Property) bool + set(property Property, value interface{}) +} + // SegmentWriter is the interface used to define what and if to write to the prompt 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 diff --git a/src/segment_angular.go b/src/segment_angular.go index fb6fe2ca..2810007c 100644 --- a/src/segment_angular.go +++ b/src/segment_angular.go @@ -13,7 +13,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_angular_test.go b/src/segment_angular_test.go index 6a5d9b4f..b89118f6 100644 --- a/src/segment_angular_test.go +++ b/src/segment_angular_test.go @@ -30,7 +30,7 @@ func TestAngularCliVersionDisplayed(t *testing.T) { env.On("hasFilesInDir", "/usr/home/dev/my-app/node_modules/@angular/core", "package.json").Return(true) env.On("getFileContent", "/usr/home/dev/my-app/node_modules/@angular/core/package.json").Return(ta.Version) - var props properties = map[Property]interface{}{} + props := properties{} angular := &angular{} angular.init(props, env) assert.True(t, angular.enabled(), fmt.Sprintf("Failed in case: %s", ta.Case)) diff --git a/src/segment_aws.go b/src/segment_aws.go index 6d856454..87c10fa9 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 48950b8c..9ccf8ffe 100644 --- a/src/segment_aws_test.go +++ b/src/segment_aws_test.go @@ -54,7 +54,7 @@ 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") - var props properties = map[Property]interface{}{ + props := properties{ DisplayDefault: tc.DisplayDefault, } if tc.Template != "" { diff --git a/src/segment_az.go b/src/segment_az.go index 12c21018..d8c91347 100644 --- a/src/segment_az.go +++ b/src/segment_az.go @@ -7,7 +7,7 @@ import ( ) type az struct { - props properties + props Properties env environmentInfo AzureSubscription @@ -91,7 +91,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 } diff --git a/src/segment_az_functions.go b/src/segment_az_functions.go index 397fc2ae..16e6bf96 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 e6a412ce..7d81105f 100644 --- a/src/segment_az_test.go +++ b/src/segment_az_test.go @@ -60,7 +60,7 @@ func TestAzSegment(t *testing.T) { env.On("getFileContent", filepath.Join(home, ".azure/azureProfile.json")).Return(azureProfile) env.On("getFileContent", filepath.Join(home, ".azure/AzureRmContext.json")).Return(azureRmContext) - var props properties = map[Property]interface{}{ + props := properties{ SegmentTemplate: tc.Template, } az := &az{ diff --git a/src/segment_battery.go b/src/segment_battery.go index 8449c616..50bc042a 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_brewfather.go b/src/segment_brewfather.go index d8f29eb4..58c89b12 100644 --- a/src/segment_brewfather.go +++ b/src/segment_brewfather.go @@ -13,7 +13,7 @@ import ( // segment struct, makes templating easier type brewfather struct { - props properties + props Properties env environmentInfo Batch @@ -335,7 +335,7 @@ func (bf *brewfather) SGToPlato(sg float64) float64 { return math.Round(100*((135.997*sg*sg*sg)-(630.272*sg*sg)+(1111.14*sg)-616.868)) / 100 // 2 decimal places } -func (bf *brewfather) init(props properties, env environmentInfo) { +func (bf *brewfather) init(props Properties, env environmentInfo) { bf.props = props bf.env = env } diff --git a/src/segment_brewfather_test.go b/src/segment_brewfather_test.go index 62d2afa0..45a6b7c9 100644 --- a/src/segment_brewfather_test.go +++ b/src/segment_brewfather_test.go @@ -137,7 +137,7 @@ func TestBrewfatherSegment(t *testing.T) { for _, tc := range cases { env := &MockedEnvironment{} - var props properties = map[Property]interface{}{ + props := properties{ CacheTimeout: tc.CacheTimeout, BFBatchID: BFFakeBatchID, BFAPIKey: "FAKE", diff --git a/src/segment_command.go b/src/segment_command.go index 261638de..13f4093a 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 952ac783..66502173 100644 --- a/src/segment_command_test.go +++ b/src/segment_command_test.go @@ -14,7 +14,7 @@ func TestExecuteCommand(t *testing.T) { env.init(&args{ Debug: &debug, }) - var props properties = map[Property]interface{}{ + props := properties{ Command: "echo hello", } c := &command{ @@ -32,7 +32,7 @@ func TestExecuteMultipleCommandsOrFirst(t *testing.T) { env.init(&args{ Debug: &debug, }) - var props properties = map[Property]interface{}{ + props := properties{ Command: "exit 1 || echo hello", } c := &command{ @@ -50,7 +50,7 @@ func TestExecuteMultipleCommandsOrSecond(t *testing.T) { env.init(&args{ Debug: &debug, }) - var props properties = map[Property]interface{}{ + props := properties{ Command: "echo hello || echo world", } c := &command{ @@ -68,7 +68,7 @@ func TestExecuteMultipleCommandsAnd(t *testing.T) { env.init(&args{ Debug: &debug, }) - var props properties = map[Property]interface{}{ + props := properties{ Command: "echo hello && echo world", } c := &command{ @@ -86,7 +86,7 @@ func TestExecuteSingleCommandEmpty(t *testing.T) { env.init(&args{ Debug: &debug, }) - var props properties = map[Property]interface{}{ + props := properties{ Command: "", } c := &command{ @@ -119,7 +119,7 @@ func TestExecuteMultipleCommandsAndDisabled(t *testing.T) { env.init(&args{ Debug: &debug, }) - var props properties = map[Property]interface{}{ + props := properties{ Command: "echo && echo", } c := &command{ @@ -136,7 +136,7 @@ func TestExecuteMultipleCommandsOrDisabled(t *testing.T) { env.init(&args{ Debug: &debug, }) - var props properties = map[Property]interface{}{ + props := properties{ Command: "echo|| echo", } c := &command{ diff --git a/src/segment_crystal.go b/src/segment_crystal.go index caef827a..e92589c4 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 a653f930..f7c48be1 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 6375ea76..68de7095 100644 --- a/src/segment_deprecated.go +++ b/src/segment_deprecated.go @@ -42,6 +42,10 @@ func (p properties) hasOneOf(properties ...Property) bool { return false } +func (p properties) set(property Property, value interface{}) { + p[property] = value +} + // GIT Segement const ( @@ -117,9 +121,9 @@ func (g *git) deprecatedString(statusColorsEnabled bool) string { func (g *git) SetStatusColor() { if g.props.getBool(ColorBackground, true) { - g.props[BackgroundOverride] = g.getStatusColor(g.props.getColor(BackgroundOverride, "")) + g.props.set(BackgroundOverride, g.getStatusColor(g.props.getColor(BackgroundOverride, ""))) } else { - g.props[ForegroundOverride] = g.getStatusColor(g.props.getColor(ForegroundOverride, "")) + g.props.set(ForegroundOverride, g.getStatusColor(g.props.getColor(ForegroundOverride, ""))) } } @@ -178,10 +182,10 @@ const ( func (e *exit) deprecatedString() string { colorBackground := e.props.getBool(ColorBackground, false) if e.Code != 0 && !colorBackground { - e.props[ForegroundOverride] = e.props.getColor(ErrorColor, e.props.getColor(ForegroundOverride, "")) + e.props.set(ForegroundOverride, e.props.getColor(ErrorColor, e.props.getColor(ForegroundOverride, ""))) } if e.Code != 0 && colorBackground { - e.props[BackgroundOverride] = e.props.getColor(ErrorColor, e.props.getColor(BackgroundOverride, "")) + e.props.set(BackgroundOverride, e.props.getColor(ErrorColor, e.props.getColor(BackgroundOverride, ""))) } if e.Code == 0 { return e.props.getString(SuccessIcon, "") @@ -228,9 +232,9 @@ func (b *batt) colorSegment() { } colorBackground := b.props.getBool(ColorBackground, false) if colorBackground { - b.props[BackgroundOverride] = b.props.getColor(colorProperty, b.props.getColor(BackgroundOverride, "")) + b.props.set(BackgroundOverride, b.props.getColor(colorProperty, b.props.getColor(BackgroundOverride, ""))) } else { - b.props[ForegroundOverride] = b.props.getColor(colorProperty, b.props.getColor(ForegroundOverride, "")) + b.props.set(ForegroundOverride, b.props.getColor(colorProperty, b.props.getColor(ForegroundOverride, ""))) } } @@ -383,10 +387,10 @@ func (l *language) string() string { func (l *language) colorMismatch() { if l.props.getBool(ColorBackground, false) { - l.props[BackgroundOverride] = l.props.getColor(VersionMismatchColor, l.props.getColor(BackgroundOverride, "")) + l.props.set(BackgroundOverride, l.props.getColor(VersionMismatchColor, l.props.getColor(BackgroundOverride, ""))) return } - l.props[ForegroundOverride] = l.props.getColor(VersionMismatchColor, l.props.getColor(ForegroundOverride, "")) + l.props.set(ForegroundOverride, l.props.getColor(VersionMismatchColor, l.props.getColor(ForegroundOverride, ""))) } // Python @@ -417,7 +421,7 @@ const ( // Environment Variable type envvar struct { - props properties + props Properties env environmentInfo Value string } @@ -450,7 +454,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_deprecated_test.go b/src/segment_deprecated_test.go index a86b9844..1c00b014 100644 --- a/src/segment_deprecated_test.go +++ b/src/segment_deprecated_test.go @@ -17,7 +17,11 @@ func TestGetStatusDetailStringDefault(t *testing.T) { Added: 1, }, } - g := &git{} + g := &git{ + scm: scm{ + props: properties{}, + }, + } assert.Equal(t, expected, g.getStatusDetailString(status, WorkingColor, LocalWorkingIcon, "icon")) } @@ -28,7 +32,7 @@ func TestGetStatusDetailStringDefaultColorOverride(t *testing.T) { Added: 1, }, } - var props properties = map[Property]interface{}{ + props := properties{ WorkingColor: "#123456", } g := &git{ @@ -46,7 +50,7 @@ func TestGetStatusDetailStringDefaultColorOverrideAndIconColorOverride(t *testin Added: 1, }, } - var props properties = map[Property]interface{}{ + props := properties{ WorkingColor: "#123456", LocalWorkingIcon: "<#789123>work", } @@ -65,7 +69,7 @@ func TestGetStatusDetailStringDefaultColorOverrideNoIconColorOverride(t *testing Added: 1, }, } - var props properties = map[Property]interface{}{ + props := properties{ WorkingColor: "#123456", LocalWorkingIcon: "work", } @@ -84,7 +88,7 @@ func TestGetStatusDetailStringNoStatus(t *testing.T) { Added: 1, }, } - var props properties = map[Property]interface{}{ + props := properties{ DisplayStatusDetail: false, } g := &git{ @@ -102,7 +106,7 @@ func TestGetStatusDetailStringNoStatusColorOverride(t *testing.T) { Added: 1, }, } - var props properties = map[Property]interface{}{ + props := properties{ DisplayStatusDetail: false, WorkingColor: "#123456", } @@ -116,7 +120,7 @@ func TestGetStatusDetailStringNoStatusColorOverride(t *testing.T) { func TestGetStatusColorLocalChangesStaging(t *testing.T) { expected := changesColor - var props properties = map[Property]interface{}{ + props := properties{ LocalChangesColor: expected, } g := &git{ @@ -135,7 +139,7 @@ func TestGetStatusColorLocalChangesStaging(t *testing.T) { func TestGetStatusColorLocalChangesWorking(t *testing.T) { expected := changesColor - var props properties = map[Property]interface{}{ + props := properties{ LocalChangesColor: expected, } g := &git{ @@ -154,7 +158,7 @@ func TestGetStatusColorLocalChangesWorking(t *testing.T) { func TestGetStatusColorAheadAndBehind(t *testing.T) { expected := changesColor - var props properties = map[Property]interface{}{ + props := properties{ AheadAndBehindColor: expected, } g := &git{ @@ -171,7 +175,7 @@ func TestGetStatusColorAheadAndBehind(t *testing.T) { func TestGetStatusColorAhead(t *testing.T) { expected := changesColor - var props properties = map[Property]interface{}{ + props := properties{ AheadColor: expected, } g := &git{ @@ -188,7 +192,7 @@ func TestGetStatusColorAhead(t *testing.T) { func TestGetStatusColorBehind(t *testing.T) { expected := changesColor - var props properties = map[Property]interface{}{ + props := properties{ BehindColor: expected, } g := &git{ @@ -205,7 +209,7 @@ func TestGetStatusColorBehind(t *testing.T) { func TestGetStatusColorDefault(t *testing.T) { expected := changesColor - var props properties = map[Property]interface{}{ + props := properties{ BehindColor: changesColor, } g := &git{ @@ -222,7 +226,7 @@ func TestGetStatusColorDefault(t *testing.T) { func TestSetStatusColorForeground(t *testing.T) { expected := changesColor - var props properties = map[Property]interface{}{ + props := properties{ LocalChangesColor: changesColor, ColorBackground: false, } @@ -238,12 +242,12 @@ func TestSetStatusColorForeground(t *testing.T) { Working: &GitStatus{}, } g.SetStatusColor() - assert.Equal(t, expected, g.props[ForegroundOverride]) + assert.Equal(t, expected, g.props.getColor(ForegroundOverride, "")) } func TestSetStatusColorBackground(t *testing.T) { expected := changesColor - var props properties = map[Property]interface{}{ + props := properties{ LocalChangesColor: changesColor, ColorBackground: true, } @@ -259,7 +263,7 @@ func TestSetStatusColorBackground(t *testing.T) { }, } g.SetStatusColor() - assert.Equal(t, expected, g.props[BackgroundOverride]) + assert.Equal(t, expected, g.props.getColor(BackgroundOverride, "")) } func TestStatusColorsWithoutDisplayStatus(t *testing.T) { @@ -279,21 +283,22 @@ func TestStatusColorsWithoutDisplayStatus(t *testing.T) { env.On("hasFilesInDir", "", "sequencer/todo").Return(false) env.mockGitCommand("", "describe", "--tags", "--exact-match") env.mockGitCommand(status, "status", "-unormal", "--branch", "--porcelain=2") + props := properties{ + DisplayStatus: false, + StatusColorsEnabled: true, + LocalChangesColor: expected, + } g := &git{ scm: scm{ - env: env, - props: map[Property]interface{}{ - DisplayStatus: false, - StatusColorsEnabled: true, - LocalChangesColor: expected, - }, + env: env, + props: props, }, gitWorkingFolder: "", } g.Working = &GitStatus{} g.Staging = &GitStatus{} g.string() - assert.Equal(t, expected, g.props[BackgroundOverride]) + assert.Equal(t, expected, g.props.getColor(BackgroundOverride, "")) } // EXIT Segement @@ -320,7 +325,7 @@ func TestExitWriterDeprecatedString(t *testing.T) { for _, tc := range cases { env := new(MockedEnvironment) env.On("lastErrorCode", nil).Return(tc.ExitCode) - var props properties = map[Property]interface{}{ + props := properties{ SuccessIcon: tc.SuccessIcon, ErrorIcon: tc.ErrorIcon, DisplayExitCode: tc.DisplayExitCode, @@ -424,7 +429,7 @@ func TestBatterySegmentSingle(t *testing.T) { for _, tc := range cases { env := &MockedEnvironment{} - var props properties = map[Property]interface{}{ + props := properties{ ChargingIcon: "charging ", ChargedIcon: "charged ", DischargingIcon: "going down ", @@ -455,9 +460,9 @@ func TestBatterySegmentSingle(t *testing.T) { if len(tc.ExpectedColor) == 0 { continue } - actualColor := b.props[ForegroundOverride] + actualColor := b.props.getColor(ForegroundOverride, "") if tc.ColorBackground { - actualColor = b.props[BackgroundOverride] + actualColor = b.props.getColor(BackgroundOverride, "") } assert.Equal(t, tc.ExpectedColor, actualColor, tc.Case) } @@ -637,7 +642,7 @@ 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) - var props properties = map[Property]interface{}{ + props := properties{ UserInfoSeparator: " at ", SSHIcon: "ssh ", DefaultUserName: tc.DefaultUserName, @@ -674,7 +679,7 @@ func TestLanguageVersionMismatch(t *testing.T) { {Case: "No mismatch", Enabled: true, Mismatch: false}, } for _, tc := range cases { - props := map[Property]interface{}{ + props := properties{ EnableVersionMismatch: tc.Enabled, VersionMismatchColor: tc.ExpectedColor, ColorBackground: tc.ColorBackground, @@ -709,7 +714,7 @@ 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[BackgroundOverride], tc.Case) + assert.Equal(t, tc.ExpectedColor, lang.props.getColor(BackgroundOverride, ""), tc.Case) return } assert.Equal(t, tc.ExpectedColor, lang.props.getColor(ForegroundOverride, ""), tc.Case) @@ -751,7 +756,7 @@ 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") - var props properties = map[Property]interface{}{ + props := properties{ FetchVersion: tc.FetchVersion, DisplayVirtualEnv: true, DisplayDefault: tc.DisplayDefault, @@ -772,7 +777,7 @@ func TestEnvvarAvailable(t *testing.T) { env.On("getenv", name).Return(expected) e := &envvar{ env: env, - props: map[Property]interface{}{ + props: properties{ VarName: name, }, } @@ -787,7 +792,7 @@ func TestEnvvarNotAvailable(t *testing.T) { env.On("getenv", name).Return(expected) e := &envvar{ env: env, - props: map[Property]interface{}{ + props: properties{ VarName: name, }, } diff --git a/src/segment_dotnet.go b/src/segment_dotnet.go index 50fb4255..7869743b 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 e862b1e1..6266bf33 100644 --- a/src/segment_dotnet_test.go +++ b/src/segment_dotnet_test.go @@ -28,7 +28,7 @@ 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") - var props properties = map[Property]interface{}{ + props := properties{ FetchVersion: args.displayVersion, UnsupportedDotnetVersionIcon: args.unsupportedIcon, } diff --git a/src/segment_executiontime.go b/src/segment_executiontime.go index 680942ed..d3791837 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 5e5edbf5..f4b6f787 100644 --- a/src/segment_executiontime_test.go +++ b/src/segment_executiontime_test.go @@ -11,7 +11,8 @@ func TestExecutionTimeWriterDefaultThresholdEnabled(t *testing.T) { env := new(MockedEnvironment) env.On("executionTime", nil).Return(1337) executionTime := &executiontime{ - env: env, + env: env, + props: properties{}, } assert.True(t, executionTime.enabled()) } @@ -20,7 +21,8 @@ func TestExecutionTimeWriterDefaultThresholdDisabled(t *testing.T) { env := new(MockedEnvironment) env.On("executionTime", nil).Return(1) executionTime := &executiontime{ - env: env, + env: env, + props: properties{}, } assert.False(t, executionTime.enabled()) } @@ -28,7 +30,7 @@ func TestExecutionTimeWriterDefaultThresholdDisabled(t *testing.T) { func TestExecutionTimeWriterCustomThresholdEnabled(t *testing.T) { env := new(MockedEnvironment) env.On("executionTime", nil).Return(99) - var props properties = map[Property]interface{}{ + props := properties{ ThresholdProperty: float64(10), } executionTime := &executiontime{ @@ -41,7 +43,7 @@ func TestExecutionTimeWriterCustomThresholdEnabled(t *testing.T) { func TestExecutionTimeWriterCustomThresholdDisabled(t *testing.T) { env := new(MockedEnvironment) env.On("executionTime", nil).Return(99) - var props properties = map[Property]interface{}{ + props := properties{ ThresholdProperty: float64(100), } executionTime := &executiontime{ @@ -57,7 +59,8 @@ func TestExecutionTimeWriterDuration(t *testing.T) { env := new(MockedEnvironment) env.On("executionTime", nil).Return(input) executionTime := &executiontime{ - env: env, + env: env, + props: properties{}, } executionTime.enabled() assert.Equal(t, expected, executionTime.FormattedMs) @@ -69,7 +72,8 @@ func TestExecutionTimeWriterDuration2(t *testing.T) { env := new(MockedEnvironment) env.On("executionTime", nil).Return(input) executionTime := &executiontime{ - env: env, + env: env, + props: properties{}, } executionTime.enabled() assert.Equal(t, expected, executionTime.FormattedMs) diff --git a/src/segment_exit.go b/src/segment_exit.go index 6395a779..dc988e0d 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 7fe1a6ed..8dfdb6f9 100644 --- a/src/segment_exit_test.go +++ b/src/segment_exit_test.go @@ -20,7 +20,8 @@ func TestExitWriterEnabled(t *testing.T) { env := new(MockedEnvironment) env.On("lastErrorCode", nil).Return(tc.ExitCode) e := &exit{ - env: env, + env: env, + props: properties{}, } assert.Equal(t, tc.Expected, e.enabled()) } @@ -76,7 +77,7 @@ func TestExitWriterTemplateString(t *testing.T) { for _, tc := range cases { env := new(MockedEnvironment) env.On("lastErrorCode", nil).Return(tc.ExitCode) - var props properties = map[Property]interface{}{ + props := properties{ SegmentTemplate: tc.Template, } e := &exit{ diff --git a/src/segment_git_test.go b/src/segment_git_test.go index ed0ff1b6..9fc3a0ef 100644 --- a/src/segment_git_test.go +++ b/src/segment_git_test.go @@ -21,7 +21,8 @@ func TestEnabledGitNotFound(t *testing.T) { env.On("isWsl", nil).Return(false) g := &git{ scm: scm{ - env: env, + env: env, + props: properties{}, }, } assert.False(t, g.enabled()) @@ -41,7 +42,8 @@ func TestEnabledInWorkingDirectory(t *testing.T) { env.On("hasParentFilePath", ".git").Return(fileInfo, nil) g := &git{ scm: scm{ - env: env, + env: env, + props: properties{}, }, } assert.True(t, g.enabled()) @@ -64,7 +66,8 @@ func TestEnabledInWorkingTree(t *testing.T) { env.On("getFileContent", "/dev/real_folder/.git/worktrees/folder_worktree/gitdir").Return("/dev/folder_worktree.git\n") g := &git{ scm: scm{ - env: env, + env: env, + props: properties{}, }, } assert.True(t, g.enabled()) @@ -88,7 +91,8 @@ func TestEnabledInSubmodule(t *testing.T) { env.On("getFileContent", "/dev/parent/.git/modules/test-submodule").Return("/dev/folder_worktree.git\n") g := &git{ scm: scm{ - env: env, + env: env, + props: properties{}, }, } assert.True(t, g.enabled()) @@ -107,7 +111,8 @@ func TestGetGitOutputForCommand(t *testing.T) { env.On("getRuntimeGOOS", nil).Return("unix") g := &git{ scm: scm{ - env: env, + env: env, + props: properties{}, }, } got := g.getGitCommandOutput(commandArgs...) @@ -256,7 +261,7 @@ func TestSetGitHEADContextClean(t *testing.T) { g := &git{ scm: scm{ env: env, - props: map[Property]interface{}{ + props: properties{ BranchIcon: "branch ", CommitIcon: "commit ", RebaseIcon: "rebase ", @@ -298,7 +303,7 @@ func TestSetPrettyHEADName(t *testing.T) { g := &git{ scm: scm{ env: env, - props: map[Property]interface{}{ + props: properties{ BranchIcon: "branch ", CommitIcon: "commit ", TagIcon: "tag ", @@ -476,7 +481,7 @@ 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") - var props properties = map[Property]interface{}{ + props := properties{ GithubIcon: "GH", GitlabIcon: "GL", BitbucketIcon: "BB", @@ -512,7 +517,7 @@ func TestGetBranchStatus(t *testing.T) { } for _, tc := range cases { - var props properties = map[Property]interface{}{ + props := properties{ BranchAheadIcon: "up", BranchBehindIcon: "down", BranchIdenticalIcon: "equal", @@ -544,7 +549,7 @@ func TestShouldIgnoreRootRepository(t *testing.T) { } for _, tc := range cases { - var props properties = map[Property]interface{}{ + props := properties{ ExcludeFolders: []string{ "/home/bill", "/home/gates.*", @@ -730,7 +735,7 @@ func TestGitTemplateString(t *testing.T) { } for _, tc := range cases { - var props properties = map[Property]interface{}{ + props := properties{ FetchStatus: true, } tc.Git.props = props diff --git a/src/segment_golang.go b/src/segment_golang.go index d608dee5..692c839f 100644 --- a/src/segment_golang.go +++ b/src/segment_golang.go @@ -16,7 +16,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 d1e93371..c8a411a0 100644 --- a/src/segment_golang_test.go +++ b/src/segment_golang_test.go @@ -23,7 +23,7 @@ func getMockedLanguageEnv(params *mockedLanguageParams) (*MockedEnvironment, pro env.On("hasFiles", params.extension).Return(true) env.On("getcwd", nil).Return("/usr/home/project") env.On("homeDir", nil).Return("/usr/home") - var props properties = map[Property]interface{}{ + props := properties{ FetchVersion: true, } return env, props diff --git a/src/segment_ipify.go b/src/segment_ipify.go index 26c323ef..fa5455d6 100644 --- a/src/segment_ipify.go +++ b/src/segment_ipify.go @@ -1,7 +1,7 @@ package main type ipify struct { - props properties + props Properties env environmentInfo IP string } @@ -66,7 +66,7 @@ func (i *ipify) getResult() (string, error) { return response, nil } -func (i *ipify) init(props properties, env environmentInfo) { +func (i *ipify) init(props Properties, env environmentInfo) { i.props = props i.env = env } diff --git a/src/segment_ipify_test.go b/src/segment_ipify_test.go index 7b0ef972..4b211662 100644 --- a/src/segment_ipify_test.go +++ b/src/segment_ipify_test.go @@ -43,7 +43,7 @@ func TestIpifySegment(t *testing.T) { for _, tc := range cases { env := &MockedEnvironment{} - var props properties = map[Property]interface{}{ + props := properties{ CacheTimeout: 0, } diff --git a/src/segment_java.go b/src/segment_java.go index c3aa2ba9..03cc49d1 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 590ba032..c60afc6f 100644 --- a/src/segment_java_test.go +++ b/src/segment_java_test.go @@ -66,7 +66,7 @@ func TestJava(t *testing.T) { } else { env.On("getenv", "JAVA_HOME").Return("") } - var props properties = map[Property]interface{}{ + props := properties{ FetchVersion: true, } j := &java{} diff --git a/src/segment_julia.go b/src/segment_julia.go index b67f9599..5ea75adb 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 71d29eaf..cc79fcd7 100644 --- a/src/segment_kubectl.go +++ b/src/segment_kubectl.go @@ -10,7 +10,7 @@ import ( const ParseKubeConfig Property = "parse_kubeconfig" type kubectl struct { - props properties + props Properties env environmentInfo Context string KubeContext @@ -44,7 +44,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 34d69f4a..f97a5433 100644 --- a/src/segment_kubectl_test.go +++ b/src/segment_kubectl_test.go @@ -128,7 +128,7 @@ func TestKubectlSegment(t *testing.T) { k := &kubectl{ env: env, - props: map[Property]interface{}{ + props: properties{ SegmentTemplate: tc.Template, DisplayError: tc.DisplayError, ParseKubeConfig: tc.ParseKubeConfig, diff --git a/src/segment_language.go b/src/segment_language.go index 95024540..888ffda6 100644 --- a/src/segment_language.go +++ b/src/segment_language.go @@ -47,7 +47,7 @@ func (c *cmd) parse(versionInfo string) (*version, error) { } type language struct { - props properties + props Properties env environmentInfo extensions []string commands []*cmd diff --git a/src/segment_language_test.go b/src/segment_language_test.go index d5c0f6a1..ba80daef 100644 --- a/src/segment_language_test.go +++ b/src/segment_language_test.go @@ -20,7 +20,7 @@ type languageArgs struct { enabledCommands []string versionURLTemplate string expectedError error - properties map[Property]interface{} + properties Properties matchesVersionFile matchesVersionFile inHome bool } @@ -50,6 +50,9 @@ func bootStrapLanguageTest(args *languageArgs) *language { } env.On("getcwd", nil).Return(cwd) env.On("homeDir", nil).Return(home) + if args.properties == nil { + args.properties = properties{} + } l := &language{ props: args.properties, env: env, @@ -78,7 +81,7 @@ func TestLanguageFilesFoundButNoCommandAndVersionAndDisplayVersion(t *testing.T) } func TestLanguageFilesFoundButNoCommandAndVersionAndDontDisplayVersion(t *testing.T) { - props := map[Property]interface{}{ + props := properties{ FetchVersion: false, } args := &languageArgs{ @@ -228,7 +231,7 @@ func TestLanguageEnabledAllExtensionsFound(t *testing.T) { } func TestLanguageEnabledNoVersion(t *testing.T) { - props := map[Property]interface{}{ + props := properties{ FetchVersion: false, } args := &languageArgs{ @@ -251,7 +254,7 @@ func TestLanguageEnabledNoVersion(t *testing.T) { } func TestLanguageEnabledMissingCommand(t *testing.T) { - props := map[Property]interface{}{ + props := properties{ FetchVersion: false, } args := &languageArgs{ @@ -268,7 +271,7 @@ func TestLanguageEnabledMissingCommand(t *testing.T) { } func TestLanguageEnabledNoVersionData(t *testing.T) { - props := map[Property]interface{}{ + props := properties{ FetchVersion: true, } args := &languageArgs{ @@ -292,7 +295,7 @@ func TestLanguageEnabledNoVersionData(t *testing.T) { func TestLanguageEnabledMissingCommandCustomText(t *testing.T) { expected := "missing" - props := map[Property]interface{}{ + props := properties{ MissingCommandText: expected, } args := &languageArgs{ @@ -309,7 +312,7 @@ func TestLanguageEnabledMissingCommandCustomText(t *testing.T) { } func TestLanguageEnabledMissingCommandCustomTextHideError(t *testing.T) { - props := map[Property]interface{}{ + props := properties{ MissingCommandText: "missing", DisplayError: false, } @@ -349,7 +352,7 @@ func TestLanguageEnabledCommandExitCode(t *testing.T) { } func TestLanguageHyperlinkEnabled(t *testing.T) { - props := map[Property]interface{}{ + props := properties{ EnableHyperlink: true, } args := &languageArgs{ @@ -378,7 +381,7 @@ func TestLanguageHyperlinkEnabled(t *testing.T) { } func TestLanguageHyperlinkEnabledWrongRegex(t *testing.T) { - props := map[Property]interface{}{ + props := properties{ EnableHyperlink: true, } args := &languageArgs{ @@ -407,7 +410,7 @@ func TestLanguageHyperlinkEnabledWrongRegex(t *testing.T) { } func TestLanguageHyperlinkEnabledLessParamInTemplate(t *testing.T) { - props := map[Property]interface{}{ + props := properties{ EnableHyperlink: true, } args := &languageArgs{ @@ -445,7 +448,7 @@ func TestLanguageEnabledInHome(t *testing.T) { {Case: "Context disabled", HomeEnabled: false, ExpectedEnabled: false}, } for _, tc := range cases { - props := map[Property]interface{}{ + props := properties{ HomeEnabled: tc.HomeEnabled, } args := &languageArgs{ @@ -469,7 +472,7 @@ func TestLanguageEnabledInHome(t *testing.T) { } func TestLanguageHyperlinkEnabledMoreParamInTemplate(t *testing.T) { - props := map[Property]interface{}{ + props := properties{ EnableHyperlink: true, } args := &languageArgs{ diff --git a/src/segment_nbgv.go b/src/segment_nbgv.go index d4af63b9..82011014 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 f55b1c52..df3c9141 100644 --- a/src/segment_nbgv_test.go +++ b/src/segment_nbgv_test.go @@ -62,7 +62,7 @@ func TestNbgv(t *testing.T) { env.On("runCommand", "nbgv", []string{"get-version", "--format=json"}).Return(tc.Response, tc.Error) nbgv := &nbgv{ env: env, - props: map[Property]interface{}{ + props: properties{ SegmentTemplate: tc.SegmentTemplate, }, } diff --git a/src/segment_nightscout.go b/src/segment_nightscout.go index 521d6857..677deed9 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 2d7f5ddd..4b19575c 100644 --- a/src/segment_nightscout_test.go +++ b/src/segment_nightscout_test.go @@ -130,7 +130,7 @@ func TestNSSegment(t *testing.T) { for _, tc := range cases { env := &MockedEnvironment{} - var props properties = map[Property]interface{}{ + props := properties{ CacheTimeout: tc.CacheTimeout, URL: "FAKE", } diff --git a/src/segment_node.go b/src/segment_node.go index 6c7203bf..6de82b4a 100644 --- a/src/segment_node.go +++ b/src/segment_node.go @@ -26,7 +26,7 @@ func (n *node) string() string { return n.language.renderTemplate(segmentTemplate, n) } -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 239c509b..0fe70963 100644 --- a/src/segment_node_test.go +++ b/src/segment_node_test.go @@ -67,7 +67,7 @@ func TestNodeInContext(t *testing.T) { node := &node{ language: language{ env: env, - props: map[Property]interface{}{ + props: properties{ YarnIcon: "yarn", NPMIcon: "npm", DisplayPackageManager: tc.PkgMgrEnabled, diff --git a/src/segment_os.go b/src/segment_os.go index 37a31edf..7ca5b85d 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 61565ed7..3ba540a3 100644 --- a/src/segment_os_test.go +++ b/src/segment_os_test.go @@ -66,7 +66,7 @@ func TestOSInfo(t *testing.T) { env.On("getPlatform", nil).Return(tc.Platform) osInfo := &osInfo{ env: env, - props: map[Property]interface{}{ + props: properties{ WSL: "WSL", WSLSeparator: " at ", DisplayDistroName: tc.DisplayDistroName, diff --git a/src/segment_owm.go b/src/segment_owm.go index eba76435..89f9eedb 100644 --- a/src/segment_owm.go +++ b/src/segment_owm.go @@ -7,7 +7,7 @@ import ( ) type owm struct { - props properties + props Properties env environmentInfo Temperature float64 Weather string @@ -173,7 +173,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 96183579..0969f492 100644 --- a/src/segment_owm_test.go +++ b/src/segment_owm_test.go @@ -51,7 +51,7 @@ func TestOWMSegmentSingle(t *testing.T) { for _, tc := range cases { env := &MockedEnvironment{} - var props properties = map[Property]interface{}{ + props := properties{ APIKey: "key", Location: "AMSTERDAM,NL", Units: "metric", @@ -187,7 +187,7 @@ func TestOWMSegmentIcons(t *testing.T) { env.On("doGet", OWMAPIURL).Return([]byte(response), nil) o := &owm{ - props: map[Property]interface{}{ + props: properties{ APIKey: "key", Location: "AMSTERDAM,NL", Units: "metric", @@ -210,7 +210,7 @@ func TestOWMSegmentIcons(t *testing.T) { env.On("doGet", OWMAPIURL).Return([]byte(response), nil) o := &owm{ - props: map[Property]interface{}{ + props: properties{ APIKey: "key", Location: "AMSTERDAM,NL", Units: "metric", @@ -232,7 +232,7 @@ func TestOWMSegmentFromCache(t *testing.T) { env := &MockedEnvironment{} cache := &MockedCache{} o := &owm{ - props: map[Property]interface{}{ + props: properties{ APIKey: "key", Location: "AMSTERDAM,NL", Units: "metric", @@ -256,7 +256,7 @@ func TestOWMSegmentFromCacheWithHyperlink(t *testing.T) { cache := &MockedCache{} o := &owm{ - props: map[Property]interface{}{ + props: properties{ APIKey: "key", Location: "AMSTERDAM,NL", Units: "metric", diff --git a/src/segment_path.go b/src/segment_path.go index d87a8bfa..1475b3ff 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 PWD string @@ -112,7 +112,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 e293894f..7001bed7 100644 --- a/src/segment_path_test.go +++ b/src/segment_path_test.go @@ -267,7 +267,7 @@ func TestRootLocationHome(t *testing.T) { env.On("getRuntimeGOOS", nil).Return("") path := &path{ env: env, - props: map[Property]interface{}{ + props: properties{ HomeIcon: tc.HomeIcon, WindowsRegistryIcon: tc.RegistryIcon, }, @@ -419,7 +419,7 @@ func TestAgnosterPathStyles(t *testing.T) { env.On("getArgs", nil).Return(args) path := &path{ env: env, - props: map[Property]interface{}{ + props: properties{ FolderSeparatorIcon: tc.FolderSeparatorIcon, Style: tc.Style, MaxDepth: tc.MaxDepth, @@ -540,7 +540,7 @@ func TestGetFullPath(t *testing.T) { if len(tc.Template) == 0 { tc.Template = "{{ if gt .StackCount 0 }}{{ .StackCount }} {{ end }}{{ .Path }}" } - var props properties = map[Property]interface{}{ + props := properties{ Style: tc.Style, SegmentTemplate: tc.Template, } @@ -588,7 +588,7 @@ func TestGetFullPathCustomMappedLocations(t *testing.T) { env.On("getArgs", nil).Return(args) path := &path{ env: env, - props: map[Property]interface{}{ + props: properties{ MappedLocationsEnabled: false, MappedLocations: tc.MappedLocations, }, @@ -639,7 +639,7 @@ func TestGetFolderPathCustomMappedLocations(t *testing.T) { env.On("getArgs", nil).Return(args) path := &path{ env: env, - props: map[Property]interface{}{ + props: properties{ MappedLocations: map[string]string{ "/a/b/c/d": "#", }, @@ -686,7 +686,7 @@ func TestAgnosterPath(t *testing.T) { // nolint:dupl env.On("getArgs", nil).Return(args) path := &path{ env: env, - props: map[Property]interface{}{ + props: properties{ FolderSeparatorIcon: " > ", FolderIcon: "f", HomeIcon: "~", @@ -734,7 +734,7 @@ func TestAgnosterLeftPath(t *testing.T) { // nolint:dupl env.On("getArgs", nil).Return(args) path := &path{ env: env, - props: map[Property]interface{}{ + props: properties{ FolderSeparatorIcon: " > ", FolderIcon: "f", HomeIcon: "~", @@ -782,7 +782,7 @@ func TestGetPwd(t *testing.T) { env.On("getArgs", nil).Return(args) path := &path{ env: env, - props: map[Property]interface{}{ + props: properties{ MappedLocationsEnabled: tc.MappedLocationsEnabled, MappedLocations: map[string]string{ "/a/b/c/d": "#", diff --git a/src/segment_php.go b/src/segment_php.go index 04304f70..3d0805f4 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_plastic.go b/src/segment_plastic.go index 8c7a1489..4da95895 100644 --- a/src/segment_plastic.go +++ b/src/segment_plastic.go @@ -34,7 +34,7 @@ type plastic struct { plasticWorkspaceFolder string // root folder of workspace } -func (p *plastic) init(props properties, env environmentInfo) { +func (p *plastic) init(props Properties, env environmentInfo) { p.props = props p.env = env } diff --git a/src/segment_plastic_test.go b/src/segment_plastic_test.go index 54fb670c..c34f877d 100644 --- a/src/segment_plastic_test.go +++ b/src/segment_plastic_test.go @@ -13,7 +13,8 @@ func TestPlasticEnabledNotFound(t *testing.T) { env.On("isWsl", nil).Return(false) p := &plastic{ scm: scm{ - env: env, + env: env, + props: properties{}, }, } assert.False(t, p.enabled()) @@ -32,7 +33,8 @@ func TestPlasticEnabledInWorkspaceDirectory(t *testing.T) { env.On("hasParentFilePath", ".plastic").Return(fileInfo, nil) p := &plastic{ scm: scm{ - env: env, + env: env, + props: properties{}, }, } assert.True(t, p.enabled()) @@ -45,7 +47,8 @@ func setupCmStatusEnv(status, headStatus string) *plastic { env.On("runCommand", "cm", []string{"status", "--head", "--machinereadable"}).Return(headStatus, nil) p := &plastic{ scm: scm{ - env: env, + env: env, + props: properties{}, }, } return p @@ -321,7 +324,7 @@ func TestPlasticTemplateString(t *testing.T) { } for _, tc := range cases { - var props properties = map[Property]interface{}{ + props := properties{ FetchStatus: true, } tc.Plastic.props = props diff --git a/src/segment_posh_git.go b/src/segment_posh_git.go index 262dc142..83b77c96 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 738e1939..0fa529a4 100644 --- a/src/segment_python.go +++ b/src/segment_python.go @@ -19,7 +19,7 @@ func (p *python) string() string { return p.language.renderTemplate(segmentTemplate, p) } -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 3aab1dcd..f026f09c 100644 --- a/src/segment_python_test.go +++ b/src/segment_python_test.go @@ -52,7 +52,7 @@ func TestPythonTemplate(t *testing.T) { env.On("getPathSeperator", nil).Return("") env.On("getcwd", nil).Return("/usr/home/project") env.On("homeDir", nil).Return("/usr/home") - var props properties = map[Property]interface{}{ + props := properties{ FetchVersion: tc.FetchVersion, SegmentTemplate: tc.Template, DisplayMode: DisplayModeAlways, @@ -81,7 +81,7 @@ func TestPythonPythonInContext(t *testing.T) { env.On("getenv", "CONDA_DEFAULT_ENV").Return("") env.On("getenv", "PYENV_VERSION").Return("") python := &python{} - python.init(nil, env) + python.init(properties{}, env) python.loadContext() assert.Equal(t, tc.Expected, python.inContext()) } diff --git a/src/segment_root.go b/src/segment_root.go index d16553a6..534d71ac 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 d37cc6d3..5dc00c82 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 ebcd9043..0295eb5e 100644 --- a/src/segment_ruby_test.go +++ b/src/segment_ruby_test.go @@ -98,7 +98,7 @@ 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") - var props properties = map[Property]interface{}{ + props := properties{ FetchVersion: tc.FetchVersion, } ruby := &ruby{} diff --git a/src/segment_rust.go b/src/segment_rust.go index b2f094e0..27349e02 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 06ab4f76..05850d88 100644 --- a/src/segment_session.go +++ b/src/segment_session.go @@ -3,7 +3,7 @@ package main import "strings" type session struct { - props properties + props Properties env environmentInfo text string @@ -45,7 +45,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 } diff --git a/src/segment_session_test.go b/src/segment_session_test.go index 973c0770..9b82daba 100644 --- a/src/segment_session_test.go +++ b/src/segment_session_test.go @@ -109,7 +109,7 @@ func TestSessionSegmentTemplate(t *testing.T) { env.On("getenv", defaultUserEnvVar).Return(tc.DefaultUserName) session := &session{ env: env, - props: map[Property]interface{}{ + props: properties{ SegmentTemplate: tc.Template, }, } diff --git a/src/segment_shell.go b/src/segment_shell.go index 7c60a1ff..5cda252e 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 12dba9e9..b48c8b2a 100644 --- a/src/segment_shell_test.go +++ b/src/segment_shell_test.go @@ -11,7 +11,8 @@ func TestWriteCurrentShell(t *testing.T) { env := new(MockedEnvironment) env.On("getShellName", nil).Return(expected, nil) s := &shell{ - env: env, + env: env, + props: properties{}, } assert.Equal(t, expected, s.string()) } @@ -30,7 +31,7 @@ func TestUseMappedShellNames(t *testing.T) { env.On("getShellName", nil).Return(tc.Expected, nil) s := &shell{ env: env, - props: map[Property]interface{}{ + props: properties{ MappedShellNames: map[string]string{"pwsh": "PS"}, }, } diff --git a/src/segment_spotify.go b/src/segment_spotify.go index 307dad20..54aeeb0f 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 ced85cae..bc30d393 100644 --- a/src/segment_spotify_darwin_test.go +++ b/src/segment_spotify_darwin_test.go @@ -23,7 +23,8 @@ func bootStrapSpotifyDarwinTest(args *spotifyArgs) *spotify { 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) s := &spotify{ - env: env, + env: env, + props: properties{}, } return s } diff --git a/src/segment_spotify_test.go b/src/segment_spotify_test.go index fe7c3b14..5f6d3be8 100644 --- a/src/segment_spotify_test.go +++ b/src/segment_spotify_test.go @@ -12,6 +12,7 @@ func TestSpotifyStringPlayingSong(t *testing.T) { artist: "Candlemass", track: "Spellbreaker", status: "playing", + props: properties{}, } assert.Equal(t, expected, s.string()) } @@ -22,6 +23,7 @@ func TestSpotifyStringPausedSong(t *testing.T) { artist: "Candlemass", track: "Spellbreaker", status: "paused", + props: properties{}, } assert.Equal(t, expected, s.string()) } @@ -32,6 +34,7 @@ func TestSpotifyStringStoppedSong(t *testing.T) { artist: "Candlemass", track: "Spellbreaker", status: "stopped", + props: properties{}, } assert.Equal(t, expected, s.string()) } diff --git a/src/segment_spotify_windows_test.go b/src/segment_spotify_windows_test.go index 98568a65..37153e3d 100644 --- a/src/segment_spotify_windows_test.go +++ b/src/segment_spotify_windows_test.go @@ -18,7 +18,8 @@ func bootStrapSpotifyWindowsTest(args *spotifyArgs) *spotify { env := new(MockedEnvironment) env.On("getWindowTitle", "spotify.exe").Return(args.title, args.runError) s := &spotify{ - env: env, + env: env, + props: properties{}, } return s } diff --git a/src/segment_spotify_wsl_test.go b/src/segment_spotify_wsl_test.go index c5de82f2..70905388 100644 --- a/src/segment_spotify_wsl_test.go +++ b/src/segment_spotify_wsl_test.go @@ -55,7 +55,8 @@ func TestSpotifyWsl(t *testing.T) { 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) s := &spotify{ - env: env, + env: env, + props: properties{}, } 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 3fab2aa6..003cddf3 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 c30b5864..de7cf87b 100644 --- a/src/segment_sysinfo_test.go +++ b/src/segment_sysinfo_test.go @@ -35,11 +35,11 @@ func TestSysInfo(t *testing.T) { for _, tc := range cases { tc.SysInfo.env = new(MockedEnvironment) - tc.SysInfo.props = map[Property]interface{}{ + tc.SysInfo.props = properties{ Precision: tc.Precision, } if tc.Template != "" { - tc.SysInfo.props[SegmentTemplate] = tc.Template + tc.SysInfo.props.set(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 9ded07ce..9e3907a1 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 bf3d6ab5..7b0131fb 100644 --- a/src/segment_terraform_test.go +++ b/src/segment_terraform_test.go @@ -19,7 +19,8 @@ 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, + env: env, + props: properties{}, } return k } diff --git a/src/segment_test.go b/src/segment_test.go index 9526e893..213ab4d5 100644 --- a/src/segment_test.go +++ b/src/segment_test.go @@ -84,7 +84,7 @@ func TestShouldIncludeFolder(t *testing.T) { env.On("homeDir", nil).Return("") env.On("getcwd", nil).Return(cwd) segment := &Segment{ - Properties: map[Property]interface{}{ + Properties: properties{ IncludeFolders: tc.IncludeFolders, ExcludeFolders: tc.ExcludeFolders, }, @@ -101,7 +101,7 @@ func TestShouldIncludeFolderRegexInverted(t *testing.T) { env.On("homeDir", nil).Return("") env.On("getcwd", nil).Return(cwd) segment := &Segment{ - Properties: map[Property]interface{}{ + Properties: properties{ ExcludeFolders: []string{"(?!Projects[\\/]).*"}, }, env: env, @@ -122,7 +122,7 @@ func TestShouldIncludeFolderRegexInvertedNonEscaped(t *testing.T) { env.On("homeDir", nil).Return("") env.On("getcwd", nil).Return(cwd) segment := &Segment{ - Properties: map[Property]interface{}{ + Properties: properties{ ExcludeFolders: []string{"(?!Projects/).*"}, }, env: env, diff --git a/src/segment_text.go b/src/segment_text.go index afc40421..a5227002 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 21932956..bac04e0c 100644 --- a/src/segment_text_test.go +++ b/src/segment_text_test.go @@ -35,7 +35,7 @@ func TestTextSegment(t *testing.T) { env.On("getHostName", nil).Return("MyHost", nil) txt := &text{ env: env, - props: map[Property]interface{}{ + props: properties{ TextProperty: tc.Text, }, } diff --git a/src/segment_time.go b/src/segment_time.go index 8f6a3227..d107a916 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 f8e8f0ef..991f7a05 100644 --- a/src/segment_time_test.go +++ b/src/segment_time_test.go @@ -41,7 +41,7 @@ func TestTimeSegmentTemplate(t *testing.T) { env := new(MockedEnvironment) tempus := &tempus{ env: env, - props: map[Property]interface{}{ + props: properties{ SegmentTemplate: tc.Template, }, CurrentDate: currentDate, diff --git a/src/segment_wakatime.go b/src/segment_wakatime.go index 124f8c0f..7b050e28 100644 --- a/src/segment_wakatime.go +++ b/src/segment_wakatime.go @@ -5,7 +5,7 @@ import ( ) type wakatime struct { - props properties + props Properties env environmentInfo wtData @@ -73,7 +73,7 @@ func (w *wakatime) setAPIData() error { return nil } -func (w *wakatime) init(props properties, env environmentInfo) { +func (w *wakatime) init(props Properties, env environmentInfo) { w.props = props w.env = env } diff --git a/src/segment_wakatime_test.go b/src/segment_wakatime_test.go index e2016f40..3dfe18ec 100644 --- a/src/segment_wakatime_test.go +++ b/src/segment_wakatime_test.go @@ -79,7 +79,7 @@ func TestWTTrackedTime(t *testing.T) { env.On("cache", nil).Return(cache) w := &wakatime{ - props: map[Property]interface{}{ + props: properties{ APIKey: "key", CacheTimeout: tc.CacheTimeout, URL: FAKEAPIURL, diff --git a/src/segment_wifi.go b/src/segment_wifi.go index 1d3efa02..c8cf7832 100644 --- a/src/segment_wifi.go +++ b/src/segment_wifi.go @@ -1,7 +1,7 @@ package main type wifi struct { - props properties + props Properties env environmentInfo wifiInfo @@ -44,7 +44,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 086409de..fe0c6c16 100644 --- a/src/segment_wifi_test.go +++ b/src/segment_wifi_test.go @@ -48,7 +48,7 @@ func TestWiFiSegment(t *testing.T) { w := &wifi{ env: env, - props: map[Property]interface{}{ + props: properties{ DisplayError: tc.DisplayError, SegmentTemplate: "{{ if .Error }}{{ .Error }}{{ else }}{{ .SSID }}{{ end }}", }, diff --git a/src/segment_winreg.go b/src/segment_winreg.go index eb53dcbe..237ade2e 100644 --- a/src/segment_winreg.go +++ b/src/segment_winreg.go @@ -6,7 +6,7 @@ import ( ) type winreg struct { - props properties + props Properties env environmentInfo Value string @@ -19,7 +19,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 638e68e3..0264c888 100644 --- a/src/segment_winreg_test.go +++ b/src/segment_winreg_test.go @@ -75,7 +75,7 @@ func TestWinReg(t *testing.T) { env.On("getWindowsRegistryKeyValue", tc.Path).Return(tc.getWRKVOutput, tc.Err) r := &winreg{ env: env, - props: map[Property]interface{}{ + props: properties{ RegistryPath: tc.Path, Fallback: tc.Fallback, }, diff --git a/src/segment_ytm.go b/src/segment_ytm.go index fdf0e00c..cfcbd615 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 9547b72d..7be7cfd9 100644 --- a/src/segment_ytm_test.go +++ b/src/segment_ytm_test.go @@ -13,6 +13,7 @@ func TestYTMStringPlayingSong(t *testing.T) { artist: "Candlemass", track: "Spellbreaker", status: playing, + props: properties{}, } assert.Equal(t, expected, y.string()) } @@ -23,6 +24,7 @@ func TestYTMStringPausedSong(t *testing.T) { artist: "Candlemass", track: "Spellbreaker", status: paused, + props: properties{}, } assert.Equal(t, expected, y.string()) } @@ -33,6 +35,7 @@ func TestYTMStringStoppedSong(t *testing.T) { artist: "Candlemass", track: "Spellbreaker", status: stopped, + props: properties{}, } assert.Equal(t, expected, y.string()) } @@ -43,7 +46,7 @@ func bootstrapYTMDATest(json string, err error) *ytm { env.On("doGet", url+"/query").Return([]byte(json), err) ytm := &ytm{ env: env, - props: map[Property]interface{}{ + props: properties{ APIURL: url, }, }