Skip to content

Commit

Permalink
fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
askovpen committed Sep 6, 2024
1 parent 637b6ed commit abdce1e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
7 changes: 4 additions & 3 deletions pkg/config/city.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ import (
"gopkg.in/yaml.v3"
)

func readCity() {
func readCity() error {
yamlFile, err := os.ReadFile(Config.CityPath)
if err != nil {
panic(err)
return err
}
err = yaml.Unmarshal(yamlFile, &city)
if err != nil {
panic(err)
return err
}
return nil
}

// GetCity return city
Expand Down
16 changes: 8 additions & 8 deletions pkg/config/colorscheme.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,13 @@ func StringToStyle(str string) (tcell.Style, error) {

if fg != "" && fg != "default" {
if _, ok := tcell.ColorNames[fg]; !ok {
errStack = errors.Join(errStack, errors.New(fmt.Sprintf("unknown foreground color name \"%s\"", fg)))
errStack = errors.Join(errStack, fmt.Errorf("unknown foreground color name \"%s\"", fg))
}
fgColor = StringToColor(fg)
}
if bg != "" && bg != "default" {
if _, ok := tcell.ColorNames[bg]; !ok {
errStack = errors.Join(errStack, errors.New(fmt.Sprintf("unknown background color name \"%s\"", bg)))
errStack = errors.Join(errStack, fmt.Errorf("unknown background color name \"%s\"", bg))
}
bgColor = StringToColor(bg)
}
Expand All @@ -242,7 +242,7 @@ func StringToStyle(str string) (tcell.Style, error) {
} else if v == StyleBold {
style = style.Bold(true)
} else if v != "" {
errStack = errors.Join(errStack, errors.New(fmt.Sprintf("unknown style \"%s\"", v)))
errStack = errors.Join(errStack, fmt.Errorf("unknown style \"%s\"", v))
}
}
return style, errStack
Expand Down Expand Up @@ -320,19 +320,19 @@ func readColors() error {
if Config.Colorscheme != "" {
yamlColors, err := os.ReadFile(Config.Colorscheme)
if err != nil {
return errors.New(fmt.Sprintf("cannot read color scheme file: %s", Config.Colorscheme))
return fmt.Errorf("cannot read color scheme file: %s", Config.Colorscheme)
}
colorsBackup := Config.Colors
err = yaml.Unmarshal(yamlColors, &Config.Colors)
if err != nil {
log.Println(fmt.Sprintf("errors during read of color scheme file: %s", Config.Colorscheme))
log.Println(fmt.Sprintf("yaml unmarshal errors: %v", err))
log.Printf("errors during read of color scheme file: %s", Config.Colorscheme)
log.Printf("yaml unmarshal errors: %v", err)
Config.Colors = colorsBackup
} else {
log.Println(fmt.Sprintf("color scheme read successfully from file: %s", Config.Colorscheme))
log.Printf("color scheme read successfully from file: %s", Config.Colorscheme)
}
}
StyleDefault = GetElementStyle(ColorAreaDefault, ColorElementText)
StyleDefault.Attributes(tcell.AttrNone)
// ??? StyleDefault.Attributes(tcell.AttrNone)

This comment has been minimized.

Copy link
@lamskoy

lamskoy Sep 6, 2024

Contributor

Have initial thought to disallow default style to be Bold/Reverse/Underline etc.
Only background and foreground colors
Should we allow it?

This comment has been minimized.

Copy link
@askovpen

askovpen Sep 6, 2024

Author Owner
func (s Style) Attributes(attrs AttrMask) Style {
	return Style{
		fg:    s.fg,
		bg:    s.bg,
		attrs: attrs,
		url:   s.url,
		urlId: s.urlId,
	}
}

this function not set anything

This comment has been minimized.

Copy link
@askovpen

askovpen Sep 6, 2024

Author Owner

maybe StyleDefault = StyleDefault.Attributes(tcell.AttrNone)?

This comment has been minimized.

Copy link
@lamskoy

lamskoy Sep 6, 2024

Contributor

Yeah, correct. Forgot it's immutable

This comment has been minimized.

Copy link
@askovpen

askovpen Sep 6, 2024

Author Owner

I'll fix

return nil
}
5 changes: 4 additions & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ func Read(fn string) error {
return errors.New("Config.CityPath not defined")
}
Config.CityPath = tryPath(rootPath, Config.CityPath)
readCity()
err = readCity()
if err != nil {
return err
}
return nil
}

Expand Down

0 comments on commit abdce1e

Please sign in to comment.