From 701cd499dfea23b372f137edda8f4e1e827e2704 Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Tue, 6 Aug 2024 13:56:56 +0200 Subject: [PATCH] refactor: remove if/else statements --- src/segments/umbraco.go | 5 ++--- src/template/text.go | 11 +++++++---- src/terminal/writer.go | 8 +++++--- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/segments/umbraco.go b/src/segments/umbraco.go index e36e86b0..78e30a95 100644 --- a/src/segments/umbraco.go +++ b/src/segments/umbraco.go @@ -153,11 +153,10 @@ func (u *Umbraco) TryFindLegacyUmbraco(configPath string) bool { for _, appSetting := range webConfigAppSettings.AppSettings { if strings.EqualFold(appSetting.Key, "umbraco.core.configurationstatus") || strings.EqualFold(appSetting.Key, "umbracoConfigurationStatus") { u.Modern = false + u.Version = appSetting.Value - if len(appSetting.Value) == 0 { + if len(u.Version) == 0 { u.Version = UNKNOWN - } else { - u.Version = appSetting.Value } return true diff --git a/src/template/text.go b/src/template/text.go index 408ef00a..ca8b4bf3 100644 --- a/src/template/text.go +++ b/src/template/text.go @@ -222,16 +222,18 @@ func (t *Text) cleanTemplate() { result += string(char) continue } - // end of a variable, needs to be appended - if !isKnownVariable(property) { //nolint: gocritic + + switch { + case !isKnownVariable(property): + // end of a variable, needs to be appended result += ".Data" + property - } else if strings.HasPrefix(property, ".Segments") && !strings.HasSuffix(property, ".Contains") { + case strings.HasPrefix(property, ".Segments") && !strings.HasSuffix(property, ".Contains"): // as we can't provide a clean way to access the list // of segments, we need to replace the property with // the list of segments so they can be accessed directly property = strings.Replace(property, ".Segments", ".Segments.ToSimple", 1) result += property - } else { + default: // check if we have the same property in Data // and replace it with the Data property so it // can take precedence @@ -242,6 +244,7 @@ func (t *Text) cleanTemplate() { property = strings.TrimPrefix(property, globalRef) result += property } + property = "" result += string(char) inProperty = false diff --git a/src/terminal/writer.go b/src/terminal/writer.go index 01ce8e09..ad4a5217 100644 --- a/src/terminal/writer.go +++ b/src/terminal/writer.go @@ -428,17 +428,19 @@ func writeSegmentColors() { return } - if fg.IsTransparent() && len(BackgroundColor) != 0 { //nolint: gocritic + switch { + case fg.IsTransparent() && len(BackgroundColor) != 0: background := getAnsiFromColorString(BackgroundColor, false) writeEscapedAnsiString(fmt.Sprintf(colorise, background)) writeEscapedAnsiString(fmt.Sprintf(colorise, bg.ToForeground())) - } else if fg.IsTransparent() && !bg.IsEmpty() { + case fg.IsTransparent() && !bg.IsEmpty(): isTransparent = true writeEscapedAnsiString(fmt.Sprintf(transparentStart, bg)) - } else { + default: if !bg.IsEmpty() && !bg.IsTransparent() { writeEscapedAnsiString(fmt.Sprintf(colorise, bg)) } + if !fg.IsEmpty() { writeEscapedAnsiString(fmt.Sprintf(colorise, fg)) }