mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-03-05 20:49:04 -08:00
refactor: move properties to interface
This commit is contained in:
parent
e8f1e5e2d4
commit
29e019511a
|
@ -48,7 +48,7 @@ func (n *new) string() string {
|
||||||
return text
|
return text
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *new) init(props properties, env environmentInfo) {
|
func (n *new) init(props Properties, env environmentInfo) {
|
||||||
n.props = props
|
n.props = props
|
||||||
n.env = env
|
n.env = env
|
||||||
}
|
}
|
||||||
|
|
|
@ -188,7 +188,7 @@ func getDefaultConfig(info string) *Config {
|
||||||
PowerlineSymbol: "\uE0B0",
|
PowerlineSymbol: "\uE0B0",
|
||||||
Background: "#ff479c",
|
Background: "#ff479c",
|
||||||
Foreground: "#ffffff",
|
Foreground: "#ffffff",
|
||||||
Properties: map[Property]interface{}{
|
Properties: properties{
|
||||||
Prefix: " \uE5FF ",
|
Prefix: " \uE5FF ",
|
||||||
Style: "folder",
|
Style: "folder",
|
||||||
},
|
},
|
||||||
|
@ -199,7 +199,7 @@ func getDefaultConfig(info string) *Config {
|
||||||
PowerlineSymbol: "\uE0B0",
|
PowerlineSymbol: "\uE0B0",
|
||||||
Background: "#fffb38",
|
Background: "#fffb38",
|
||||||
Foreground: "#193549",
|
Foreground: "#193549",
|
||||||
Properties: map[Property]interface{}{
|
Properties: properties{
|
||||||
FetchStashCount: true,
|
FetchStashCount: true,
|
||||||
FetchUpstreamIcon: true,
|
FetchUpstreamIcon: true,
|
||||||
},
|
},
|
||||||
|
@ -210,7 +210,7 @@ func getDefaultConfig(info string) *Config {
|
||||||
PowerlineSymbol: "\uE0B0",
|
PowerlineSymbol: "\uE0B0",
|
||||||
Background: "#f36943",
|
Background: "#f36943",
|
||||||
Foreground: "#193549",
|
Foreground: "#193549",
|
||||||
Properties: map[Property]interface{}{
|
Properties: properties{
|
||||||
ColorBackground: true,
|
ColorBackground: true,
|
||||||
ChargedColor: "#4caf50",
|
ChargedColor: "#4caf50",
|
||||||
ChargingColor: "#40c4ff",
|
ChargingColor: "#40c4ff",
|
||||||
|
@ -224,7 +224,7 @@ func getDefaultConfig(info string) *Config {
|
||||||
PowerlineSymbol: "\uE0B0",
|
PowerlineSymbol: "\uE0B0",
|
||||||
Background: "#6CA35E",
|
Background: "#6CA35E",
|
||||||
Foreground: "#ffffff",
|
Foreground: "#ffffff",
|
||||||
Properties: map[Property]interface{}{
|
Properties: properties{
|
||||||
Prefix: " \uE718",
|
Prefix: " \uE718",
|
||||||
FetchVersion: false,
|
FetchVersion: false,
|
||||||
},
|
},
|
||||||
|
@ -235,7 +235,7 @@ func getDefaultConfig(info string) *Config {
|
||||||
PowerlineSymbol: "\uE0B0",
|
PowerlineSymbol: "\uE0B0",
|
||||||
Background: "#0077c2",
|
Background: "#0077c2",
|
||||||
Foreground: "#ffffff",
|
Foreground: "#ffffff",
|
||||||
Properties: map[Property]interface{}{
|
Properties: properties{
|
||||||
Prefix: " \uFCB5 ",
|
Prefix: " \uFCB5 ",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -252,7 +252,7 @@ func getDefaultConfig(info string) *Config {
|
||||||
PowerlineSymbol: "\uE0B0",
|
PowerlineSymbol: "\uE0B0",
|
||||||
Background: "#ffffff",
|
Background: "#ffffff",
|
||||||
Foreground: "#111111",
|
Foreground: "#111111",
|
||||||
Properties: map[Property]interface{}{
|
Properties: properties{
|
||||||
TextProperty: info,
|
TextProperty: info,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -263,7 +263,7 @@ func getDefaultConfig(info string) *Config {
|
||||||
Foreground: "#ffffff",
|
Foreground: "#ffffff",
|
||||||
LeadingDiamond: "<transparent,#2e9599>\uE0B0</>",
|
LeadingDiamond: "<transparent,#2e9599>\uE0B0</>",
|
||||||
TrailingDiamond: "\uE0B4",
|
TrailingDiamond: "\uE0B4",
|
||||||
Properties: map[Property]interface{}{
|
Properties: properties{
|
||||||
DisplayExitCode: false,
|
DisplayExitCode: false,
|
||||||
AlwaysEnabled: true,
|
AlwaysEnabled: true,
|
||||||
ErrorColor: "#f1184c",
|
ErrorColor: "#f1184c",
|
||||||
|
|
|
@ -12,101 +12,101 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGetString(t *testing.T) {
|
func TestGetString(t *testing.T) {
|
||||||
var properties properties = map[Property]interface{}{TextProperty: expected}
|
var properties properties = properties{TextProperty: expected}
|
||||||
value := properties.getString(TextProperty, "err")
|
value := properties.getString(TextProperty, "err")
|
||||||
assert.Equal(t, expected, value)
|
assert.Equal(t, expected, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetStringNoEntry(t *testing.T) {
|
func TestGetStringNoEntry(t *testing.T) {
|
||||||
var properties properties = map[Property]interface{}{}
|
var properties properties = properties{}
|
||||||
value := properties.getString(TextProperty, expected)
|
value := properties.getString(TextProperty, expected)
|
||||||
assert.Equal(t, expected, value)
|
assert.Equal(t, expected, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetStringNoTextEntry(t *testing.T) {
|
func TestGetStringNoTextEntry(t *testing.T) {
|
||||||
var properties properties = map[Property]interface{}{TextProperty: true}
|
var properties properties = properties{TextProperty: true}
|
||||||
value := properties.getString(TextProperty, expected)
|
value := properties.getString(TextProperty, expected)
|
||||||
assert.Equal(t, expected, value)
|
assert.Equal(t, expected, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetHexColor(t *testing.T) {
|
func TestGetHexColor(t *testing.T) {
|
||||||
expected := expectedColor
|
expected := expectedColor
|
||||||
var properties properties = map[Property]interface{}{UserColor: expected}
|
var properties properties = properties{UserColor: expected}
|
||||||
value := properties.getColor(UserColor, "#789123")
|
value := properties.getColor(UserColor, "#789123")
|
||||||
assert.Equal(t, expected, value)
|
assert.Equal(t, expected, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetColor(t *testing.T) {
|
func TestGetColor(t *testing.T) {
|
||||||
expected := "yellow"
|
expected := "yellow"
|
||||||
var properties properties = map[Property]interface{}{UserColor: expected}
|
var properties properties = properties{UserColor: expected}
|
||||||
value := properties.getColor(UserColor, "#789123")
|
value := properties.getColor(UserColor, "#789123")
|
||||||
assert.Equal(t, expected, value)
|
assert.Equal(t, expected, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDefaultColorWithInvalidColorCode(t *testing.T) {
|
func TestDefaultColorWithInvalidColorCode(t *testing.T) {
|
||||||
expected := expectedColor
|
expected := expectedColor
|
||||||
var properties properties = map[Property]interface{}{UserColor: "invalid"}
|
var properties properties = properties{UserColor: "invalid"}
|
||||||
value := properties.getColor(UserColor, expected)
|
value := properties.getColor(UserColor, expected)
|
||||||
assert.Equal(t, expected, value)
|
assert.Equal(t, expected, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDefaultColorWithUnavailableProperty(t *testing.T) {
|
func TestDefaultColorWithUnavailableProperty(t *testing.T) {
|
||||||
expected := expectedColor
|
expected := expectedColor
|
||||||
var properties properties = map[Property]interface{}{}
|
var properties properties = properties{}
|
||||||
value := properties.getColor(UserColor, expected)
|
value := properties.getColor(UserColor, expected)
|
||||||
assert.Equal(t, expected, value)
|
assert.Equal(t, expected, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetPaletteColor(t *testing.T) {
|
func TestGetPaletteColor(t *testing.T) {
|
||||||
expected := "p:red"
|
expected := "p:red"
|
||||||
var properties properties = map[Property]interface{}{Background: expected}
|
var properties properties = properties{Background: expected}
|
||||||
value := properties.getColor(Background, "white")
|
value := properties.getColor(Background, "white")
|
||||||
assert.Equal(t, expected, value)
|
assert.Equal(t, expected, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetBool(t *testing.T) {
|
func TestGetBool(t *testing.T) {
|
||||||
expected := true
|
expected := true
|
||||||
var properties properties = map[Property]interface{}{DisplayHost: expected}
|
var properties properties = properties{DisplayHost: expected}
|
||||||
value := properties.getBool(DisplayHost, false)
|
value := properties.getBool(DisplayHost, false)
|
||||||
assert.True(t, value)
|
assert.True(t, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetBoolPropertyNotInMap(t *testing.T) {
|
func TestGetBoolPropertyNotInMap(t *testing.T) {
|
||||||
var properties properties = map[Property]interface{}{}
|
var properties properties = properties{}
|
||||||
value := properties.getBool(DisplayHost, false)
|
value := properties.getBool(DisplayHost, false)
|
||||||
assert.False(t, value)
|
assert.False(t, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetBoolInvalidProperty(t *testing.T) {
|
func TestGetBoolInvalidProperty(t *testing.T) {
|
||||||
var properties properties = map[Property]interface{}{DisplayHost: "borked"}
|
var properties properties = properties{DisplayHost: "borked"}
|
||||||
value := properties.getBool(DisplayHost, false)
|
value := properties.getBool(DisplayHost, false)
|
||||||
assert.False(t, value)
|
assert.False(t, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetFloat64(t *testing.T) {
|
func TestGetFloat64(t *testing.T) {
|
||||||
expected := float64(1337)
|
expected := float64(1337)
|
||||||
var properties properties = map[Property]interface{}{"myfloat": expected}
|
var properties properties = properties{"myfloat": expected}
|
||||||
value := properties.getFloat64("myfloat", 9001)
|
value := properties.getFloat64("myfloat", 9001)
|
||||||
assert.Equal(t, expected, value)
|
assert.Equal(t, expected, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetFloat64PropertyNotInMap(t *testing.T) {
|
func TestGetFloat64PropertyNotInMap(t *testing.T) {
|
||||||
expected := float64(1337)
|
expected := float64(1337)
|
||||||
var properties properties = map[Property]interface{}{}
|
var properties properties = properties{}
|
||||||
value := properties.getFloat64(ThresholdProperty, expected)
|
value := properties.getFloat64(ThresholdProperty, expected)
|
||||||
assert.Equal(t, expected, value)
|
assert.Equal(t, expected, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetFloat64InvalidStringProperty(t *testing.T) {
|
func TestGetFloat64InvalidStringProperty(t *testing.T) {
|
||||||
expected := float64(1337)
|
expected := float64(1337)
|
||||||
var properties properties = map[Property]interface{}{ThresholdProperty: "invalid"}
|
var properties properties = properties{ThresholdProperty: "invalid"}
|
||||||
value := properties.getFloat64(ThresholdProperty, expected)
|
value := properties.getFloat64(ThresholdProperty, expected)
|
||||||
assert.Equal(t, expected, value)
|
assert.Equal(t, expected, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetFloat64InvalidBoolProperty(t *testing.T) {
|
func TestGetFloat64InvalidBoolProperty(t *testing.T) {
|
||||||
expected := float64(1337)
|
expected := float64(1337)
|
||||||
var properties properties = map[Property]interface{}{ThresholdProperty: true}
|
var properties properties = properties{ThresholdProperty: true}
|
||||||
value := properties.getFloat64(ThresholdProperty, expected)
|
value := properties.getFloat64(ThresholdProperty, expected)
|
||||||
assert.Equal(t, expected, value)
|
assert.Equal(t, expected, value)
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ func (s *ScmStatus) String() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
type scm struct {
|
type scm struct {
|
||||||
props properties
|
props Properties
|
||||||
env environmentInfo
|
env environmentInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ const (
|
||||||
FullBranchPath Property = "full_branch_path"
|
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.props = props
|
||||||
s.env = env
|
s.env = env
|
||||||
}
|
}
|
||||||
|
@ -68,11 +68,10 @@ func (s *scm) truncateBranch(branch string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *scm) shouldIgnoreRootRepository(rootDir string) bool {
|
func (s *scm) shouldIgnoreRootRepository(rootDir string) bool {
|
||||||
value, ok := s.props[ExcludeFolders]
|
excludedFolders := s.props.getStringArray(ExcludeFolders, []string{})
|
||||||
if !ok {
|
if len(excludedFolders) == 0 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
excludedFolders := parseStringArray(value)
|
|
||||||
return dirMatchesOneOf(s.env, rootDir, excludedFolders)
|
return dirMatchesOneOf(s.env, rootDir, excludedFolders)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -104,7 +104,7 @@ func TestTruncateBranch(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
var props properties = map[Property]interface{}{
|
props := properties{
|
||||||
BranchMaxLength: tc.MaxLength,
|
BranchMaxLength: tc.MaxLength,
|
||||||
FullBranchPath: tc.FullBranch,
|
FullBranchPath: tc.FullBranch,
|
||||||
}
|
}
|
||||||
|
@ -140,7 +140,7 @@ func TestTruncateBranchWithSymbol(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
var props properties = map[Property]interface{}{
|
props := properties{
|
||||||
BranchMaxLength: tc.MaxLength,
|
BranchMaxLength: tc.MaxLength,
|
||||||
TruncateSymbol: tc.TruncateSymbol,
|
TruncateSymbol: tc.TruncateSymbol,
|
||||||
FullBranchPath: tc.FullBranch,
|
FullBranchPath: tc.FullBranch,
|
||||||
|
@ -167,7 +167,7 @@ func TestScmShouldIgnoreRootRepository(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
var props properties = map[Property]interface{}{
|
props := properties{
|
||||||
ExcludeFolders: []string{
|
ExcludeFolders: []string{
|
||||||
"/home/bill",
|
"/home/bill",
|
||||||
"/home/gates.*",
|
"/home/gates.*",
|
||||||
|
|
|
@ -37,11 +37,26 @@ type SegmentTiming struct {
|
||||||
stringDuration time.Duration
|
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
|
// SegmentWriter is the interface used to define what and if to write to the prompt
|
||||||
type SegmentWriter interface {
|
type SegmentWriter interface {
|
||||||
enabled() bool
|
enabled() bool
|
||||||
string() string
|
string() string
|
||||||
init(props properties, env environmentInfo)
|
init(props Properties, env environmentInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SegmentStyle the syle of segment, for more information, see the constants
|
// SegmentStyle the syle of segment, for more information, see the constants
|
||||||
|
|
|
@ -13,7 +13,7 @@ func (a *angular) string() string {
|
||||||
return a.language.string()
|
return a.language.string()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *angular) init(props properties, env environmentInfo) {
|
func (a *angular) init(props Properties, env environmentInfo) {
|
||||||
a.language = language{
|
a.language = language{
|
||||||
env: env,
|
env: env,
|
||||||
props: props,
|
props: props,
|
||||||
|
|
|
@ -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("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)
|
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 := &angular{}
|
||||||
angular.init(props, env)
|
angular.init(props, env)
|
||||||
assert.True(t, angular.enabled(), fmt.Sprintf("Failed in case: %s", ta.Case))
|
assert.True(t, angular.enabled(), fmt.Sprintf("Failed in case: %s", ta.Case))
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type aws struct {
|
type aws struct {
|
||||||
props properties
|
props Properties
|
||||||
env environmentInfo
|
env environmentInfo
|
||||||
Profile string
|
Profile string
|
||||||
Region string
|
Region string
|
||||||
|
@ -16,7 +16,7 @@ const (
|
||||||
defaultUser = "default"
|
defaultUser = "default"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (a *aws) init(props properties, env environmentInfo) {
|
func (a *aws) init(props Properties, env environmentInfo) {
|
||||||
a.props = props
|
a.props = props
|
||||||
a.env = env
|
a.env = env
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ func TestAWSSegment(t *testing.T) {
|
||||||
env.On("getenv", "AWS_CONFIG_FILE").Return(tc.ConfigFile)
|
env.On("getenv", "AWS_CONFIG_FILE").Return(tc.ConfigFile)
|
||||||
env.On("getFileContent", "/usr/home/.aws/config").Return("")
|
env.On("getFileContent", "/usr/home/.aws/config").Return("")
|
||||||
env.On("homeDir", nil).Return("/usr/home")
|
env.On("homeDir", nil).Return("/usr/home")
|
||||||
var props properties = map[Property]interface{}{
|
props := properties{
|
||||||
DisplayDefault: tc.DisplayDefault,
|
DisplayDefault: tc.DisplayDefault,
|
||||||
}
|
}
|
||||||
if tc.Template != "" {
|
if tc.Template != "" {
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type az struct {
|
type az struct {
|
||||||
props properties
|
props Properties
|
||||||
env environmentInfo
|
env environmentInfo
|
||||||
|
|
||||||
AzureSubscription
|
AzureSubscription
|
||||||
|
@ -91,7 +91,7 @@ func (a *az) string() string {
|
||||||
return text
|
return text
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *az) init(props properties, env environmentInfo) {
|
func (a *az) init(props Properties, env environmentInfo) {
|
||||||
a.props = props
|
a.props = props
|
||||||
a.env = env
|
a.env = env
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ func (az *azfunc) string() string {
|
||||||
return az.language.string()
|
return az.language.string()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (az *azfunc) init(props properties, env environmentInfo) {
|
func (az *azfunc) init(props Properties, env environmentInfo) {
|
||||||
az.language = language{
|
az.language = language{
|
||||||
env: env,
|
env: env,
|
||||||
props: props,
|
props: props,
|
||||||
|
|
|
@ -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/azureProfile.json")).Return(azureProfile)
|
||||||
env.On("getFileContent", filepath.Join(home, ".azure/AzureRmContext.json")).Return(azureRmContext)
|
env.On("getFileContent", filepath.Join(home, ".azure/AzureRmContext.json")).Return(azureRmContext)
|
||||||
|
|
||||||
var props properties = map[Property]interface{}{
|
props := properties{
|
||||||
SegmentTemplate: tc.Template,
|
SegmentTemplate: tc.Template,
|
||||||
}
|
}
|
||||||
az := &az{
|
az := &az{
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type batt struct {
|
type batt struct {
|
||||||
props properties
|
props Properties
|
||||||
env environmentInfo
|
env environmentInfo
|
||||||
|
|
||||||
battery.Battery
|
battery.Battery
|
||||||
|
@ -118,7 +118,7 @@ func (b *batt) string() string {
|
||||||
return text
|
return text
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *batt) init(props properties, env environmentInfo) {
|
func (b *batt) init(props Properties, env environmentInfo) {
|
||||||
b.props = props
|
b.props = props
|
||||||
b.env = env
|
b.env = env
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
|
|
||||||
// segment struct, makes templating easier
|
// segment struct, makes templating easier
|
||||||
type brewfather struct {
|
type brewfather struct {
|
||||||
props properties
|
props Properties
|
||||||
env environmentInfo
|
env environmentInfo
|
||||||
|
|
||||||
Batch
|
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
|
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.props = props
|
||||||
bf.env = env
|
bf.env = env
|
||||||
}
|
}
|
||||||
|
|
|
@ -137,7 +137,7 @@ func TestBrewfatherSegment(t *testing.T) {
|
||||||
|
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
env := &MockedEnvironment{}
|
env := &MockedEnvironment{}
|
||||||
var props properties = map[Property]interface{}{
|
props := properties{
|
||||||
CacheTimeout: tc.CacheTimeout,
|
CacheTimeout: tc.CacheTimeout,
|
||||||
BFBatchID: BFFakeBatchID,
|
BFBatchID: BFFakeBatchID,
|
||||||
BFAPIKey: "FAKE",
|
BFAPIKey: "FAKE",
|
||||||
|
|
|
@ -3,7 +3,7 @@ package main
|
||||||
import "strings"
|
import "strings"
|
||||||
|
|
||||||
type command struct {
|
type command struct {
|
||||||
props properties
|
props Properties
|
||||||
env environmentInfo
|
env environmentInfo
|
||||||
value string
|
value string
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ func (c *command) string() string {
|
||||||
return c.value
|
return c.value
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *command) init(props properties, env environmentInfo) {
|
func (c *command) init(props Properties, env environmentInfo) {
|
||||||
c.props = props
|
c.props = props
|
||||||
c.env = env
|
c.env = env
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ func TestExecuteCommand(t *testing.T) {
|
||||||
env.init(&args{
|
env.init(&args{
|
||||||
Debug: &debug,
|
Debug: &debug,
|
||||||
})
|
})
|
||||||
var props properties = map[Property]interface{}{
|
props := properties{
|
||||||
Command: "echo hello",
|
Command: "echo hello",
|
||||||
}
|
}
|
||||||
c := &command{
|
c := &command{
|
||||||
|
@ -32,7 +32,7 @@ func TestExecuteMultipleCommandsOrFirst(t *testing.T) {
|
||||||
env.init(&args{
|
env.init(&args{
|
||||||
Debug: &debug,
|
Debug: &debug,
|
||||||
})
|
})
|
||||||
var props properties = map[Property]interface{}{
|
props := properties{
|
||||||
Command: "exit 1 || echo hello",
|
Command: "exit 1 || echo hello",
|
||||||
}
|
}
|
||||||
c := &command{
|
c := &command{
|
||||||
|
@ -50,7 +50,7 @@ func TestExecuteMultipleCommandsOrSecond(t *testing.T) {
|
||||||
env.init(&args{
|
env.init(&args{
|
||||||
Debug: &debug,
|
Debug: &debug,
|
||||||
})
|
})
|
||||||
var props properties = map[Property]interface{}{
|
props := properties{
|
||||||
Command: "echo hello || echo world",
|
Command: "echo hello || echo world",
|
||||||
}
|
}
|
||||||
c := &command{
|
c := &command{
|
||||||
|
@ -68,7 +68,7 @@ func TestExecuteMultipleCommandsAnd(t *testing.T) {
|
||||||
env.init(&args{
|
env.init(&args{
|
||||||
Debug: &debug,
|
Debug: &debug,
|
||||||
})
|
})
|
||||||
var props properties = map[Property]interface{}{
|
props := properties{
|
||||||
Command: "echo hello && echo world",
|
Command: "echo hello && echo world",
|
||||||
}
|
}
|
||||||
c := &command{
|
c := &command{
|
||||||
|
@ -86,7 +86,7 @@ func TestExecuteSingleCommandEmpty(t *testing.T) {
|
||||||
env.init(&args{
|
env.init(&args{
|
||||||
Debug: &debug,
|
Debug: &debug,
|
||||||
})
|
})
|
||||||
var props properties = map[Property]interface{}{
|
props := properties{
|
||||||
Command: "",
|
Command: "",
|
||||||
}
|
}
|
||||||
c := &command{
|
c := &command{
|
||||||
|
@ -119,7 +119,7 @@ func TestExecuteMultipleCommandsAndDisabled(t *testing.T) {
|
||||||
env.init(&args{
|
env.init(&args{
|
||||||
Debug: &debug,
|
Debug: &debug,
|
||||||
})
|
})
|
||||||
var props properties = map[Property]interface{}{
|
props := properties{
|
||||||
Command: "echo && echo",
|
Command: "echo && echo",
|
||||||
}
|
}
|
||||||
c := &command{
|
c := &command{
|
||||||
|
@ -136,7 +136,7 @@ func TestExecuteMultipleCommandsOrDisabled(t *testing.T) {
|
||||||
env.init(&args{
|
env.init(&args{
|
||||||
Debug: &debug,
|
Debug: &debug,
|
||||||
})
|
})
|
||||||
var props properties = map[Property]interface{}{
|
props := properties{
|
||||||
Command: "echo|| echo",
|
Command: "echo|| echo",
|
||||||
}
|
}
|
||||||
c := &command{
|
c := &command{
|
||||||
|
|
|
@ -8,7 +8,7 @@ func (c *crystal) string() string {
|
||||||
return c.language.string()
|
return c.language.string()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *crystal) init(props properties, env environmentInfo) {
|
func (c *crystal) init(props Properties, env environmentInfo) {
|
||||||
c.language = language{
|
c.language = language{
|
||||||
env: env,
|
env: env,
|
||||||
props: props,
|
props: props,
|
||||||
|
|
|
@ -8,7 +8,7 @@ func (d *dart) string() string {
|
||||||
return d.language.string()
|
return d.language.string()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *dart) init(props properties, env environmentInfo) {
|
func (d *dart) init(props Properties, env environmentInfo) {
|
||||||
d.language = language{
|
d.language = language{
|
||||||
env: env,
|
env: env,
|
||||||
props: props,
|
props: props,
|
||||||
|
|
|
@ -42,6 +42,10 @@ func (p properties) hasOneOf(properties ...Property) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p properties) set(property Property, value interface{}) {
|
||||||
|
p[property] = value
|
||||||
|
}
|
||||||
|
|
||||||
// GIT Segement
|
// GIT Segement
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -117,9 +121,9 @@ func (g *git) deprecatedString(statusColorsEnabled bool) string {
|
||||||
|
|
||||||
func (g *git) SetStatusColor() {
|
func (g *git) SetStatusColor() {
|
||||||
if g.props.getBool(ColorBackground, true) {
|
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 {
|
} 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 {
|
func (e *exit) deprecatedString() string {
|
||||||
colorBackground := e.props.getBool(ColorBackground, false)
|
colorBackground := e.props.getBool(ColorBackground, false)
|
||||||
if e.Code != 0 && !colorBackground {
|
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 {
|
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 {
|
if e.Code == 0 {
|
||||||
return e.props.getString(SuccessIcon, "")
|
return e.props.getString(SuccessIcon, "")
|
||||||
|
@ -228,9 +232,9 @@ func (b *batt) colorSegment() {
|
||||||
}
|
}
|
||||||
colorBackground := b.props.getBool(ColorBackground, false)
|
colorBackground := b.props.getBool(ColorBackground, false)
|
||||||
if colorBackground {
|
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 {
|
} 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() {
|
func (l *language) colorMismatch() {
|
||||||
if l.props.getBool(ColorBackground, false) {
|
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
|
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
|
// Python
|
||||||
|
@ -417,7 +421,7 @@ const (
|
||||||
// Environment Variable
|
// Environment Variable
|
||||||
|
|
||||||
type envvar struct {
|
type envvar struct {
|
||||||
props properties
|
props Properties
|
||||||
env environmentInfo
|
env environmentInfo
|
||||||
Value string
|
Value string
|
||||||
}
|
}
|
||||||
|
@ -450,7 +454,7 @@ func (e *envvar) string() string {
|
||||||
return text
|
return text
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *envvar) init(props properties, env environmentInfo) {
|
func (e *envvar) init(props Properties, env environmentInfo) {
|
||||||
e.props = props
|
e.props = props
|
||||||
e.env = env
|
e.env = env
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,11 @@ func TestGetStatusDetailStringDefault(t *testing.T) {
|
||||||
Added: 1,
|
Added: 1,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
g := &git{}
|
g := &git{
|
||||||
|
scm: scm{
|
||||||
|
props: properties{},
|
||||||
|
},
|
||||||
|
}
|
||||||
assert.Equal(t, expected, g.getStatusDetailString(status, WorkingColor, LocalWorkingIcon, "icon"))
|
assert.Equal(t, expected, g.getStatusDetailString(status, WorkingColor, LocalWorkingIcon, "icon"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +32,7 @@ func TestGetStatusDetailStringDefaultColorOverride(t *testing.T) {
|
||||||
Added: 1,
|
Added: 1,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
var props properties = map[Property]interface{}{
|
props := properties{
|
||||||
WorkingColor: "#123456",
|
WorkingColor: "#123456",
|
||||||
}
|
}
|
||||||
g := &git{
|
g := &git{
|
||||||
|
@ -46,7 +50,7 @@ func TestGetStatusDetailStringDefaultColorOverrideAndIconColorOverride(t *testin
|
||||||
Added: 1,
|
Added: 1,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
var props properties = map[Property]interface{}{
|
props := properties{
|
||||||
WorkingColor: "#123456",
|
WorkingColor: "#123456",
|
||||||
LocalWorkingIcon: "<#789123>work</>",
|
LocalWorkingIcon: "<#789123>work</>",
|
||||||
}
|
}
|
||||||
|
@ -65,7 +69,7 @@ func TestGetStatusDetailStringDefaultColorOverrideNoIconColorOverride(t *testing
|
||||||
Added: 1,
|
Added: 1,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
var props properties = map[Property]interface{}{
|
props := properties{
|
||||||
WorkingColor: "#123456",
|
WorkingColor: "#123456",
|
||||||
LocalWorkingIcon: "work",
|
LocalWorkingIcon: "work",
|
||||||
}
|
}
|
||||||
|
@ -84,7 +88,7 @@ func TestGetStatusDetailStringNoStatus(t *testing.T) {
|
||||||
Added: 1,
|
Added: 1,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
var props properties = map[Property]interface{}{
|
props := properties{
|
||||||
DisplayStatusDetail: false,
|
DisplayStatusDetail: false,
|
||||||
}
|
}
|
||||||
g := &git{
|
g := &git{
|
||||||
|
@ -102,7 +106,7 @@ func TestGetStatusDetailStringNoStatusColorOverride(t *testing.T) {
|
||||||
Added: 1,
|
Added: 1,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
var props properties = map[Property]interface{}{
|
props := properties{
|
||||||
DisplayStatusDetail: false,
|
DisplayStatusDetail: false,
|
||||||
WorkingColor: "#123456",
|
WorkingColor: "#123456",
|
||||||
}
|
}
|
||||||
|
@ -116,7 +120,7 @@ func TestGetStatusDetailStringNoStatusColorOverride(t *testing.T) {
|
||||||
|
|
||||||
func TestGetStatusColorLocalChangesStaging(t *testing.T) {
|
func TestGetStatusColorLocalChangesStaging(t *testing.T) {
|
||||||
expected := changesColor
|
expected := changesColor
|
||||||
var props properties = map[Property]interface{}{
|
props := properties{
|
||||||
LocalChangesColor: expected,
|
LocalChangesColor: expected,
|
||||||
}
|
}
|
||||||
g := &git{
|
g := &git{
|
||||||
|
@ -135,7 +139,7 @@ func TestGetStatusColorLocalChangesStaging(t *testing.T) {
|
||||||
|
|
||||||
func TestGetStatusColorLocalChangesWorking(t *testing.T) {
|
func TestGetStatusColorLocalChangesWorking(t *testing.T) {
|
||||||
expected := changesColor
|
expected := changesColor
|
||||||
var props properties = map[Property]interface{}{
|
props := properties{
|
||||||
LocalChangesColor: expected,
|
LocalChangesColor: expected,
|
||||||
}
|
}
|
||||||
g := &git{
|
g := &git{
|
||||||
|
@ -154,7 +158,7 @@ func TestGetStatusColorLocalChangesWorking(t *testing.T) {
|
||||||
|
|
||||||
func TestGetStatusColorAheadAndBehind(t *testing.T) {
|
func TestGetStatusColorAheadAndBehind(t *testing.T) {
|
||||||
expected := changesColor
|
expected := changesColor
|
||||||
var props properties = map[Property]interface{}{
|
props := properties{
|
||||||
AheadAndBehindColor: expected,
|
AheadAndBehindColor: expected,
|
||||||
}
|
}
|
||||||
g := &git{
|
g := &git{
|
||||||
|
@ -171,7 +175,7 @@ func TestGetStatusColorAheadAndBehind(t *testing.T) {
|
||||||
|
|
||||||
func TestGetStatusColorAhead(t *testing.T) {
|
func TestGetStatusColorAhead(t *testing.T) {
|
||||||
expected := changesColor
|
expected := changesColor
|
||||||
var props properties = map[Property]interface{}{
|
props := properties{
|
||||||
AheadColor: expected,
|
AheadColor: expected,
|
||||||
}
|
}
|
||||||
g := &git{
|
g := &git{
|
||||||
|
@ -188,7 +192,7 @@ func TestGetStatusColorAhead(t *testing.T) {
|
||||||
|
|
||||||
func TestGetStatusColorBehind(t *testing.T) {
|
func TestGetStatusColorBehind(t *testing.T) {
|
||||||
expected := changesColor
|
expected := changesColor
|
||||||
var props properties = map[Property]interface{}{
|
props := properties{
|
||||||
BehindColor: expected,
|
BehindColor: expected,
|
||||||
}
|
}
|
||||||
g := &git{
|
g := &git{
|
||||||
|
@ -205,7 +209,7 @@ func TestGetStatusColorBehind(t *testing.T) {
|
||||||
|
|
||||||
func TestGetStatusColorDefault(t *testing.T) {
|
func TestGetStatusColorDefault(t *testing.T) {
|
||||||
expected := changesColor
|
expected := changesColor
|
||||||
var props properties = map[Property]interface{}{
|
props := properties{
|
||||||
BehindColor: changesColor,
|
BehindColor: changesColor,
|
||||||
}
|
}
|
||||||
g := &git{
|
g := &git{
|
||||||
|
@ -222,7 +226,7 @@ func TestGetStatusColorDefault(t *testing.T) {
|
||||||
|
|
||||||
func TestSetStatusColorForeground(t *testing.T) {
|
func TestSetStatusColorForeground(t *testing.T) {
|
||||||
expected := changesColor
|
expected := changesColor
|
||||||
var props properties = map[Property]interface{}{
|
props := properties{
|
||||||
LocalChangesColor: changesColor,
|
LocalChangesColor: changesColor,
|
||||||
ColorBackground: false,
|
ColorBackground: false,
|
||||||
}
|
}
|
||||||
|
@ -238,12 +242,12 @@ func TestSetStatusColorForeground(t *testing.T) {
|
||||||
Working: &GitStatus{},
|
Working: &GitStatus{},
|
||||||
}
|
}
|
||||||
g.SetStatusColor()
|
g.SetStatusColor()
|
||||||
assert.Equal(t, expected, g.props[ForegroundOverride])
|
assert.Equal(t, expected, g.props.getColor(ForegroundOverride, ""))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSetStatusColorBackground(t *testing.T) {
|
func TestSetStatusColorBackground(t *testing.T) {
|
||||||
expected := changesColor
|
expected := changesColor
|
||||||
var props properties = map[Property]interface{}{
|
props := properties{
|
||||||
LocalChangesColor: changesColor,
|
LocalChangesColor: changesColor,
|
||||||
ColorBackground: true,
|
ColorBackground: true,
|
||||||
}
|
}
|
||||||
|
@ -259,7 +263,7 @@ func TestSetStatusColorBackground(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
g.SetStatusColor()
|
g.SetStatusColor()
|
||||||
assert.Equal(t, expected, g.props[BackgroundOverride])
|
assert.Equal(t, expected, g.props.getColor(BackgroundOverride, ""))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStatusColorsWithoutDisplayStatus(t *testing.T) {
|
func TestStatusColorsWithoutDisplayStatus(t *testing.T) {
|
||||||
|
@ -279,21 +283,22 @@ func TestStatusColorsWithoutDisplayStatus(t *testing.T) {
|
||||||
env.On("hasFilesInDir", "", "sequencer/todo").Return(false)
|
env.On("hasFilesInDir", "", "sequencer/todo").Return(false)
|
||||||
env.mockGitCommand("", "describe", "--tags", "--exact-match")
|
env.mockGitCommand("", "describe", "--tags", "--exact-match")
|
||||||
env.mockGitCommand(status, "status", "-unormal", "--branch", "--porcelain=2")
|
env.mockGitCommand(status, "status", "-unormal", "--branch", "--porcelain=2")
|
||||||
|
props := properties{
|
||||||
|
DisplayStatus: false,
|
||||||
|
StatusColorsEnabled: true,
|
||||||
|
LocalChangesColor: expected,
|
||||||
|
}
|
||||||
g := &git{
|
g := &git{
|
||||||
scm: scm{
|
scm: scm{
|
||||||
env: env,
|
env: env,
|
||||||
props: map[Property]interface{}{
|
props: props,
|
||||||
DisplayStatus: false,
|
|
||||||
StatusColorsEnabled: true,
|
|
||||||
LocalChangesColor: expected,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
gitWorkingFolder: "",
|
gitWorkingFolder: "",
|
||||||
}
|
}
|
||||||
g.Working = &GitStatus{}
|
g.Working = &GitStatus{}
|
||||||
g.Staging = &GitStatus{}
|
g.Staging = &GitStatus{}
|
||||||
g.string()
|
g.string()
|
||||||
assert.Equal(t, expected, g.props[BackgroundOverride])
|
assert.Equal(t, expected, g.props.getColor(BackgroundOverride, ""))
|
||||||
}
|
}
|
||||||
|
|
||||||
// EXIT Segement
|
// EXIT Segement
|
||||||
|
@ -320,7 +325,7 @@ func TestExitWriterDeprecatedString(t *testing.T) {
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
env := new(MockedEnvironment)
|
env := new(MockedEnvironment)
|
||||||
env.On("lastErrorCode", nil).Return(tc.ExitCode)
|
env.On("lastErrorCode", nil).Return(tc.ExitCode)
|
||||||
var props properties = map[Property]interface{}{
|
props := properties{
|
||||||
SuccessIcon: tc.SuccessIcon,
|
SuccessIcon: tc.SuccessIcon,
|
||||||
ErrorIcon: tc.ErrorIcon,
|
ErrorIcon: tc.ErrorIcon,
|
||||||
DisplayExitCode: tc.DisplayExitCode,
|
DisplayExitCode: tc.DisplayExitCode,
|
||||||
|
@ -424,7 +429,7 @@ func TestBatterySegmentSingle(t *testing.T) {
|
||||||
|
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
env := &MockedEnvironment{}
|
env := &MockedEnvironment{}
|
||||||
var props properties = map[Property]interface{}{
|
props := properties{
|
||||||
ChargingIcon: "charging ",
|
ChargingIcon: "charging ",
|
||||||
ChargedIcon: "charged ",
|
ChargedIcon: "charged ",
|
||||||
DischargingIcon: "going down ",
|
DischargingIcon: "going down ",
|
||||||
|
@ -455,9 +460,9 @@ func TestBatterySegmentSingle(t *testing.T) {
|
||||||
if len(tc.ExpectedColor) == 0 {
|
if len(tc.ExpectedColor) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
actualColor := b.props[ForegroundOverride]
|
actualColor := b.props.getColor(ForegroundOverride, "")
|
||||||
if tc.ColorBackground {
|
if tc.ColorBackground {
|
||||||
actualColor = b.props[BackgroundOverride]
|
actualColor = b.props.getColor(BackgroundOverride, "")
|
||||||
}
|
}
|
||||||
assert.Equal(t, tc.ExpectedColor, actualColor, tc.Case)
|
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", "SSH_CLIENT").Return(SSHSession)
|
||||||
env.On("getenv", defaultUserEnvVar).Return(tc.DefaultUserNameEnv)
|
env.On("getenv", defaultUserEnvVar).Return(tc.DefaultUserNameEnv)
|
||||||
env.On("isRunningAsRoot", nil).Return(tc.Root)
|
env.On("isRunningAsRoot", nil).Return(tc.Root)
|
||||||
var props properties = map[Property]interface{}{
|
props := properties{
|
||||||
UserInfoSeparator: " at ",
|
UserInfoSeparator: " at ",
|
||||||
SSHIcon: "ssh ",
|
SSHIcon: "ssh ",
|
||||||
DefaultUserName: tc.DefaultUserName,
|
DefaultUserName: tc.DefaultUserName,
|
||||||
|
@ -674,7 +679,7 @@ func TestLanguageVersionMismatch(t *testing.T) {
|
||||||
{Case: "No mismatch", Enabled: true, Mismatch: false},
|
{Case: "No mismatch", Enabled: true, Mismatch: false},
|
||||||
}
|
}
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
props := map[Property]interface{}{
|
props := properties{
|
||||||
EnableVersionMismatch: tc.Enabled,
|
EnableVersionMismatch: tc.Enabled,
|
||||||
VersionMismatchColor: tc.ExpectedColor,
|
VersionMismatchColor: tc.ExpectedColor,
|
||||||
ColorBackground: tc.ColorBackground,
|
ColorBackground: tc.ColorBackground,
|
||||||
|
@ -709,7 +714,7 @@ func TestLanguageVersionMismatch(t *testing.T) {
|
||||||
assert.True(t, lang.enabled(), tc.Case)
|
assert.True(t, lang.enabled(), tc.Case)
|
||||||
assert.Equal(t, universion, lang.string(), tc.Case)
|
assert.Equal(t, universion, lang.string(), tc.Case)
|
||||||
if tc.ColorBackground {
|
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
|
return
|
||||||
}
|
}
|
||||||
assert.Equal(t, tc.ExpectedColor, lang.props.getColor(ForegroundOverride, ""), tc.Case)
|
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("getPathSeperator", nil).Return("")
|
||||||
env.On("getcwd", nil).Return("/usr/home/project")
|
env.On("getcwd", nil).Return("/usr/home/project")
|
||||||
env.On("homeDir", nil).Return("/usr/home")
|
env.On("homeDir", nil).Return("/usr/home")
|
||||||
var props properties = map[Property]interface{}{
|
props := properties{
|
||||||
FetchVersion: tc.FetchVersion,
|
FetchVersion: tc.FetchVersion,
|
||||||
DisplayVirtualEnv: true,
|
DisplayVirtualEnv: true,
|
||||||
DisplayDefault: tc.DisplayDefault,
|
DisplayDefault: tc.DisplayDefault,
|
||||||
|
@ -772,7 +777,7 @@ func TestEnvvarAvailable(t *testing.T) {
|
||||||
env.On("getenv", name).Return(expected)
|
env.On("getenv", name).Return(expected)
|
||||||
e := &envvar{
|
e := &envvar{
|
||||||
env: env,
|
env: env,
|
||||||
props: map[Property]interface{}{
|
props: properties{
|
||||||
VarName: name,
|
VarName: name,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -787,7 +792,7 @@ func TestEnvvarNotAvailable(t *testing.T) {
|
||||||
env.On("getenv", name).Return(expected)
|
env.On("getenv", name).Return(expected)
|
||||||
e := &envvar{
|
e := &envvar{
|
||||||
env: env,
|
env: env,
|
||||||
props: map[Property]interface{}{
|
props: properties{
|
||||||
VarName: name,
|
VarName: name,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ func (d *dotnet) string() string {
|
||||||
return version
|
return version
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *dotnet) init(props properties, env environmentInfo) {
|
func (d *dotnet) init(props Properties, env environmentInfo) {
|
||||||
d.language = language{
|
d.language = language{
|
||||||
env: env,
|
env: env,
|
||||||
props: props,
|
props: props,
|
||||||
|
|
|
@ -28,7 +28,7 @@ func bootStrapDotnetTest(args *dotnetArgs) *dotnet {
|
||||||
env.On("getPathSeperator", nil).Return("")
|
env.On("getPathSeperator", nil).Return("")
|
||||||
env.On("getcwd", nil).Return("/usr/home/project")
|
env.On("getcwd", nil).Return("/usr/home/project")
|
||||||
env.On("homeDir", nil).Return("/usr/home")
|
env.On("homeDir", nil).Return("/usr/home")
|
||||||
var props properties = map[Property]interface{}{
|
props := properties{
|
||||||
FetchVersion: args.displayVersion,
|
FetchVersion: args.displayVersion,
|
||||||
UnsupportedDotnetVersionIcon: args.unsupportedIcon,
|
UnsupportedDotnetVersionIcon: args.unsupportedIcon,
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type executiontime struct {
|
type executiontime struct {
|
||||||
props properties
|
props Properties
|
||||||
env environmentInfo
|
env environmentInfo
|
||||||
|
|
||||||
FormattedMs string
|
FormattedMs string
|
||||||
|
@ -63,7 +63,7 @@ func (t *executiontime) string() string {
|
||||||
return t.FormattedMs
|
return t.FormattedMs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *executiontime) init(props properties, env environmentInfo) {
|
func (t *executiontime) init(props Properties, env environmentInfo) {
|
||||||
t.props = props
|
t.props = props
|
||||||
t.env = env
|
t.env = env
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,8 @@ func TestExecutionTimeWriterDefaultThresholdEnabled(t *testing.T) {
|
||||||
env := new(MockedEnvironment)
|
env := new(MockedEnvironment)
|
||||||
env.On("executionTime", nil).Return(1337)
|
env.On("executionTime", nil).Return(1337)
|
||||||
executionTime := &executiontime{
|
executionTime := &executiontime{
|
||||||
env: env,
|
env: env,
|
||||||
|
props: properties{},
|
||||||
}
|
}
|
||||||
assert.True(t, executionTime.enabled())
|
assert.True(t, executionTime.enabled())
|
||||||
}
|
}
|
||||||
|
@ -20,7 +21,8 @@ func TestExecutionTimeWriterDefaultThresholdDisabled(t *testing.T) {
|
||||||
env := new(MockedEnvironment)
|
env := new(MockedEnvironment)
|
||||||
env.On("executionTime", nil).Return(1)
|
env.On("executionTime", nil).Return(1)
|
||||||
executionTime := &executiontime{
|
executionTime := &executiontime{
|
||||||
env: env,
|
env: env,
|
||||||
|
props: properties{},
|
||||||
}
|
}
|
||||||
assert.False(t, executionTime.enabled())
|
assert.False(t, executionTime.enabled())
|
||||||
}
|
}
|
||||||
|
@ -28,7 +30,7 @@ func TestExecutionTimeWriterDefaultThresholdDisabled(t *testing.T) {
|
||||||
func TestExecutionTimeWriterCustomThresholdEnabled(t *testing.T) {
|
func TestExecutionTimeWriterCustomThresholdEnabled(t *testing.T) {
|
||||||
env := new(MockedEnvironment)
|
env := new(MockedEnvironment)
|
||||||
env.On("executionTime", nil).Return(99)
|
env.On("executionTime", nil).Return(99)
|
||||||
var props properties = map[Property]interface{}{
|
props := properties{
|
||||||
ThresholdProperty: float64(10),
|
ThresholdProperty: float64(10),
|
||||||
}
|
}
|
||||||
executionTime := &executiontime{
|
executionTime := &executiontime{
|
||||||
|
@ -41,7 +43,7 @@ func TestExecutionTimeWriterCustomThresholdEnabled(t *testing.T) {
|
||||||
func TestExecutionTimeWriterCustomThresholdDisabled(t *testing.T) {
|
func TestExecutionTimeWriterCustomThresholdDisabled(t *testing.T) {
|
||||||
env := new(MockedEnvironment)
|
env := new(MockedEnvironment)
|
||||||
env.On("executionTime", nil).Return(99)
|
env.On("executionTime", nil).Return(99)
|
||||||
var props properties = map[Property]interface{}{
|
props := properties{
|
||||||
ThresholdProperty: float64(100),
|
ThresholdProperty: float64(100),
|
||||||
}
|
}
|
||||||
executionTime := &executiontime{
|
executionTime := &executiontime{
|
||||||
|
@ -57,7 +59,8 @@ func TestExecutionTimeWriterDuration(t *testing.T) {
|
||||||
env := new(MockedEnvironment)
|
env := new(MockedEnvironment)
|
||||||
env.On("executionTime", nil).Return(input)
|
env.On("executionTime", nil).Return(input)
|
||||||
executionTime := &executiontime{
|
executionTime := &executiontime{
|
||||||
env: env,
|
env: env,
|
||||||
|
props: properties{},
|
||||||
}
|
}
|
||||||
executionTime.enabled()
|
executionTime.enabled()
|
||||||
assert.Equal(t, expected, executionTime.FormattedMs)
|
assert.Equal(t, expected, executionTime.FormattedMs)
|
||||||
|
@ -69,7 +72,8 @@ func TestExecutionTimeWriterDuration2(t *testing.T) {
|
||||||
env := new(MockedEnvironment)
|
env := new(MockedEnvironment)
|
||||||
env.On("executionTime", nil).Return(input)
|
env.On("executionTime", nil).Return(input)
|
||||||
executionTime := &executiontime{
|
executionTime := &executiontime{
|
||||||
env: env,
|
env: env,
|
||||||
|
props: properties{},
|
||||||
}
|
}
|
||||||
executionTime.enabled()
|
executionTime.enabled()
|
||||||
assert.Equal(t, expected, executionTime.FormattedMs)
|
assert.Equal(t, expected, executionTime.FormattedMs)
|
||||||
|
|
|
@ -3,7 +3,7 @@ package main
|
||||||
import "strconv"
|
import "strconv"
|
||||||
|
|
||||||
type exit struct {
|
type exit struct {
|
||||||
props properties
|
props Properties
|
||||||
env environmentInfo
|
env environmentInfo
|
||||||
|
|
||||||
Code int
|
Code int
|
||||||
|
@ -21,7 +21,7 @@ func (e *exit) string() string {
|
||||||
return e.getFormattedText()
|
return e.getFormattedText()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *exit) init(props properties, env environmentInfo) {
|
func (e *exit) init(props Properties, env environmentInfo) {
|
||||||
e.props = props
|
e.props = props
|
||||||
e.env = env
|
e.env = env
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,8 @@ func TestExitWriterEnabled(t *testing.T) {
|
||||||
env := new(MockedEnvironment)
|
env := new(MockedEnvironment)
|
||||||
env.On("lastErrorCode", nil).Return(tc.ExitCode)
|
env.On("lastErrorCode", nil).Return(tc.ExitCode)
|
||||||
e := &exit{
|
e := &exit{
|
||||||
env: env,
|
env: env,
|
||||||
|
props: properties{},
|
||||||
}
|
}
|
||||||
assert.Equal(t, tc.Expected, e.enabled())
|
assert.Equal(t, tc.Expected, e.enabled())
|
||||||
}
|
}
|
||||||
|
@ -76,7 +77,7 @@ func TestExitWriterTemplateString(t *testing.T) {
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
env := new(MockedEnvironment)
|
env := new(MockedEnvironment)
|
||||||
env.On("lastErrorCode", nil).Return(tc.ExitCode)
|
env.On("lastErrorCode", nil).Return(tc.ExitCode)
|
||||||
var props properties = map[Property]interface{}{
|
props := properties{
|
||||||
SegmentTemplate: tc.Template,
|
SegmentTemplate: tc.Template,
|
||||||
}
|
}
|
||||||
e := &exit{
|
e := &exit{
|
||||||
|
|
|
@ -21,7 +21,8 @@ func TestEnabledGitNotFound(t *testing.T) {
|
||||||
env.On("isWsl", nil).Return(false)
|
env.On("isWsl", nil).Return(false)
|
||||||
g := &git{
|
g := &git{
|
||||||
scm: scm{
|
scm: scm{
|
||||||
env: env,
|
env: env,
|
||||||
|
props: properties{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.False(t, g.enabled())
|
assert.False(t, g.enabled())
|
||||||
|
@ -41,7 +42,8 @@ func TestEnabledInWorkingDirectory(t *testing.T) {
|
||||||
env.On("hasParentFilePath", ".git").Return(fileInfo, nil)
|
env.On("hasParentFilePath", ".git").Return(fileInfo, nil)
|
||||||
g := &git{
|
g := &git{
|
||||||
scm: scm{
|
scm: scm{
|
||||||
env: env,
|
env: env,
|
||||||
|
props: properties{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.True(t, g.enabled())
|
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")
|
env.On("getFileContent", "/dev/real_folder/.git/worktrees/folder_worktree/gitdir").Return("/dev/folder_worktree.git\n")
|
||||||
g := &git{
|
g := &git{
|
||||||
scm: scm{
|
scm: scm{
|
||||||
env: env,
|
env: env,
|
||||||
|
props: properties{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.True(t, g.enabled())
|
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")
|
env.On("getFileContent", "/dev/parent/.git/modules/test-submodule").Return("/dev/folder_worktree.git\n")
|
||||||
g := &git{
|
g := &git{
|
||||||
scm: scm{
|
scm: scm{
|
||||||
env: env,
|
env: env,
|
||||||
|
props: properties{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.True(t, g.enabled())
|
assert.True(t, g.enabled())
|
||||||
|
@ -107,7 +111,8 @@ func TestGetGitOutputForCommand(t *testing.T) {
|
||||||
env.On("getRuntimeGOOS", nil).Return("unix")
|
env.On("getRuntimeGOOS", nil).Return("unix")
|
||||||
g := &git{
|
g := &git{
|
||||||
scm: scm{
|
scm: scm{
|
||||||
env: env,
|
env: env,
|
||||||
|
props: properties{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
got := g.getGitCommandOutput(commandArgs...)
|
got := g.getGitCommandOutput(commandArgs...)
|
||||||
|
@ -256,7 +261,7 @@ func TestSetGitHEADContextClean(t *testing.T) {
|
||||||
g := &git{
|
g := &git{
|
||||||
scm: scm{
|
scm: scm{
|
||||||
env: env,
|
env: env,
|
||||||
props: map[Property]interface{}{
|
props: properties{
|
||||||
BranchIcon: "branch ",
|
BranchIcon: "branch ",
|
||||||
CommitIcon: "commit ",
|
CommitIcon: "commit ",
|
||||||
RebaseIcon: "rebase ",
|
RebaseIcon: "rebase ",
|
||||||
|
@ -298,7 +303,7 @@ func TestSetPrettyHEADName(t *testing.T) {
|
||||||
g := &git{
|
g := &git{
|
||||||
scm: scm{
|
scm: scm{
|
||||||
env: env,
|
env: env,
|
||||||
props: map[Property]interface{}{
|
props: properties{
|
||||||
BranchIcon: "branch ",
|
BranchIcon: "branch ",
|
||||||
CommitIcon: "commit ",
|
CommitIcon: "commit ",
|
||||||
TagIcon: "tag ",
|
TagIcon: "tag ",
|
||||||
|
@ -476,7 +481,7 @@ func TestGitUpstream(t *testing.T) {
|
||||||
env.On("runCommand", "git", []string{"-C", "", "--no-optional-locks", "-c", "core.quotepath=false",
|
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)
|
"-c", "color.status=false", "remote", "get-url", "origin"}).Return(tc.Upstream, nil)
|
||||||
env.On("getRuntimeGOOS", nil).Return("unix")
|
env.On("getRuntimeGOOS", nil).Return("unix")
|
||||||
var props properties = map[Property]interface{}{
|
props := properties{
|
||||||
GithubIcon: "GH",
|
GithubIcon: "GH",
|
||||||
GitlabIcon: "GL",
|
GitlabIcon: "GL",
|
||||||
BitbucketIcon: "BB",
|
BitbucketIcon: "BB",
|
||||||
|
@ -512,7 +517,7 @@ func TestGetBranchStatus(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
var props properties = map[Property]interface{}{
|
props := properties{
|
||||||
BranchAheadIcon: "up",
|
BranchAheadIcon: "up",
|
||||||
BranchBehindIcon: "down",
|
BranchBehindIcon: "down",
|
||||||
BranchIdenticalIcon: "equal",
|
BranchIdenticalIcon: "equal",
|
||||||
|
@ -544,7 +549,7 @@ func TestShouldIgnoreRootRepository(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
var props properties = map[Property]interface{}{
|
props := properties{
|
||||||
ExcludeFolders: []string{
|
ExcludeFolders: []string{
|
||||||
"/home/bill",
|
"/home/bill",
|
||||||
"/home/gates.*",
|
"/home/gates.*",
|
||||||
|
@ -730,7 +735,7 @@ func TestGitTemplateString(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
var props properties = map[Property]interface{}{
|
props := properties{
|
||||||
FetchStatus: true,
|
FetchStatus: true,
|
||||||
}
|
}
|
||||||
tc.Git.props = props
|
tc.Git.props = props
|
||||||
|
|
|
@ -16,7 +16,7 @@ func (g *golang) string() string {
|
||||||
return g.language.string()
|
return g.language.string()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *golang) init(props properties, env environmentInfo) {
|
func (g *golang) init(props Properties, env environmentInfo) {
|
||||||
g.language = language{
|
g.language = language{
|
||||||
env: env,
|
env: env,
|
||||||
props: props,
|
props: props,
|
||||||
|
|
|
@ -23,7 +23,7 @@ func getMockedLanguageEnv(params *mockedLanguageParams) (*MockedEnvironment, pro
|
||||||
env.On("hasFiles", params.extension).Return(true)
|
env.On("hasFiles", params.extension).Return(true)
|
||||||
env.On("getcwd", nil).Return("/usr/home/project")
|
env.On("getcwd", nil).Return("/usr/home/project")
|
||||||
env.On("homeDir", nil).Return("/usr/home")
|
env.On("homeDir", nil).Return("/usr/home")
|
||||||
var props properties = map[Property]interface{}{
|
props := properties{
|
||||||
FetchVersion: true,
|
FetchVersion: true,
|
||||||
}
|
}
|
||||||
return env, props
|
return env, props
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
type ipify struct {
|
type ipify struct {
|
||||||
props properties
|
props Properties
|
||||||
env environmentInfo
|
env environmentInfo
|
||||||
IP string
|
IP string
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ func (i *ipify) getResult() (string, error) {
|
||||||
return response, nil
|
return response, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *ipify) init(props properties, env environmentInfo) {
|
func (i *ipify) init(props Properties, env environmentInfo) {
|
||||||
i.props = props
|
i.props = props
|
||||||
i.env = env
|
i.env = env
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ func TestIpifySegment(t *testing.T) {
|
||||||
|
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
env := &MockedEnvironment{}
|
env := &MockedEnvironment{}
|
||||||
var props properties = map[Property]interface{}{
|
props := properties{
|
||||||
CacheTimeout: 0,
|
CacheTimeout: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ func (j *java) string() string {
|
||||||
return j.language.string()
|
return j.language.string()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *java) init(props properties, env environmentInfo) {
|
func (j *java) init(props Properties, env environmentInfo) {
|
||||||
javaRegex := `(?: JRE)(?: \(.*\))? \((?P<version>(?P<major>[0-9]+)(?:\.(?P<minor>[0-9]+))?(?:\.(?P<patch>[0-9]+))?).*\),`
|
javaRegex := `(?: JRE)(?: \(.*\))? \((?P<version>(?P<major>[0-9]+)(?:\.(?P<minor>[0-9]+))?(?:\.(?P<patch>[0-9]+))?).*\),`
|
||||||
javaCmd := &cmd{
|
javaCmd := &cmd{
|
||||||
executable: "java",
|
executable: "java",
|
||||||
|
|
|
@ -66,7 +66,7 @@ func TestJava(t *testing.T) {
|
||||||
} else {
|
} else {
|
||||||
env.On("getenv", "JAVA_HOME").Return("")
|
env.On("getenv", "JAVA_HOME").Return("")
|
||||||
}
|
}
|
||||||
var props properties = map[Property]interface{}{
|
props := properties{
|
||||||
FetchVersion: true,
|
FetchVersion: true,
|
||||||
}
|
}
|
||||||
j := &java{}
|
j := &java{}
|
||||||
|
|
|
@ -8,7 +8,7 @@ func (j *julia) string() string {
|
||||||
return j.language.string()
|
return j.language.string()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *julia) init(props properties, env environmentInfo) {
|
func (j *julia) init(props Properties, env environmentInfo) {
|
||||||
j.language = language{
|
j.language = language{
|
||||||
env: env,
|
env: env,
|
||||||
props: props,
|
props: props,
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
const ParseKubeConfig Property = "parse_kubeconfig"
|
const ParseKubeConfig Property = "parse_kubeconfig"
|
||||||
|
|
||||||
type kubectl struct {
|
type kubectl struct {
|
||||||
props properties
|
props Properties
|
||||||
env environmentInfo
|
env environmentInfo
|
||||||
Context string
|
Context string
|
||||||
KubeContext
|
KubeContext
|
||||||
|
@ -44,7 +44,7 @@ func (k *kubectl) string() string {
|
||||||
return text
|
return text
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k *kubectl) init(props properties, env environmentInfo) {
|
func (k *kubectl) init(props Properties, env environmentInfo) {
|
||||||
k.props = props
|
k.props = props
|
||||||
k.env = env
|
k.env = env
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,7 +128,7 @@ func TestKubectlSegment(t *testing.T) {
|
||||||
|
|
||||||
k := &kubectl{
|
k := &kubectl{
|
||||||
env: env,
|
env: env,
|
||||||
props: map[Property]interface{}{
|
props: properties{
|
||||||
SegmentTemplate: tc.Template,
|
SegmentTemplate: tc.Template,
|
||||||
DisplayError: tc.DisplayError,
|
DisplayError: tc.DisplayError,
|
||||||
ParseKubeConfig: tc.ParseKubeConfig,
|
ParseKubeConfig: tc.ParseKubeConfig,
|
||||||
|
|
|
@ -47,7 +47,7 @@ func (c *cmd) parse(versionInfo string) (*version, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type language struct {
|
type language struct {
|
||||||
props properties
|
props Properties
|
||||||
env environmentInfo
|
env environmentInfo
|
||||||
extensions []string
|
extensions []string
|
||||||
commands []*cmd
|
commands []*cmd
|
||||||
|
|
|
@ -20,7 +20,7 @@ type languageArgs struct {
|
||||||
enabledCommands []string
|
enabledCommands []string
|
||||||
versionURLTemplate string
|
versionURLTemplate string
|
||||||
expectedError error
|
expectedError error
|
||||||
properties map[Property]interface{}
|
properties Properties
|
||||||
matchesVersionFile matchesVersionFile
|
matchesVersionFile matchesVersionFile
|
||||||
inHome bool
|
inHome bool
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,9 @@ func bootStrapLanguageTest(args *languageArgs) *language {
|
||||||
}
|
}
|
||||||
env.On("getcwd", nil).Return(cwd)
|
env.On("getcwd", nil).Return(cwd)
|
||||||
env.On("homeDir", nil).Return(home)
|
env.On("homeDir", nil).Return(home)
|
||||||
|
if args.properties == nil {
|
||||||
|
args.properties = properties{}
|
||||||
|
}
|
||||||
l := &language{
|
l := &language{
|
||||||
props: args.properties,
|
props: args.properties,
|
||||||
env: env,
|
env: env,
|
||||||
|
@ -78,7 +81,7 @@ func TestLanguageFilesFoundButNoCommandAndVersionAndDisplayVersion(t *testing.T)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLanguageFilesFoundButNoCommandAndVersionAndDontDisplayVersion(t *testing.T) {
|
func TestLanguageFilesFoundButNoCommandAndVersionAndDontDisplayVersion(t *testing.T) {
|
||||||
props := map[Property]interface{}{
|
props := properties{
|
||||||
FetchVersion: false,
|
FetchVersion: false,
|
||||||
}
|
}
|
||||||
args := &languageArgs{
|
args := &languageArgs{
|
||||||
|
@ -228,7 +231,7 @@ func TestLanguageEnabledAllExtensionsFound(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLanguageEnabledNoVersion(t *testing.T) {
|
func TestLanguageEnabledNoVersion(t *testing.T) {
|
||||||
props := map[Property]interface{}{
|
props := properties{
|
||||||
FetchVersion: false,
|
FetchVersion: false,
|
||||||
}
|
}
|
||||||
args := &languageArgs{
|
args := &languageArgs{
|
||||||
|
@ -251,7 +254,7 @@ func TestLanguageEnabledNoVersion(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLanguageEnabledMissingCommand(t *testing.T) {
|
func TestLanguageEnabledMissingCommand(t *testing.T) {
|
||||||
props := map[Property]interface{}{
|
props := properties{
|
||||||
FetchVersion: false,
|
FetchVersion: false,
|
||||||
}
|
}
|
||||||
args := &languageArgs{
|
args := &languageArgs{
|
||||||
|
@ -268,7 +271,7 @@ func TestLanguageEnabledMissingCommand(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLanguageEnabledNoVersionData(t *testing.T) {
|
func TestLanguageEnabledNoVersionData(t *testing.T) {
|
||||||
props := map[Property]interface{}{
|
props := properties{
|
||||||
FetchVersion: true,
|
FetchVersion: true,
|
||||||
}
|
}
|
||||||
args := &languageArgs{
|
args := &languageArgs{
|
||||||
|
@ -292,7 +295,7 @@ func TestLanguageEnabledNoVersionData(t *testing.T) {
|
||||||
|
|
||||||
func TestLanguageEnabledMissingCommandCustomText(t *testing.T) {
|
func TestLanguageEnabledMissingCommandCustomText(t *testing.T) {
|
||||||
expected := "missing"
|
expected := "missing"
|
||||||
props := map[Property]interface{}{
|
props := properties{
|
||||||
MissingCommandText: expected,
|
MissingCommandText: expected,
|
||||||
}
|
}
|
||||||
args := &languageArgs{
|
args := &languageArgs{
|
||||||
|
@ -309,7 +312,7 @@ func TestLanguageEnabledMissingCommandCustomText(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLanguageEnabledMissingCommandCustomTextHideError(t *testing.T) {
|
func TestLanguageEnabledMissingCommandCustomTextHideError(t *testing.T) {
|
||||||
props := map[Property]interface{}{
|
props := properties{
|
||||||
MissingCommandText: "missing",
|
MissingCommandText: "missing",
|
||||||
DisplayError: false,
|
DisplayError: false,
|
||||||
}
|
}
|
||||||
|
@ -349,7 +352,7 @@ func TestLanguageEnabledCommandExitCode(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLanguageHyperlinkEnabled(t *testing.T) {
|
func TestLanguageHyperlinkEnabled(t *testing.T) {
|
||||||
props := map[Property]interface{}{
|
props := properties{
|
||||||
EnableHyperlink: true,
|
EnableHyperlink: true,
|
||||||
}
|
}
|
||||||
args := &languageArgs{
|
args := &languageArgs{
|
||||||
|
@ -378,7 +381,7 @@ func TestLanguageHyperlinkEnabled(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLanguageHyperlinkEnabledWrongRegex(t *testing.T) {
|
func TestLanguageHyperlinkEnabledWrongRegex(t *testing.T) {
|
||||||
props := map[Property]interface{}{
|
props := properties{
|
||||||
EnableHyperlink: true,
|
EnableHyperlink: true,
|
||||||
}
|
}
|
||||||
args := &languageArgs{
|
args := &languageArgs{
|
||||||
|
@ -407,7 +410,7 @@ func TestLanguageHyperlinkEnabledWrongRegex(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLanguageHyperlinkEnabledLessParamInTemplate(t *testing.T) {
|
func TestLanguageHyperlinkEnabledLessParamInTemplate(t *testing.T) {
|
||||||
props := map[Property]interface{}{
|
props := properties{
|
||||||
EnableHyperlink: true,
|
EnableHyperlink: true,
|
||||||
}
|
}
|
||||||
args := &languageArgs{
|
args := &languageArgs{
|
||||||
|
@ -445,7 +448,7 @@ func TestLanguageEnabledInHome(t *testing.T) {
|
||||||
{Case: "Context disabled", HomeEnabled: false, ExpectedEnabled: false},
|
{Case: "Context disabled", HomeEnabled: false, ExpectedEnabled: false},
|
||||||
}
|
}
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
props := map[Property]interface{}{
|
props := properties{
|
||||||
HomeEnabled: tc.HomeEnabled,
|
HomeEnabled: tc.HomeEnabled,
|
||||||
}
|
}
|
||||||
args := &languageArgs{
|
args := &languageArgs{
|
||||||
|
@ -469,7 +472,7 @@ func TestLanguageEnabledInHome(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLanguageHyperlinkEnabledMoreParamInTemplate(t *testing.T) {
|
func TestLanguageHyperlinkEnabledMoreParamInTemplate(t *testing.T) {
|
||||||
props := map[Property]interface{}{
|
props := properties{
|
||||||
EnableHyperlink: true,
|
EnableHyperlink: true,
|
||||||
}
|
}
|
||||||
args := &languageArgs{
|
args := &languageArgs{
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type nbgv struct {
|
type nbgv struct {
|
||||||
props properties
|
props Properties
|
||||||
env environmentInfo
|
env environmentInfo
|
||||||
nbgv *versionInfo
|
nbgv *versionInfo
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ func (n *nbgv) string() string {
|
||||||
return text
|
return text
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *nbgv) init(props properties, env environmentInfo) {
|
func (n *nbgv) init(props Properties, env environmentInfo) {
|
||||||
n.props = props
|
n.props = props
|
||||||
n.env = env
|
n.env = env
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,7 @@ func TestNbgv(t *testing.T) {
|
||||||
env.On("runCommand", "nbgv", []string{"get-version", "--format=json"}).Return(tc.Response, tc.Error)
|
env.On("runCommand", "nbgv", []string{"get-version", "--format=json"}).Return(tc.Response, tc.Error)
|
||||||
nbgv := &nbgv{
|
nbgv := &nbgv{
|
||||||
env: env,
|
env: env,
|
||||||
props: map[Property]interface{}{
|
props: properties{
|
||||||
SegmentTemplate: tc.SegmentTemplate,
|
SegmentTemplate: tc.SegmentTemplate,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
|
|
||||||
// segment struct, makes templating easier
|
// segment struct, makes templating easier
|
||||||
type nightscout struct {
|
type nightscout struct {
|
||||||
props properties
|
props Properties
|
||||||
env environmentInfo
|
env environmentInfo
|
||||||
|
|
||||||
NightscoutData
|
NightscoutData
|
||||||
|
@ -148,7 +148,7 @@ func (ns *nightscout) getResult() (*NightscoutData, error) {
|
||||||
return data, nil
|
return data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ns *nightscout) init(props properties, env environmentInfo) {
|
func (ns *nightscout) init(props Properties, env environmentInfo) {
|
||||||
ns.props = props
|
ns.props = props
|
||||||
ns.env = env
|
ns.env = env
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,7 +130,7 @@ func TestNSSegment(t *testing.T) {
|
||||||
|
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
env := &MockedEnvironment{}
|
env := &MockedEnvironment{}
|
||||||
var props properties = map[Property]interface{}{
|
props := properties{
|
||||||
CacheTimeout: tc.CacheTimeout,
|
CacheTimeout: tc.CacheTimeout,
|
||||||
URL: "FAKE",
|
URL: "FAKE",
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,7 @@ func (n *node) string() string {
|
||||||
return n.language.renderTemplate(segmentTemplate, n)
|
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{
|
n.language = language{
|
||||||
env: env,
|
env: env,
|
||||||
props: props,
|
props: props,
|
||||||
|
|
|
@ -67,7 +67,7 @@ func TestNodeInContext(t *testing.T) {
|
||||||
node := &node{
|
node := &node{
|
||||||
language: language{
|
language: language{
|
||||||
env: env,
|
env: env,
|
||||||
props: map[Property]interface{}{
|
props: properties{
|
||||||
YarnIcon: "yarn",
|
YarnIcon: "yarn",
|
||||||
NPMIcon: "npm",
|
NPMIcon: "npm",
|
||||||
DisplayPackageManager: tc.PkgMgrEnabled,
|
DisplayPackageManager: tc.PkgMgrEnabled,
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type osInfo struct {
|
type osInfo struct {
|
||||||
props properties
|
props Properties
|
||||||
env environmentInfo
|
env environmentInfo
|
||||||
OS string
|
OS string
|
||||||
}
|
}
|
||||||
|
@ -145,7 +145,7 @@ func (n *osInfo) getDistroName(distro, defaultName string) string {
|
||||||
return n.props.getString(Linux, "\uF17C")
|
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.props = props
|
||||||
n.env = env
|
n.env = env
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,7 @@ func TestOSInfo(t *testing.T) {
|
||||||
env.On("getPlatform", nil).Return(tc.Platform)
|
env.On("getPlatform", nil).Return(tc.Platform)
|
||||||
osInfo := &osInfo{
|
osInfo := &osInfo{
|
||||||
env: env,
|
env: env,
|
||||||
props: map[Property]interface{}{
|
props: properties{
|
||||||
WSL: "WSL",
|
WSL: "WSL",
|
||||||
WSLSeparator: " at ",
|
WSLSeparator: " at ",
|
||||||
DisplayDistroName: tc.DisplayDistroName,
|
DisplayDistroName: tc.DisplayDistroName,
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type owm struct {
|
type owm struct {
|
||||||
props properties
|
props Properties
|
||||||
env environmentInfo
|
env environmentInfo
|
||||||
Temperature float64
|
Temperature float64
|
||||||
Weather string
|
Weather string
|
||||||
|
@ -173,7 +173,7 @@ func (d *owm) setStatus() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *owm) init(props properties, env environmentInfo) {
|
func (d *owm) init(props Properties, env environmentInfo) {
|
||||||
d.props = props
|
d.props = props
|
||||||
d.env = env
|
d.env = env
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,7 @@ func TestOWMSegmentSingle(t *testing.T) {
|
||||||
|
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
env := &MockedEnvironment{}
|
env := &MockedEnvironment{}
|
||||||
var props properties = map[Property]interface{}{
|
props := properties{
|
||||||
APIKey: "key",
|
APIKey: "key",
|
||||||
Location: "AMSTERDAM,NL",
|
Location: "AMSTERDAM,NL",
|
||||||
Units: "metric",
|
Units: "metric",
|
||||||
|
@ -187,7 +187,7 @@ func TestOWMSegmentIcons(t *testing.T) {
|
||||||
env.On("doGet", OWMAPIURL).Return([]byte(response), nil)
|
env.On("doGet", OWMAPIURL).Return([]byte(response), nil)
|
||||||
|
|
||||||
o := &owm{
|
o := &owm{
|
||||||
props: map[Property]interface{}{
|
props: properties{
|
||||||
APIKey: "key",
|
APIKey: "key",
|
||||||
Location: "AMSTERDAM,NL",
|
Location: "AMSTERDAM,NL",
|
||||||
Units: "metric",
|
Units: "metric",
|
||||||
|
@ -210,7 +210,7 @@ func TestOWMSegmentIcons(t *testing.T) {
|
||||||
env.On("doGet", OWMAPIURL).Return([]byte(response), nil)
|
env.On("doGet", OWMAPIURL).Return([]byte(response), nil)
|
||||||
|
|
||||||
o := &owm{
|
o := &owm{
|
||||||
props: map[Property]interface{}{
|
props: properties{
|
||||||
APIKey: "key",
|
APIKey: "key",
|
||||||
Location: "AMSTERDAM,NL",
|
Location: "AMSTERDAM,NL",
|
||||||
Units: "metric",
|
Units: "metric",
|
||||||
|
@ -232,7 +232,7 @@ func TestOWMSegmentFromCache(t *testing.T) {
|
||||||
env := &MockedEnvironment{}
|
env := &MockedEnvironment{}
|
||||||
cache := &MockedCache{}
|
cache := &MockedCache{}
|
||||||
o := &owm{
|
o := &owm{
|
||||||
props: map[Property]interface{}{
|
props: properties{
|
||||||
APIKey: "key",
|
APIKey: "key",
|
||||||
Location: "AMSTERDAM,NL",
|
Location: "AMSTERDAM,NL",
|
||||||
Units: "metric",
|
Units: "metric",
|
||||||
|
@ -256,7 +256,7 @@ func TestOWMSegmentFromCacheWithHyperlink(t *testing.T) {
|
||||||
cache := &MockedCache{}
|
cache := &MockedCache{}
|
||||||
|
|
||||||
o := &owm{
|
o := &owm{
|
||||||
props: map[Property]interface{}{
|
props: properties{
|
||||||
APIKey: "key",
|
APIKey: "key",
|
||||||
Location: "AMSTERDAM,NL",
|
Location: "AMSTERDAM,NL",
|
||||||
Units: "metric",
|
Units: "metric",
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type path struct {
|
type path struct {
|
||||||
props properties
|
props Properties
|
||||||
env environmentInfo
|
env environmentInfo
|
||||||
|
|
||||||
PWD string
|
PWD string
|
||||||
|
@ -112,7 +112,7 @@ func (pt *path) formatWindowsDrive(pwd string) string {
|
||||||
return pwd + "\\"
|
return pwd + "\\"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pt *path) init(props properties, env environmentInfo) {
|
func (pt *path) init(props Properties, env environmentInfo) {
|
||||||
pt.props = props
|
pt.props = props
|
||||||
pt.env = env
|
pt.env = env
|
||||||
}
|
}
|
||||||
|
|
|
@ -267,7 +267,7 @@ func TestRootLocationHome(t *testing.T) {
|
||||||
env.On("getRuntimeGOOS", nil).Return("")
|
env.On("getRuntimeGOOS", nil).Return("")
|
||||||
path := &path{
|
path := &path{
|
||||||
env: env,
|
env: env,
|
||||||
props: map[Property]interface{}{
|
props: properties{
|
||||||
HomeIcon: tc.HomeIcon,
|
HomeIcon: tc.HomeIcon,
|
||||||
WindowsRegistryIcon: tc.RegistryIcon,
|
WindowsRegistryIcon: tc.RegistryIcon,
|
||||||
},
|
},
|
||||||
|
@ -419,7 +419,7 @@ func TestAgnosterPathStyles(t *testing.T) {
|
||||||
env.On("getArgs", nil).Return(args)
|
env.On("getArgs", nil).Return(args)
|
||||||
path := &path{
|
path := &path{
|
||||||
env: env,
|
env: env,
|
||||||
props: map[Property]interface{}{
|
props: properties{
|
||||||
FolderSeparatorIcon: tc.FolderSeparatorIcon,
|
FolderSeparatorIcon: tc.FolderSeparatorIcon,
|
||||||
Style: tc.Style,
|
Style: tc.Style,
|
||||||
MaxDepth: tc.MaxDepth,
|
MaxDepth: tc.MaxDepth,
|
||||||
|
@ -540,7 +540,7 @@ func TestGetFullPath(t *testing.T) {
|
||||||
if len(tc.Template) == 0 {
|
if len(tc.Template) == 0 {
|
||||||
tc.Template = "{{ if gt .StackCount 0 }}{{ .StackCount }} {{ end }}{{ .Path }}"
|
tc.Template = "{{ if gt .StackCount 0 }}{{ .StackCount }} {{ end }}{{ .Path }}"
|
||||||
}
|
}
|
||||||
var props properties = map[Property]interface{}{
|
props := properties{
|
||||||
Style: tc.Style,
|
Style: tc.Style,
|
||||||
SegmentTemplate: tc.Template,
|
SegmentTemplate: tc.Template,
|
||||||
}
|
}
|
||||||
|
@ -588,7 +588,7 @@ func TestGetFullPathCustomMappedLocations(t *testing.T) {
|
||||||
env.On("getArgs", nil).Return(args)
|
env.On("getArgs", nil).Return(args)
|
||||||
path := &path{
|
path := &path{
|
||||||
env: env,
|
env: env,
|
||||||
props: map[Property]interface{}{
|
props: properties{
|
||||||
MappedLocationsEnabled: false,
|
MappedLocationsEnabled: false,
|
||||||
MappedLocations: tc.MappedLocations,
|
MappedLocations: tc.MappedLocations,
|
||||||
},
|
},
|
||||||
|
@ -639,7 +639,7 @@ func TestGetFolderPathCustomMappedLocations(t *testing.T) {
|
||||||
env.On("getArgs", nil).Return(args)
|
env.On("getArgs", nil).Return(args)
|
||||||
path := &path{
|
path := &path{
|
||||||
env: env,
|
env: env,
|
||||||
props: map[Property]interface{}{
|
props: properties{
|
||||||
MappedLocations: map[string]string{
|
MappedLocations: map[string]string{
|
||||||
"/a/b/c/d": "#",
|
"/a/b/c/d": "#",
|
||||||
},
|
},
|
||||||
|
@ -686,7 +686,7 @@ func TestAgnosterPath(t *testing.T) { // nolint:dupl
|
||||||
env.On("getArgs", nil).Return(args)
|
env.On("getArgs", nil).Return(args)
|
||||||
path := &path{
|
path := &path{
|
||||||
env: env,
|
env: env,
|
||||||
props: map[Property]interface{}{
|
props: properties{
|
||||||
FolderSeparatorIcon: " > ",
|
FolderSeparatorIcon: " > ",
|
||||||
FolderIcon: "f",
|
FolderIcon: "f",
|
||||||
HomeIcon: "~",
|
HomeIcon: "~",
|
||||||
|
@ -734,7 +734,7 @@ func TestAgnosterLeftPath(t *testing.T) { // nolint:dupl
|
||||||
env.On("getArgs", nil).Return(args)
|
env.On("getArgs", nil).Return(args)
|
||||||
path := &path{
|
path := &path{
|
||||||
env: env,
|
env: env,
|
||||||
props: map[Property]interface{}{
|
props: properties{
|
||||||
FolderSeparatorIcon: " > ",
|
FolderSeparatorIcon: " > ",
|
||||||
FolderIcon: "f",
|
FolderIcon: "f",
|
||||||
HomeIcon: "~",
|
HomeIcon: "~",
|
||||||
|
@ -782,7 +782,7 @@ func TestGetPwd(t *testing.T) {
|
||||||
env.On("getArgs", nil).Return(args)
|
env.On("getArgs", nil).Return(args)
|
||||||
path := &path{
|
path := &path{
|
||||||
env: env,
|
env: env,
|
||||||
props: map[Property]interface{}{
|
props: properties{
|
||||||
MappedLocationsEnabled: tc.MappedLocationsEnabled,
|
MappedLocationsEnabled: tc.MappedLocationsEnabled,
|
||||||
MappedLocations: map[string]string{
|
MappedLocations: map[string]string{
|
||||||
"/a/b/c/d": "#",
|
"/a/b/c/d": "#",
|
||||||
|
|
|
@ -8,7 +8,7 @@ func (n *php) string() string {
|
||||||
return n.language.string()
|
return n.language.string()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *php) init(props properties, env environmentInfo) {
|
func (n *php) init(props Properties, env environmentInfo) {
|
||||||
n.language = language{
|
n.language = language{
|
||||||
env: env,
|
env: env,
|
||||||
props: props,
|
props: props,
|
||||||
|
|
|
@ -34,7 +34,7 @@ type plastic struct {
|
||||||
plasticWorkspaceFolder string // root folder of workspace
|
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.props = props
|
||||||
p.env = env
|
p.env = env
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,8 @@ func TestPlasticEnabledNotFound(t *testing.T) {
|
||||||
env.On("isWsl", nil).Return(false)
|
env.On("isWsl", nil).Return(false)
|
||||||
p := &plastic{
|
p := &plastic{
|
||||||
scm: scm{
|
scm: scm{
|
||||||
env: env,
|
env: env,
|
||||||
|
props: properties{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.False(t, p.enabled())
|
assert.False(t, p.enabled())
|
||||||
|
@ -32,7 +33,8 @@ func TestPlasticEnabledInWorkspaceDirectory(t *testing.T) {
|
||||||
env.On("hasParentFilePath", ".plastic").Return(fileInfo, nil)
|
env.On("hasParentFilePath", ".plastic").Return(fileInfo, nil)
|
||||||
p := &plastic{
|
p := &plastic{
|
||||||
scm: scm{
|
scm: scm{
|
||||||
env: env,
|
env: env,
|
||||||
|
props: properties{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
assert.True(t, p.enabled())
|
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)
|
env.On("runCommand", "cm", []string{"status", "--head", "--machinereadable"}).Return(headStatus, nil)
|
||||||
p := &plastic{
|
p := &plastic{
|
||||||
scm: scm{
|
scm: scm{
|
||||||
env: env,
|
env: env,
|
||||||
|
props: properties{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return p
|
return p
|
||||||
|
@ -321,7 +324,7 @@ func TestPlasticTemplateString(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
var props properties = map[Property]interface{}{
|
props := properties{
|
||||||
FetchStatus: true,
|
FetchStatus: true,
|
||||||
}
|
}
|
||||||
tc.Plastic.props = props
|
tc.Plastic.props = props
|
||||||
|
|
|
@ -3,7 +3,7 @@ package main
|
||||||
import "strings"
|
import "strings"
|
||||||
|
|
||||||
type poshgit struct {
|
type poshgit struct {
|
||||||
props properties
|
props Properties
|
||||||
env environmentInfo
|
env environmentInfo
|
||||||
gitStatus string
|
gitStatus string
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ func (p *poshgit) string() string {
|
||||||
return p.gitStatus
|
return p.gitStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *poshgit) init(props properties, env environmentInfo) {
|
func (p *poshgit) init(props Properties, env environmentInfo) {
|
||||||
p.props = props
|
p.props = props
|
||||||
p.env = env
|
p.env = env
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ func (p *python) string() string {
|
||||||
return p.language.renderTemplate(segmentTemplate, p)
|
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{
|
p.language = language{
|
||||||
env: env,
|
env: env,
|
||||||
props: props,
|
props: props,
|
||||||
|
|
|
@ -52,7 +52,7 @@ func TestPythonTemplate(t *testing.T) {
|
||||||
env.On("getPathSeperator", nil).Return("")
|
env.On("getPathSeperator", nil).Return("")
|
||||||
env.On("getcwd", nil).Return("/usr/home/project")
|
env.On("getcwd", nil).Return("/usr/home/project")
|
||||||
env.On("homeDir", nil).Return("/usr/home")
|
env.On("homeDir", nil).Return("/usr/home")
|
||||||
var props properties = map[Property]interface{}{
|
props := properties{
|
||||||
FetchVersion: tc.FetchVersion,
|
FetchVersion: tc.FetchVersion,
|
||||||
SegmentTemplate: tc.Template,
|
SegmentTemplate: tc.Template,
|
||||||
DisplayMode: DisplayModeAlways,
|
DisplayMode: DisplayModeAlways,
|
||||||
|
@ -81,7 +81,7 @@ func TestPythonPythonInContext(t *testing.T) {
|
||||||
env.On("getenv", "CONDA_DEFAULT_ENV").Return("")
|
env.On("getenv", "CONDA_DEFAULT_ENV").Return("")
|
||||||
env.On("getenv", "PYENV_VERSION").Return("")
|
env.On("getenv", "PYENV_VERSION").Return("")
|
||||||
python := &python{}
|
python := &python{}
|
||||||
python.init(nil, env)
|
python.init(properties{}, env)
|
||||||
python.loadContext()
|
python.loadContext()
|
||||||
assert.Equal(t, tc.Expected, python.inContext())
|
assert.Equal(t, tc.Expected, python.inContext())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
type root struct {
|
type root struct {
|
||||||
props properties
|
props Properties
|
||||||
env environmentInfo
|
env environmentInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ func (rt *root) string() string {
|
||||||
return rt.props.getString(RootIcon, "\uF0E7")
|
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.props = props
|
||||||
rt.env = env
|
rt.env = env
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ func (r *ruby) string() string {
|
||||||
return version
|
return version
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *ruby) init(props properties, env environmentInfo) {
|
func (r *ruby) init(props Properties, env environmentInfo) {
|
||||||
r.language = language{
|
r.language = language{
|
||||||
env: env,
|
env: env,
|
||||||
props: props,
|
props: props,
|
||||||
|
|
|
@ -98,7 +98,7 @@ func TestRuby(t *testing.T) {
|
||||||
env.On("hasFiles", "Gemfile").Return(tc.HasGemFile)
|
env.On("hasFiles", "Gemfile").Return(tc.HasGemFile)
|
||||||
env.On("getcwd", nil).Return("/usr/home/project")
|
env.On("getcwd", nil).Return("/usr/home/project")
|
||||||
env.On("homeDir", nil).Return("/usr/home")
|
env.On("homeDir", nil).Return("/usr/home")
|
||||||
var props properties = map[Property]interface{}{
|
props := properties{
|
||||||
FetchVersion: tc.FetchVersion,
|
FetchVersion: tc.FetchVersion,
|
||||||
}
|
}
|
||||||
ruby := &ruby{}
|
ruby := &ruby{}
|
||||||
|
|
|
@ -8,7 +8,7 @@ func (r *rust) string() string {
|
||||||
return r.language.string()
|
return r.language.string()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *rust) init(props properties, env environmentInfo) {
|
func (r *rust) init(props Properties, env environmentInfo) {
|
||||||
r.language = language{
|
r.language = language{
|
||||||
env: env,
|
env: env,
|
||||||
props: props,
|
props: props,
|
||||||
|
|
|
@ -3,7 +3,7 @@ package main
|
||||||
import "strings"
|
import "strings"
|
||||||
|
|
||||||
type session struct {
|
type session struct {
|
||||||
props properties
|
props Properties
|
||||||
env environmentInfo
|
env environmentInfo
|
||||||
text string
|
text string
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ func (s *session) string() string {
|
||||||
return s.getFormattedText()
|
return s.getFormattedText()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *session) init(props properties, env environmentInfo) {
|
func (s *session) init(props Properties, env environmentInfo) {
|
||||||
s.props = props
|
s.props = props
|
||||||
s.env = env
|
s.env = env
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,7 +109,7 @@ func TestSessionSegmentTemplate(t *testing.T) {
|
||||||
env.On("getenv", defaultUserEnvVar).Return(tc.DefaultUserName)
|
env.On("getenv", defaultUserEnvVar).Return(tc.DefaultUserName)
|
||||||
session := &session{
|
session := &session{
|
||||||
env: env,
|
env: env,
|
||||||
props: map[Property]interface{}{
|
props: properties{
|
||||||
SegmentTemplate: tc.Template,
|
SegmentTemplate: tc.Template,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package main
|
||||||
import "strings"
|
import "strings"
|
||||||
|
|
||||||
type shell struct {
|
type shell struct {
|
||||||
props properties
|
props Properties
|
||||||
env environmentInfo
|
env environmentInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ func (s *shell) string() string {
|
||||||
return shellName
|
return shellName
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *shell) init(props properties, env environmentInfo) {
|
func (s *shell) init(props Properties, env environmentInfo) {
|
||||||
s.props = props
|
s.props = props
|
||||||
s.env = env
|
s.env = env
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,8 @@ func TestWriteCurrentShell(t *testing.T) {
|
||||||
env := new(MockedEnvironment)
|
env := new(MockedEnvironment)
|
||||||
env.On("getShellName", nil).Return(expected, nil)
|
env.On("getShellName", nil).Return(expected, nil)
|
||||||
s := &shell{
|
s := &shell{
|
||||||
env: env,
|
env: env,
|
||||||
|
props: properties{},
|
||||||
}
|
}
|
||||||
assert.Equal(t, expected, s.string())
|
assert.Equal(t, expected, s.string())
|
||||||
}
|
}
|
||||||
|
@ -30,7 +31,7 @@ func TestUseMappedShellNames(t *testing.T) {
|
||||||
env.On("getShellName", nil).Return(tc.Expected, nil)
|
env.On("getShellName", nil).Return(tc.Expected, nil)
|
||||||
s := &shell{
|
s := &shell{
|
||||||
env: env,
|
env: env,
|
||||||
props: map[Property]interface{}{
|
props: properties{
|
||||||
MappedShellNames: map[string]string{"pwsh": "PS"},
|
MappedShellNames: map[string]string{"pwsh": "PS"},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type spotify struct {
|
type spotify struct {
|
||||||
props properties
|
props Properties
|
||||||
env environmentInfo
|
env environmentInfo
|
||||||
status string
|
status string
|
||||||
artist 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)
|
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.props = props
|
||||||
s.env = env
|
s.env = env
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 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)
|
env.On("runCommand", "osascript", []string{"-e", "tell application \"Spotify\" to name of current track as string"}).Return(args.track, nil)
|
||||||
s := &spotify{
|
s := &spotify{
|
||||||
env: env,
|
env: env,
|
||||||
|
props: properties{},
|
||||||
}
|
}
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ func TestSpotifyStringPlayingSong(t *testing.T) {
|
||||||
artist: "Candlemass",
|
artist: "Candlemass",
|
||||||
track: "Spellbreaker",
|
track: "Spellbreaker",
|
||||||
status: "playing",
|
status: "playing",
|
||||||
|
props: properties{},
|
||||||
}
|
}
|
||||||
assert.Equal(t, expected, s.string())
|
assert.Equal(t, expected, s.string())
|
||||||
}
|
}
|
||||||
|
@ -22,6 +23,7 @@ func TestSpotifyStringPausedSong(t *testing.T) {
|
||||||
artist: "Candlemass",
|
artist: "Candlemass",
|
||||||
track: "Spellbreaker",
|
track: "Spellbreaker",
|
||||||
status: "paused",
|
status: "paused",
|
||||||
|
props: properties{},
|
||||||
}
|
}
|
||||||
assert.Equal(t, expected, s.string())
|
assert.Equal(t, expected, s.string())
|
||||||
}
|
}
|
||||||
|
@ -32,6 +34,7 @@ func TestSpotifyStringStoppedSong(t *testing.T) {
|
||||||
artist: "Candlemass",
|
artist: "Candlemass",
|
||||||
track: "Spellbreaker",
|
track: "Spellbreaker",
|
||||||
status: "stopped",
|
status: "stopped",
|
||||||
|
props: properties{},
|
||||||
}
|
}
|
||||||
assert.Equal(t, expected, s.string())
|
assert.Equal(t, expected, s.string())
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,8 @@ func bootStrapSpotifyWindowsTest(args *spotifyArgs) *spotify {
|
||||||
env := new(MockedEnvironment)
|
env := new(MockedEnvironment)
|
||||||
env.On("getWindowTitle", "spotify.exe").Return(args.title, args.runError)
|
env.On("getWindowTitle", "spotify.exe").Return(args.title, args.runError)
|
||||||
s := &spotify{
|
s := &spotify{
|
||||||
env: env,
|
env: env,
|
||||||
|
props: properties{},
|
||||||
}
|
}
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,8 @@ func TestSpotifyWsl(t *testing.T) {
|
||||||
env.On("isWsl", nil).Return(true)
|
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)
|
env.On("runCommand", "tasklist.exe", []string{"/V", "/FI", "Imagename eq Spotify.exe", "/FO", "CSV", "/NH"}).Return(tc.ExecOutput, nil)
|
||||||
s := &spotify{
|
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.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))
|
assert.Equal(t, tc.ExpectedString, s.string(), fmt.Sprintf("Failed in case: %s", tc.Case))
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type sysinfo struct {
|
type sysinfo struct {
|
||||||
props properties
|
props Properties
|
||||||
env environmentInfo
|
env environmentInfo
|
||||||
Precision int
|
Precision int
|
||||||
// mem
|
// mem
|
||||||
|
@ -53,7 +53,7 @@ func (s *sysinfo) string() string {
|
||||||
return text
|
return text
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *sysinfo) init(props properties, env environmentInfo) {
|
func (s *sysinfo) init(props Properties, env environmentInfo) {
|
||||||
s.props = props
|
s.props = props
|
||||||
s.env = env
|
s.env = env
|
||||||
s.Precision = s.props.getInt(Precision, 2)
|
s.Precision = s.props.getInt(Precision, 2)
|
||||||
|
|
|
@ -35,11 +35,11 @@ func TestSysInfo(t *testing.T) {
|
||||||
|
|
||||||
for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
tc.SysInfo.env = new(MockedEnvironment)
|
tc.SysInfo.env = new(MockedEnvironment)
|
||||||
tc.SysInfo.props = map[Property]interface{}{
|
tc.SysInfo.props = properties{
|
||||||
Precision: tc.Precision,
|
Precision: tc.Precision,
|
||||||
}
|
}
|
||||||
if tc.Template != "" {
|
if tc.Template != "" {
|
||||||
tc.SysInfo.props[SegmentTemplate] = tc.Template
|
tc.SysInfo.props.set(SegmentTemplate, tc.Template)
|
||||||
}
|
}
|
||||||
if tc.ExpectDisabled {
|
if tc.ExpectDisabled {
|
||||||
assert.Equal(t, false, tc.SysInfo.enabled(), tc.Case)
|
assert.Equal(t, false, tc.SysInfo.enabled(), tc.Case)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
type terraform struct {
|
type terraform struct {
|
||||||
props properties
|
props Properties
|
||||||
env environmentInfo
|
env environmentInfo
|
||||||
WorkspaceName string
|
WorkspaceName string
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ func (tf *terraform) string() string {
|
||||||
return text
|
return text
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tf *terraform) init(props properties, env environmentInfo) {
|
func (tf *terraform) init(props Properties, env environmentInfo) {
|
||||||
tf.props = props
|
tf.props = props
|
||||||
tf.env = env
|
tf.env = env
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,8 @@ func bootStrapTerraformTest(args *terraformArgs) *terraform {
|
||||||
env.On("getcwd", nil).Return("")
|
env.On("getcwd", nil).Return("")
|
||||||
env.On("runCommand", "terraform", []string{"workspace", "show"}).Return(args.workspaceName, nil)
|
env.On("runCommand", "terraform", []string{"workspace", "show"}).Return(args.workspaceName, nil)
|
||||||
k := &terraform{
|
k := &terraform{
|
||||||
env: env,
|
env: env,
|
||||||
|
props: properties{},
|
||||||
}
|
}
|
||||||
return k
|
return k
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,7 +84,7 @@ func TestShouldIncludeFolder(t *testing.T) {
|
||||||
env.On("homeDir", nil).Return("")
|
env.On("homeDir", nil).Return("")
|
||||||
env.On("getcwd", nil).Return(cwd)
|
env.On("getcwd", nil).Return(cwd)
|
||||||
segment := &Segment{
|
segment := &Segment{
|
||||||
Properties: map[Property]interface{}{
|
Properties: properties{
|
||||||
IncludeFolders: tc.IncludeFolders,
|
IncludeFolders: tc.IncludeFolders,
|
||||||
ExcludeFolders: tc.ExcludeFolders,
|
ExcludeFolders: tc.ExcludeFolders,
|
||||||
},
|
},
|
||||||
|
@ -101,7 +101,7 @@ func TestShouldIncludeFolderRegexInverted(t *testing.T) {
|
||||||
env.On("homeDir", nil).Return("")
|
env.On("homeDir", nil).Return("")
|
||||||
env.On("getcwd", nil).Return(cwd)
|
env.On("getcwd", nil).Return(cwd)
|
||||||
segment := &Segment{
|
segment := &Segment{
|
||||||
Properties: map[Property]interface{}{
|
Properties: properties{
|
||||||
ExcludeFolders: []string{"(?!Projects[\\/]).*"},
|
ExcludeFolders: []string{"(?!Projects[\\/]).*"},
|
||||||
},
|
},
|
||||||
env: env,
|
env: env,
|
||||||
|
@ -122,7 +122,7 @@ func TestShouldIncludeFolderRegexInvertedNonEscaped(t *testing.T) {
|
||||||
env.On("homeDir", nil).Return("")
|
env.On("homeDir", nil).Return("")
|
||||||
env.On("getcwd", nil).Return(cwd)
|
env.On("getcwd", nil).Return(cwd)
|
||||||
segment := &Segment{
|
segment := &Segment{
|
||||||
Properties: map[Property]interface{}{
|
Properties: properties{
|
||||||
ExcludeFolders: []string{"(?!Projects/).*"},
|
ExcludeFolders: []string{"(?!Projects/).*"},
|
||||||
},
|
},
|
||||||
env: env,
|
env: env,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
type text struct {
|
type text struct {
|
||||||
props properties
|
props Properties
|
||||||
env environmentInfo
|
env environmentInfo
|
||||||
content string
|
content string
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@ func (t *text) string() string {
|
||||||
return t.content
|
return t.content
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *text) init(props properties, env environmentInfo) {
|
func (t *text) init(props Properties, env environmentInfo) {
|
||||||
t.props = props
|
t.props = props
|
||||||
t.env = env
|
t.env = env
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ func TestTextSegment(t *testing.T) {
|
||||||
env.On("getHostName", nil).Return("MyHost", nil)
|
env.On("getHostName", nil).Return("MyHost", nil)
|
||||||
txt := &text{
|
txt := &text{
|
||||||
env: env,
|
env: env,
|
||||||
props: map[Property]interface{}{
|
props: properties{
|
||||||
TextProperty: tc.Text,
|
TextProperty: tc.Text,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package main
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
type tempus struct {
|
type tempus struct {
|
||||||
props properties
|
props Properties
|
||||||
env environmentInfo
|
env environmentInfo
|
||||||
templateText string
|
templateText string
|
||||||
CurrentDate time.Time
|
CurrentDate time.Time
|
||||||
|
@ -40,7 +40,7 @@ func (t *tempus) string() string {
|
||||||
return t.getFormattedText()
|
return t.getFormattedText()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *tempus) init(props properties, env environmentInfo) {
|
func (t *tempus) init(props Properties, env environmentInfo) {
|
||||||
t.props = props
|
t.props = props
|
||||||
t.env = env
|
t.env = env
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ func TestTimeSegmentTemplate(t *testing.T) {
|
||||||
env := new(MockedEnvironment)
|
env := new(MockedEnvironment)
|
||||||
tempus := &tempus{
|
tempus := &tempus{
|
||||||
env: env,
|
env: env,
|
||||||
props: map[Property]interface{}{
|
props: properties{
|
||||||
SegmentTemplate: tc.Template,
|
SegmentTemplate: tc.Template,
|
||||||
},
|
},
|
||||||
CurrentDate: currentDate,
|
CurrentDate: currentDate,
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type wakatime struct {
|
type wakatime struct {
|
||||||
props properties
|
props Properties
|
||||||
env environmentInfo
|
env environmentInfo
|
||||||
|
|
||||||
wtData
|
wtData
|
||||||
|
@ -73,7 +73,7 @@ func (w *wakatime) setAPIData() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *wakatime) init(props properties, env environmentInfo) {
|
func (w *wakatime) init(props Properties, env environmentInfo) {
|
||||||
w.props = props
|
w.props = props
|
||||||
w.env = env
|
w.env = env
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,7 @@ func TestWTTrackedTime(t *testing.T) {
|
||||||
env.On("cache", nil).Return(cache)
|
env.On("cache", nil).Return(cache)
|
||||||
|
|
||||||
w := &wakatime{
|
w := &wakatime{
|
||||||
props: map[Property]interface{}{
|
props: properties{
|
||||||
APIKey: "key",
|
APIKey: "key",
|
||||||
CacheTimeout: tc.CacheTimeout,
|
CacheTimeout: tc.CacheTimeout,
|
||||||
URL: FAKEAPIURL,
|
URL: FAKEAPIURL,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
type wifi struct {
|
type wifi struct {
|
||||||
props properties
|
props Properties
|
||||||
env environmentInfo
|
env environmentInfo
|
||||||
|
|
||||||
wifiInfo
|
wifiInfo
|
||||||
|
@ -44,7 +44,7 @@ func (w *wifi) string() string {
|
||||||
return text
|
return text
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *wifi) init(props properties, env environmentInfo) {
|
func (w *wifi) init(props Properties, env environmentInfo) {
|
||||||
w.props = props
|
w.props = props
|
||||||
w.env = env
|
w.env = env
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ func TestWiFiSegment(t *testing.T) {
|
||||||
|
|
||||||
w := &wifi{
|
w := &wifi{
|
||||||
env: env,
|
env: env,
|
||||||
props: map[Property]interface{}{
|
props: properties{
|
||||||
DisplayError: tc.DisplayError,
|
DisplayError: tc.DisplayError,
|
||||||
SegmentTemplate: "{{ if .Error }}{{ .Error }}{{ else }}{{ .SSID }}{{ end }}",
|
SegmentTemplate: "{{ if .Error }}{{ .Error }}{{ else }}{{ .SSID }}{{ end }}",
|
||||||
},
|
},
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type winreg struct {
|
type winreg struct {
|
||||||
props properties
|
props Properties
|
||||||
env environmentInfo
|
env environmentInfo
|
||||||
|
|
||||||
Value string
|
Value string
|
||||||
|
@ -19,7 +19,7 @@ const (
|
||||||
Fallback Property = "fallback"
|
Fallback Property = "fallback"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (wr *winreg) init(props properties, env environmentInfo) {
|
func (wr *winreg) init(props Properties, env environmentInfo) {
|
||||||
wr.props = props
|
wr.props = props
|
||||||
wr.env = env
|
wr.env = env
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,7 @@ func TestWinReg(t *testing.T) {
|
||||||
env.On("getWindowsRegistryKeyValue", tc.Path).Return(tc.getWRKVOutput, tc.Err)
|
env.On("getWindowsRegistryKeyValue", tc.Path).Return(tc.getWRKVOutput, tc.Err)
|
||||||
r := &winreg{
|
r := &winreg{
|
||||||
env: env,
|
env: env,
|
||||||
props: map[Property]interface{}{
|
props: properties{
|
||||||
RegistryPath: tc.Path,
|
RegistryPath: tc.Path,
|
||||||
Fallback: tc.Fallback,
|
Fallback: tc.Fallback,
|
||||||
},
|
},
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type ytm struct {
|
type ytm struct {
|
||||||
props properties
|
props Properties
|
||||||
env environmentInfo
|
env environmentInfo
|
||||||
status playStatus
|
status playStatus
|
||||||
artist string
|
artist string
|
||||||
|
@ -39,7 +39,7 @@ func (y *ytm) enabled() bool {
|
||||||
return err == nil
|
return err == nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (y *ytm) init(props properties, env environmentInfo) {
|
func (y *ytm) init(props Properties, env environmentInfo) {
|
||||||
y.props = props
|
y.props = props
|
||||||
y.env = env
|
y.env = env
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ func TestYTMStringPlayingSong(t *testing.T) {
|
||||||
artist: "Candlemass",
|
artist: "Candlemass",
|
||||||
track: "Spellbreaker",
|
track: "Spellbreaker",
|
||||||
status: playing,
|
status: playing,
|
||||||
|
props: properties{},
|
||||||
}
|
}
|
||||||
assert.Equal(t, expected, y.string())
|
assert.Equal(t, expected, y.string())
|
||||||
}
|
}
|
||||||
|
@ -23,6 +24,7 @@ func TestYTMStringPausedSong(t *testing.T) {
|
||||||
artist: "Candlemass",
|
artist: "Candlemass",
|
||||||
track: "Spellbreaker",
|
track: "Spellbreaker",
|
||||||
status: paused,
|
status: paused,
|
||||||
|
props: properties{},
|
||||||
}
|
}
|
||||||
assert.Equal(t, expected, y.string())
|
assert.Equal(t, expected, y.string())
|
||||||
}
|
}
|
||||||
|
@ -33,6 +35,7 @@ func TestYTMStringStoppedSong(t *testing.T) {
|
||||||
artist: "Candlemass",
|
artist: "Candlemass",
|
||||||
track: "Spellbreaker",
|
track: "Spellbreaker",
|
||||||
status: stopped,
|
status: stopped,
|
||||||
|
props: properties{},
|
||||||
}
|
}
|
||||||
assert.Equal(t, expected, y.string())
|
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)
|
env.On("doGet", url+"/query").Return([]byte(json), err)
|
||||||
ytm := &ytm{
|
ytm := &ytm{
|
||||||
env: env,
|
env: env,
|
||||||
props: map[Property]interface{}{
|
props: properties{
|
||||||
APIURL: url,
|
APIURL: url,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue