1
0
mirror of https://github.com/mrusme/neonmodem.git synced 2024-11-03 04:27:16 -05:00

Optimized Theme engine

This commit is contained in:
マリウス 2022-12-31 18:42:49 -05:00
parent c1a6b9273e
commit 1ceebe29d1
No known key found for this signature in database
GPG Key ID: 272ED814BF63261F

View File

@ -42,131 +42,31 @@ type Theme struct {
func New(cfg *config.Config) (*Theme) {
t := new(Theme)
t.PostsList.List.Focused = lipgloss.NewStyle().
Margin(cfg.Theme.PostsList.List.Focused.Margin...).
Padding(cfg.Theme.PostsList.List.Focused.Padding...).
Border(cfg.Theme.PostsList.List.Focused.Border.Border, cfg.Theme.PostsList.List.Focused.Border.Sides...).
BorderForeground(cfg.Theme.PostsList.List.Focused.Border.Foreground).
BorderBackground(cfg.Theme.PostsList.List.Focused.Border.Background).
Foreground(cfg.Theme.PostsList.List.Focused.Foreground).
Background(cfg.Theme.PostsList.List.Focused.Background)
t.PostsList.List.Blurred = lipgloss.NewStyle().
Margin(cfg.Theme.PostsList.List.Blurred.Margin...).
Padding(cfg.Theme.PostsList.List.Blurred.Padding...).
Border(cfg.Theme.PostsList.List.Blurred.Border.Border, cfg.Theme.PostsList.List.Blurred.Border.Sides...).
BorderForeground(cfg.Theme.PostsList.List.Blurred.Border.Foreground).
BorderBackground(cfg.Theme.PostsList.List.Blurred.Border.Background).
Foreground(cfg.Theme.PostsList.List.Blurred.Foreground).
Background(cfg.Theme.PostsList.List.Blurred.Background)
t.PostsList.Item.Focused = lipgloss.NewStyle().
Margin(cfg.Theme.PostsList.Item.Focused.Margin...).
Padding(cfg.Theme.PostsList.Item.Focused.Padding...).
Border(cfg.Theme.PostsList.Item.Focused.Border.Border, cfg.Theme.PostsList.Item.Focused.Border.Sides...).
BorderForeground(cfg.Theme.PostsList.Item.Focused.Border.Foreground).
BorderBackground(cfg.Theme.PostsList.Item.Focused.Border.Background).
Foreground(cfg.Theme.PostsList.Item.Focused.Foreground).
Background(cfg.Theme.PostsList.Item.Focused.Background)
t.PostsList.Item.Blurred = lipgloss.NewStyle().
Margin(cfg.Theme.PostsList.Item.Blurred.Margin...).
Padding(cfg.Theme.PostsList.Item.Blurred.Padding...).
Border(cfg.Theme.PostsList.Item.Blurred.Border.Border, cfg.Theme.PostsList.Item.Blurred.Border.Sides...).
BorderForeground(cfg.Theme.PostsList.Item.Blurred.Border.Foreground).
BorderBackground(cfg.Theme.PostsList.Item.Blurred.Border.Background).
Foreground(cfg.Theme.PostsList.Item.Blurred.Foreground).
Background(cfg.Theme.PostsList.Item.Blurred.Background)
t.PostsList.Item.Selected = lipgloss.NewStyle().
Margin(cfg.Theme.PostsList.Item.Selected.Margin...).
Padding(cfg.Theme.PostsList.Item.Selected.Padding...).
Border(cfg.Theme.PostsList.Item.Selected.Border.Border, cfg.Theme.PostsList.Item.Selected.Border.Sides...).
BorderForeground(cfg.Theme.PostsList.Item.Selected.Border.Foreground).
BorderBackground(cfg.Theme.PostsList.Item.Selected.Border.Background).
Foreground(cfg.Theme.PostsList.Item.Selected.Foreground).
Background(cfg.Theme.PostsList.Item.Selected.Background)
t.PostsList.ItemDetail.Focused = lipgloss.NewStyle().
Margin(cfg.Theme.PostsList.ItemDetail.Focused.Margin...).
Padding(cfg.Theme.PostsList.ItemDetail.Focused.Padding...).
Border(cfg.Theme.PostsList.ItemDetail.Focused.Border.Border, cfg.Theme.PostsList.ItemDetail.Focused.Border.Sides...).
BorderForeground(cfg.Theme.PostsList.ItemDetail.Focused.Border.Foreground).
BorderBackground(cfg.Theme.PostsList.ItemDetail.Focused.Border.Background).
Foreground(cfg.Theme.PostsList.ItemDetail.Focused.Foreground).
Background(cfg.Theme.PostsList.ItemDetail.Focused.Background)
t.PostsList.ItemDetail.Blurred = lipgloss.NewStyle().
Margin(cfg.Theme.PostsList.ItemDetail.Blurred.Margin...).
Padding(cfg.Theme.PostsList.ItemDetail.Blurred.Padding...).
Border(cfg.Theme.PostsList.ItemDetail.Blurred.Border.Border, cfg.Theme.PostsList.ItemDetail.Blurred.Border.Sides...).
BorderForeground(cfg.Theme.PostsList.ItemDetail.Blurred.Border.Foreground).
BorderBackground(cfg.Theme.PostsList.ItemDetail.Blurred.Border.Background).
Foreground(cfg.Theme.PostsList.ItemDetail.Blurred.Foreground).
Background(cfg.Theme.PostsList.ItemDetail.Blurred.Background)
t.PostsList.ItemDetail.Selected = lipgloss.NewStyle().
Margin(cfg.Theme.PostsList.ItemDetail.Selected.Margin...).
Padding(cfg.Theme.PostsList.ItemDetail.Selected.Padding...).
Border(cfg.Theme.PostsList.ItemDetail.Selected.Border.Border, cfg.Theme.PostsList.ItemDetail.Selected.Border.Sides...).
BorderForeground(cfg.Theme.PostsList.ItemDetail.Selected.Border.Foreground).
BorderBackground(cfg.Theme.PostsList.ItemDetail.Selected.Border.Background).
Foreground(cfg.Theme.PostsList.ItemDetail.Selected.Foreground).
Background(cfg.Theme.PostsList.ItemDetail.Selected.Background)
t.DialogBox.Window = lipgloss.NewStyle().
Margin(cfg.Theme.DialogBox.Window.Margin...).
Padding(cfg.Theme.DialogBox.Window.Padding...).
Border(cfg.Theme.DialogBox.Window.Border.Border, cfg.Theme.DialogBox.Window.Border.Sides...).
BorderForeground(cfg.Theme.DialogBox.Window.Border.Foreground).
BorderBackground(cfg.Theme.DialogBox.Window.Border.Background).
Foreground(cfg.Theme.DialogBox.Window.Foreground).
Background(cfg.Theme.DialogBox.Window.Background)
t.DialogBox.Titlebar = lipgloss.NewStyle().
Margin(cfg.Theme.DialogBox.Titlebar.Margin...).
Padding(cfg.Theme.DialogBox.Titlebar.Padding...).
Border(cfg.Theme.DialogBox.Titlebar.Border.Border, cfg.Theme.DialogBox.Titlebar.Border.Sides...).
BorderForeground(cfg.Theme.DialogBox.Titlebar.Border.Foreground).
BorderBackground(cfg.Theme.DialogBox.Titlebar.Border.Background).
Foreground(cfg.Theme.DialogBox.Titlebar.Foreground).
Background(cfg.Theme.DialogBox.Titlebar.Background)
t.DialogBox.Bottombar = lipgloss.NewStyle().
Margin(cfg.Theme.DialogBox.Bottombar.Margin...).
Padding(cfg.Theme.DialogBox.Bottombar.Padding...).
Border(cfg.Theme.DialogBox.Bottombar.Border.Border, cfg.Theme.DialogBox.Bottombar.Border.Sides...).
BorderForeground(cfg.Theme.DialogBox.Bottombar.Border.Foreground).
BorderBackground(cfg.Theme.DialogBox.Bottombar.Border.Background).
Foreground(cfg.Theme.DialogBox.Bottombar.Foreground).
Background(cfg.Theme.DialogBox.Bottombar.Background)
t.Post.Author = lipgloss.NewStyle().
Margin(cfg.Theme.Post.Author.Margin...).
Padding(cfg.Theme.Post.Author.Padding...).
Border(cfg.Theme.Post.Author.Border.Border, cfg.Theme.Post.Author.Border.Sides...).
BorderForeground(cfg.Theme.Post.Author.Border.Foreground).
BorderBackground(cfg.Theme.Post.Author.Border.Background).
Foreground(cfg.Theme.Post.Author.Foreground).
Background(cfg.Theme.Post.Author.Background)
t.Post.Subject = lipgloss.NewStyle().
Margin(cfg.Theme.Post.Subject.Margin...).
Padding(cfg.Theme.Post.Subject.Padding...).
Border(cfg.Theme.Post.Subject.Border.Border, cfg.Theme.Post.Subject.Border.Sides...).
BorderForeground(cfg.Theme.Post.Subject.Border.Foreground).
BorderBackground(cfg.Theme.Post.Subject.Border.Background).
Foreground(cfg.Theme.Post.Subject.Foreground).
Background(cfg.Theme.Post.Subject.Background)
t.Reply.Author = lipgloss.NewStyle().
Margin(cfg.Theme.Reply.Author.Margin...).
Padding(cfg.Theme.Reply.Author.Padding...).
Border(cfg.Theme.Reply.Author.Border.Border, cfg.Theme.Reply.Author.Border.Sides...).
BorderForeground(cfg.Theme.Reply.Author.Border.Foreground).
BorderBackground(cfg.Theme.Reply.Author.Border.Background).
Foreground(cfg.Theme.Reply.Author.Foreground).
Background(cfg.Theme.Reply.Author.Background)
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)
return t
}
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)
}