1
0
mirror of https://github.com/mrusme/neonmodem.git synced 2024-06-23 06:35:24 +00:00
neonmodem/ui/theme/theme.go

73 lines
2.1 KiB
Go
Raw Normal View History

2022-12-31 21:57:11 +00:00
package theme
import (
"github.com/charmbracelet/lipgloss"
"github.com/mrusme/gobbs/config"
)
type Theme struct {
DialogBox struct {
Window lipgloss.Style
Titlebar lipgloss.Style
Bottombar lipgloss.Style
}
PostsList struct {
2022-12-31 22:18:53 +00:00
List struct {
Focused lipgloss.Style
Blurred lipgloss.Style
}
Item struct {
Focused lipgloss.Style
Blurred lipgloss.Style
2022-12-31 23:32:04 +00:00
Selected lipgloss.Style
}
ItemDetail struct {
Focused lipgloss.Style
Blurred lipgloss.Style
Selected lipgloss.Style
2022-12-31 22:18:53 +00:00
}
2022-12-31 21:57:11 +00:00
}
Post struct {
Author lipgloss.Style
Subject lipgloss.Style
}
Reply struct {
Author lipgloss.Style
}
}
func New(cfg *config.Config) (*Theme) {
t := new(Theme)
2022-12-31 23:42:49 +00:00
t.PostsList.List.Focused = t.fromConfig(&cfg.Theme.PostsList.List.Focused)
t.PostsList.List.Blurred = t.fromConfig(&cfg.Theme.PostsList.List.Blurred)
t.PostsList.Item.Focused = t.fromConfig(&cfg.Theme.PostsList.Item.Focused)
t.PostsList.Item.Blurred = t.fromConfig(&cfg.Theme.PostsList.Item.Blurred)
t.PostsList.Item.Selected = t.fromConfig(&cfg.Theme.PostsList.Item.Selected)
t.PostsList.ItemDetail.Focused = t.fromConfig(&cfg.Theme.PostsList.ItemDetail.Focused)
t.PostsList.ItemDetail.Blurred = t.fromConfig(&cfg.Theme.PostsList.ItemDetail.Blurred)
t.PostsList.ItemDetail.Selected = t.fromConfig(&cfg.Theme.PostsList.ItemDetail.Selected)
t.DialogBox.Window = t.fromConfig(&cfg.Theme.DialogBox.Window)
t.DialogBox.Titlebar = t.fromConfig(&cfg.Theme.DialogBox.Titlebar)
t.DialogBox.Bottombar = t.fromConfig(&cfg.Theme.DialogBox.Bottombar)
t.Post.Author = t.fromConfig(&cfg.Theme.Post.Author)
t.Post.Subject = t.fromConfig(&cfg.Theme.Post.Subject)
t.Reply.Author = t.fromConfig(&cfg.Theme.Reply.Author)
2022-12-31 21:57:11 +00:00
return t
}
2022-12-31 23:42:49 +00:00
func (t *Theme) fromConfig(itemCfg *config.ThemeItemConfig) lipgloss.Style {
return lipgloss.NewStyle().
Margin(itemCfg.Margin...).
Padding(itemCfg.Padding...).
Border(itemCfg.Border.Border, itemCfg.Border.Sides...).
BorderForeground(itemCfg.Border.Foreground).
BorderBackground(itemCfg.Border.Background).
Foreground(itemCfg.Foreground).
Background(itemCfg.Background)
}