Factorize code to init sementic colors

master
joce 3 years ago
parent 9560670e98
commit b45fbfe908
  1. 24
      profile.go

@ -82,20 +82,9 @@ func NewProfile(filename string) *Profile {
} else { } else {
json.Unmarshal(data, profile) json.Unmarshal(data, profile)
profile.Colors.Gain = strings.ToLower(profile.Colors.Gain) InitColor(profile.Colors.Gain, defaultGainColor)
if !IsSupportedColor(profile.Colors.Gain) { InitColor(profile.Colors.Loss, defaultLossColor)
profile.Colors.Gain = defaultGainColor InitColor(profile.Colors.Tag, defaultTagColor)
}
profile.Colors.Loss = strings.ToLower(profile.Colors.Loss)
if !IsSupportedColor(profile.Colors.Loss) {
profile.Colors.Loss = defaultLossColor
}
profile.Colors.Tag = strings.ToLower(profile.Colors.Tag)
if !IsSupportedColor(profile.Colors.Tag) {
profile.Colors.Tag = defaultTagColor
}
profile.SetFilter(profile.Filter) profile.SetFilter(profile.Filter)
} }
@ -104,6 +93,13 @@ func NewProfile(filename string) *Profile {
return profile return profile
} }
func InitColor(color string, defaultValue string) {
color = strings.ToLower(color)
if !IsSupportedColor(color) {
color = defaultValue;
}
}
// Save serializes settings using JSON and saves them in ~/.moprc file. // Save serializes settings using JSON and saves them in ~/.moprc file.
func (profile *Profile) Save() error { func (profile *Profile) Save() error {
data, err := json.MarshalIndent(profile, "", " ") data, err := json.MarshalIndent(profile, "", " ")

Loading…
Cancel
Save