-
Notifications
You must be signed in to change notification settings - Fork 15
/
colors.go
118 lines (98 loc) · 2.74 KB
/
colors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package main
import (
"fmt"
"strings"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)
// Colors are the configurable colors used in gomu
type Colors struct {
accent tcell.Color
background tcell.Color
foreground tcell.Color
// title refers to now_playing_title in config file
title tcell.Color
popup tcell.Color
playlistHi tcell.Color
playlistDir tcell.Color
queueHi tcell.Color
subtitle string
}
func init() {
tcell.ColorNames["none"] = tcell.ColorDefault
}
func newColor() *Colors {
defaultColors := map[string]string{
"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",
}
anko := gomu.anko
// checks for invalid color and set default fallback
for k, v := range defaultColors {
// color from the config file
cfgColor := anko.GetString(k)
if _, ok := tcell.ColorNames[cfgColor]; !ok {
// use default value if invalid hex color was given
anko.Set(k, v)
}
}
accent := anko.GetString("Color.accent")
background := anko.GetString("Color.background")
foreground := anko.GetString("Color.foreground")
popup := anko.GetString("Color.popup")
playlistDir := anko.GetString("Color.playlist_directory")
playlistHi := anko.GetString("Color.playlist_highlight")
queueHi := anko.GetString("Color.queue_highlight")
title := anko.GetString("Color.now_playing_title")
subtitle := anko.GetString("Color.subtitle")
color := &Colors{
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,
}
return color
}
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)
i := 0
colorPad := strings.Repeat(" ", 5)
for name := range tcell.ColorNames {
fmt.Fprintf(textView, "%20s [:%s]%s[:-] ", name, name, colorPad)
if i == 2 {
fmt.Fprint(textView, "\n")
i = 0
continue
}
i++
}
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
}