Skip to content

Commit

Permalink
Merge pull request #9 from isabelroses/configfile
Browse files Browse the repository at this point in the history
  • Loading branch information
isabelroses committed Apr 19, 2024
2 parents 399dd4b + 49598cb commit c8b6cea
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 11 deletions.
12 changes: 12 additions & 0 deletions example.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# this should follow the Go reference time format
# see <https://go.dev/src/time/format.go> for more information
dateformat = "02/01/2006"

# these values can be any format that lipgloss supports
# see <https://github.com/charmbracelet/lipgloss#colors>
[colors]
text = "#cdd6f4"
inverttext = "#1e1e2e"
subtext = "#a6adc8"
accent = "#74c7ec"
borders = "#313244"
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/charmbracelet/bubbletea v0.25.0
github.com/charmbracelet/lipgloss v0.10.0
github.com/mmcdole/gofeed v1.3.0
github.com/pelletier/go-toml/v2 v2.2.1
github.com/urfave/cli/v2 v2.27.1
)

Expand Down
12 changes: 10 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo
github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/pelletier/go-toml/v2 v2.2.1 h1:9TA9+T8+8CUCO2+WYnDLCgrYi9+omqKXyjDtosvtEhg=
github.com/pelletier/go-toml/v2 v2.2.1/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand All @@ -93,11 +95,17 @@ github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAm
github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=
github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/urfave/cli/v2 v2.27.1 h1:8xSQ6szndafKVRmfyeUMxkNUJQMjL1F2zmsZ+qHpfho=
github.com/urfave/cli/v2 v2.27.1/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ=
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 h1:+qGGcbkzsfDQNPPe9UDgpxAWQrhbbBXOYJFQDq/dtJw=
Expand Down
52 changes: 48 additions & 4 deletions lib/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,20 @@ import (
"strings"

"github.com/adrg/xdg"
"github.com/pelletier/go-toml/v2"
)

// ParseUrls reads the URLs from the config file and returns them as a slice
func ParseUrls() []string {
urlsFile, err := xdg.ConfigFile("izrss/urls")
func getConfigFile(file string) string {
configFile, err := xdg.ConfigFile("izrss/" + file)
if err != nil {
log.Fatalf("could not find config file: %v", err)
return nil
}
return configFile
}

// ParseUrls reads the URLs from the config file and returns them as a slice
func ParseUrls() []string {
urlsFile := getConfigFile("urls")

urlsRaw, err := os.ReadFile(urlsFile)
if err != nil {
Expand All @@ -39,3 +44,42 @@ func ParseUrls() []string {

return filteredUrls
}

// LoadConfig loads the users configuration file and applys it to the config struct
func LoadConfig() {
configFile := getConfigFile("config.toml")
configRaw, err := os.ReadFile(configFile)
if err != nil {
log.Fatalf("could not read file: %v", err)
}

if err := toml.Unmarshal(configRaw, &UserConfig); err != nil {
log.Fatalf("could not unmarshal config: %v", err)
}
}

// UserConfig is the global user configuration
var UserConfig = config{
DateFormat: "%d/%m/%Y",
Colors: colors{
Text: "#cdd6f4",
Inverttext: "#1e1e2e",
Subtext: "#a6adc8",
Accent: "#74c7ec",
Borders: "#313244",
},
}

// Config is the struct that holds the configuration
type config struct {
DateFormat string `toml:"dateformat"`
Colors colors `toml:"colors"`
}

type colors struct {
Text string `toml:"text"`
Inverttext string `toml:"inverttext"`
Subtext string `toml:"subtext"`
Accent string `toml:"accent"`
Borders string `toml:"borders"`
}
10 changes: 5 additions & 5 deletions lib/style.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ import (
var (
// MainStyle is the main style for the application
MainStyle = lipgloss.NewStyle().
Foreground(lipgloss.Color("#cdd6f4")).
Foreground(lipgloss.Color(UserConfig.Colors.Text)).
Border(lipgloss.RoundedBorder(), true).
BorderForeground(lipgloss.Color("#313244")).
BorderForeground(lipgloss.Color(UserConfig.Colors.Borders)).
Padding(0, 1).
Margin(0)

// ReaderStyle is the style for the reader
ReaderStyle = lipgloss.NewStyle()

// HelpStyle is the style for the help keybinds menu
HelpStyle = lipgloss.NewStyle().Foreground(lipgloss.Color("#a6adc8"))
HelpStyle = lipgloss.NewStyle().Foreground(lipgloss.Color(UserConfig.Colors.Subtext))
)

// TableStyle returns the style for the table
Expand All @@ -28,8 +28,8 @@ func TableStyle() table.Styles {
Bold(true).
Padding(0)
s.Selected = s.Selected.
Foreground(lipgloss.Color("#1e1e2e")).
Background(lipgloss.Color("#74c7ec")).
Foreground(lipgloss.Color(UserConfig.Colors.Inverttext)).
Background(lipgloss.Color(UserConfig.Colors.Accent)).
Bold(false)
s.Cell.Padding(0)

Expand Down

0 comments on commit c8b6cea

Please sign in to comment.