gomu/colors.go

119 lines
2.7 KiB
Go
Raw Normal View History

2020-08-22 14:41:03 +08:00
package main
import (
2021-03-15 13:26:51 +08:00
"fmt"
2021-03-15 22:34:59 +08:00
"strings"
2021-03-15 13:26:51 +08:00
2021-01-21 01:30:16 +08:00
"github.com/gdamore/tcell/v2"
2021-03-15 13:26:51 +08:00
"github.com/rivo/tview"
2020-08-22 14:41:03 +08:00
)
2021-03-25 12:01:12 +08:00
// Colors are the configurable colors used in gomu
2020-08-22 14:41:03 +08:00
type Colors struct {
accent tcell.Color
background tcell.Color
2021-03-16 11:47:35 +08:00
foreground tcell.Color
2020-08-22 14:41:03 +08:00
// title refers to now_playing_title in config file
2021-03-16 11:47:35 +08:00
title tcell.Color
popup tcell.Color
playlistHi tcell.Color
playlistDir tcell.Color
queueHi tcell.Color
subtitle string
2020-08-22 14:41:03 +08:00
}
2021-03-15 22:34:59 +08:00
func init() {
tcell.ColorNames["none"] = tcell.ColorDefault
}
2020-08-22 14:41:03 +08:00
func newColor() *Colors {
defaultColors := map[string]string{
2021-03-16 11:47:35 +08:00
"Color.accent": "darkcyan",
"Color.background": "none",
"Color.foreground": "white",
"Color.popup": "black",
"Color.playlist_directory": "darkcyan",
"Color.playlist_highlight": "darkcyan",
"Color.queue_highlight": "darkcyan",
"Color.now_playing_title": "darkgreen",
"Color.subtitle": "darkgoldenrod",
2020-08-22 14:41:03 +08:00
}
2021-02-14 13:45:43 +08:00
anko := gomu.anko
2021-03-15 22:34:59 +08:00
// checks for invalid color and set default fallback
2020-08-22 14:41:03 +08:00
for k, v := range defaultColors {
// color from the config file
2021-02-14 14:35:36 +08:00
cfgColor := anko.GetString(k)
2020-08-22 14:41:03 +08:00
2021-03-15 22:34:59 +08:00
if _, ok := tcell.ColorNames[cfgColor]; !ok {
// use default value if invalid hex color was given
anko.Set(k, v)
}
2020-08-22 14:41:03 +08:00
}
2021-02-18 10:23:15 +08:00
accent := anko.GetString("Color.accent")
2021-03-15 22:34:59 +08:00
background := anko.GetString("Color.background")
2021-03-16 11:47:35 +08:00
foreground := anko.GetString("Color.foreground")
2021-02-18 10:23:15 +08:00
popup := anko.GetString("Color.popup")
2021-03-16 11:47:35 +08:00
playlistDir := anko.GetString("Color.playlist_directory")
playlistHi := anko.GetString("Color.playlist_highlight")
queueHi := anko.GetString("Color.queue_highlight")
2021-02-18 10:23:15 +08:00
title := anko.GetString("Color.now_playing_title")
2021-03-16 11:47:35 +08:00
subtitle := anko.GetString("Color.subtitle")
2020-08-22 14:41:03 +08:00
color := &Colors{
2021-03-16 11:47:35 +08:00
accent: tcell.ColorNames[accent],
foreground: tcell.ColorNames[foreground],
background: tcell.ColorNames[background],
popup: tcell.ColorNames[popup],
playlistDir: tcell.ColorNames[playlistDir],
playlistHi: tcell.ColorNames[playlistHi],
queueHi: tcell.ColorNames[queueHi],
title: tcell.ColorNames[title],
subtitle: subtitle,
2020-08-22 14:41:03 +08:00
}
return color
}
2021-03-15 13:26:51 +08:00
func colorsPopup() tview.Primitive {
textView := tview.NewTextView().
SetWrap(true).
SetDynamicColors(true).
SetWrap(true).
SetWordWrap(true)
textView.
SetBorder(true).
SetTitle(" Colors ").
SetBorderPadding(1, 1, 2, 2)
2021-03-15 22:34:59 +08:00
i := 0
colorPad := strings.Repeat(" ", 5)
for name := range tcell.ColorNames {
fmt.Fprintf(textView, "%20s [:%s]%s[:-] ", name, name, colorPad)
2021-03-15 13:26:51 +08:00
2021-03-15 22:34:59 +08:00
if i == 2 {
2021-03-16 11:47:35 +08:00
fmt.Fprint(textView, "\n")
2021-03-15 22:34:59 +08:00
i = 0
continue
}
i++
2021-03-15 13:26:51 +08:00
}
textView.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
switch event.Key() {
case tcell.KeyEsc:
gomu.pages.RemovePage("show-color-popup")
gomu.popups.pop()
}
return event
})
return textView
}