Skip to content

Commit

Permalink
Allow for basic theming of the ui
Browse files Browse the repository at this point in the history
  • Loading branch information
zMoooooritz committed Nov 6, 2023
1 parent 72ea52f commit f0ef602
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 27 deletions.
29 changes: 20 additions & 9 deletions example_config.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@

# Configuration on how to open specific resources
# Configuration of how to open specific resources
# Via the args it is possible to provide flags to the application
# the arg $ will be replaced by the url of the resource
#
Application:
Image:
path: sxiv
args:
Path: sxiv
Args:
- $
Audio:
path: mpv
args:
Path: mpv
Args:
- $
Video:
path: mpv
args:
Path: mpv
Args:
- $
HTML:
path: qutebrowser
args:
Path: qutebrowser
Args:
- $

# Configuration of the theming
# Currently only the configuration of colors is implemented
Theme:
PrimaryColor: "62"
SecondaryColor: "230"
NormalTitleColor: "#DDDDDD"
NormalDescColor: "#777777"
SelectedPrimaryColor: "#AD58B4"
SelectedSecondaryColor: "#EE6FF8"
BreakingColor: "#FF0000"

17 changes: 14 additions & 3 deletions models.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,18 @@ type VideoURLs struct {
}

type Configuration struct {
AppConfig ApplicationsConfig `yaml:"Application"`
AppConfig ApplicationsConfig `yaml:"Application,omitempty"`
ThemeConfig ThemeConfig `yaml:"Theme,omitempty"`
}

type ThemeConfig struct {
PrimaryColor string `yaml:"PrimaryColor"`
SecondaryColor string `yaml:"SecondaryColor"`
NormalTitleColor string `yaml:"NormaleTitleColor"`
NormalDescColor string `yaml:"NormalDescColor"`
SelectedPrimaryColor string `yaml:"SelectedPrimaryColor"`
SelectedSecondaryColor string `yaml:"SelectedSecondaryColor"`
BreakingColor string `yaml:"BreakingColor"`
}

type ApplicationsConfig struct {
Expand All @@ -62,8 +73,8 @@ type ApplicationsConfig struct {
}

type ApplicationConfig struct {
Path string `yaml:"path"`
Args []string `yaml:"args"`
Path string `yaml:"Path"`
Args []string `yaml:"Args"`
}

type ResourceType int
Expand Down
4 changes: 2 additions & 2 deletions newslist.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ type NewsDelegate struct {
spacing int
}

func NewNewsDelegate() NewsDelegate {
func NewNewsDelegate(s Style) NewsDelegate {
return NewsDelegate{
Styles: DefaultNewsStyle(),
Styles: s,
height: 2,
spacing: 1,
}
Expand Down
28 changes: 20 additions & 8 deletions style.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,26 @@ type Style struct {
ItemBreakingDesc lipgloss.Style
}

func DefaultNewsStyle() (s Style) {
primaryColor := lipgloss.Color("62")
secondaryColor := lipgloss.Color("230")
normalTitleColor := lipgloss.Color("#DDDDDD")
normalDescColor := lipgloss.Color("#777777")
selectedPrimaryColor := lipgloss.Color("#AD58B4")
selectedSecondaryColor := lipgloss.Color("#EE6FF8")
breakingColor := lipgloss.Color("#FF0000")
func DefaultThemeConfiguration() ThemeConfig {
return ThemeConfig{
PrimaryColor: "62",
SecondaryColor: "230",
NormalTitleColor: "#DDDDDD",
NormalDescColor: "#777777",
SelectedPrimaryColor: "#AD58B4",
SelectedSecondaryColor: "#EE6FF8",
BreakingColor: "#FF0000",
}
}

func NewsStyle(t ThemeConfig) (s Style) {
primaryColor := lipgloss.Color(t.PrimaryColor)
secondaryColor := lipgloss.Color(t.SecondaryColor)
normalTitleColor := lipgloss.Color(t.NormalTitleColor)
normalDescColor := lipgloss.Color(t.NormalDescColor)
selectedPrimaryColor := lipgloss.Color(t.SelectedPrimaryColor)
selectedSecondaryColor := lipgloss.Color(t.SelectedSecondaryColor)
breakingColor := lipgloss.Color(t.BreakingColor)

s.ActiveStyle = lipgloss.NewStyle().Foreground(primaryColor).BorderForeground(primaryColor)
s.TitleActiveStyle = lipgloss.NewStyle().Background(primaryColor).Foreground(secondaryColor)
Expand Down
18 changes: 13 additions & 5 deletions tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,10 @@ func (m *Model) InitLists(news [][]NewsEntry) {
}
}

func EmptyLists(count int) []list.Model {
func EmptyLists(s Style, count int) []list.Model {
var lists []list.Model
for i := 0; i < count; i++ {
newList := list.New([]list.Item{}, NewNewsDelegate(), 0, 0)
newList := list.New([]list.Item{}, NewNewsDelegate(s), 0, 0)
newList.SetFilteringEnabled(false)
newList.SetShowTitle(true)
newList.SetShowStatusBar(false)
Expand All @@ -131,6 +131,14 @@ func NewHelper(s Style) help.Model {
}

func InitialModel(c Configuration) Model {
tc := ThemeConfig{}
var style Style
if c.ThemeConfig != tc {
style = NewsStyle(c.ThemeConfig)
} else {
style = NewsStyle(DefaultThemeConfiguration())
}

m := Model{
configuration: c,
keymap: keymap{
Expand Down Expand Up @@ -187,14 +195,14 @@ func InitialModel(c Configuration) Model {
key.WithHelp("?", "help"),
),
},
style: DefaultNewsStyle(),
style: style,
ready: false,
help: NewHelper(DefaultNewsStyle()),
help: NewHelper(style),
helpMode: 1,
reader: viewport.New(0, 0),
spinner: NewDotSpinner(),
focus: 0,
lists: EmptyLists(2),
lists: EmptyLists(style, 2),
listsActiveIndeces: []int{},
activeListIndex: 0,
width: 0,
Expand Down

0 comments on commit f0ef602

Please sign in to comment.