mirror of
https://github.com/issadarkthing/gomu.git
synced 2025-04-28 13:48:53 +08:00
Merge pull request #43 from issadarkthing/refactor-color
Better color support
This commit is contained in:
commit
70167ba6c3
@ -72,6 +72,7 @@ Each panel has it's own additional keybinding. To view the available keybinding
|
|||||||
| ? | toggle help |
|
| ? | toggle help |
|
||||||
| m | open repl |
|
| m | open repl |
|
||||||
| T | switch lyrics |
|
| T | switch lyrics |
|
||||||
|
| c | show colors |
|
||||||
|
|
||||||
|
|
||||||
| Key (Playlist) | Description |
|
| Key (Playlist) | Description |
|
||||||
|
103
colors.go
103
colors.go
@ -1,68 +1,117 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/gdamore/tcell/v2"
|
"github.com/gdamore/tcell/v2"
|
||||||
|
"github.com/rivo/tview"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Colors struct {
|
type Colors struct {
|
||||||
accent tcell.Color
|
accent tcell.Color
|
||||||
foreground tcell.Color
|
|
||||||
background tcell.Color
|
background tcell.Color
|
||||||
|
foreground tcell.Color
|
||||||
// title refers to now_playing_title in config file
|
// title refers to now_playing_title in config file
|
||||||
title tcell.Color
|
title tcell.Color
|
||||||
popup tcell.Color
|
popup tcell.Color
|
||||||
playlist tcell.Color
|
playlistHi tcell.Color
|
||||||
|
playlistDir tcell.Color
|
||||||
|
queueHi tcell.Color
|
||||||
|
subtitle string
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
tcell.ColorNames["none"] = tcell.ColorDefault
|
||||||
}
|
}
|
||||||
|
|
||||||
func newColor() *Colors {
|
func newColor() *Colors {
|
||||||
|
|
||||||
defaultColors := map[string]string{
|
defaultColors := map[string]string{
|
||||||
"Color.accent": "#008B8B",
|
"Color.accent": "darkcyan",
|
||||||
"Color.foreground": "#FFFFFF",
|
|
||||||
"Color.background": "none",
|
"Color.background": "none",
|
||||||
"Color.popup": "#0A0F14",
|
"Color.foreground": "white",
|
||||||
"Color.now_playing_title": "#017702",
|
"Color.popup": "black",
|
||||||
"Color.playlist": "#008B8B",
|
"Color.playlist_directory": "darkcyan",
|
||||||
|
"Color.playlist_highlight": "darkcyan",
|
||||||
|
"Color.queue_highlight": "darkcyan",
|
||||||
|
"Color.now_playing_title": "darkgreen",
|
||||||
|
"Color.subtitle": "darkgoldenrod",
|
||||||
}
|
}
|
||||||
|
|
||||||
anko := gomu.anko
|
anko := gomu.anko
|
||||||
|
|
||||||
// Validate hex color
|
// checks for invalid color and set default fallback
|
||||||
for k, v := range defaultColors {
|
for k, v := range defaultColors {
|
||||||
|
|
||||||
// color from the config file
|
// color from the config file
|
||||||
cfgColor := anko.GetString(k)
|
cfgColor := anko.GetString(k)
|
||||||
if validHexColor(cfgColor) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if _, ok := tcell.ColorNames[cfgColor]; !ok {
|
||||||
// use default value if invalid hex color was given
|
// use default value if invalid hex color was given
|
||||||
anko.Set(k, v)
|
anko.Set(k, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
// handle none background color
|
|
||||||
var bgColor tcell.Color
|
|
||||||
bg := anko.GetString("Color.background")
|
|
||||||
|
|
||||||
if bg == "none" {
|
|
||||||
bgColor = tcell.ColorDefault
|
|
||||||
} else {
|
|
||||||
bgColor = tcell.GetColor(bg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
accent := anko.GetString("Color.accent")
|
accent := anko.GetString("Color.accent")
|
||||||
|
background := anko.GetString("Color.background")
|
||||||
foreground := anko.GetString("Color.foreground")
|
foreground := anko.GetString("Color.foreground")
|
||||||
popup := anko.GetString("Color.popup")
|
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")
|
title := anko.GetString("Color.now_playing_title")
|
||||||
playlist := anko.GetString("Color.playlist")
|
subtitle := anko.GetString("Color.subtitle")
|
||||||
|
|
||||||
color := &Colors{
|
color := &Colors{
|
||||||
accent: tcell.GetColor(accent),
|
accent: tcell.ColorNames[accent],
|
||||||
foreground: tcell.GetColor(foreground),
|
foreground: tcell.ColorNames[foreground],
|
||||||
background: bgColor,
|
background: tcell.ColorNames[background],
|
||||||
popup: tcell.GetColor(popup),
|
popup: tcell.ColorNames[popup],
|
||||||
title: tcell.GetColor(title),
|
playlistDir: tcell.ColorNames[playlistDir],
|
||||||
playlist: tcell.GetColor(playlist),
|
playlistHi: tcell.ColorNames[playlistHi],
|
||||||
|
queueHi: tcell.ColorNames[queueHi],
|
||||||
|
title: tcell.ColorNames[title],
|
||||||
|
subtitle: subtitle,
|
||||||
}
|
}
|
||||||
return color
|
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
|
||||||
|
}
|
||||||
|
@ -445,6 +445,12 @@ func (c Command) defineCommands() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
c.define("show_colors", func() {
|
||||||
|
cp := colorsPopup()
|
||||||
|
gomu.pages.AddPage("show-color-popup", center(cp, 95, 40), true, true)
|
||||||
|
gomu.popups.push(cp)
|
||||||
|
})
|
||||||
|
|
||||||
for name, cmd := range c.commands {
|
for name, cmd := range c.commands {
|
||||||
err := gomu.anko.Define(name, cmd)
|
err := gomu.anko.Define(name, cmd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
4
gomu.go
4
gomu.go
@ -130,8 +130,8 @@ func (g *Gomu) setFocusPanel(panel Panel) {
|
|||||||
|
|
||||||
// Removes the color of the given panel
|
// Removes the color of the given panel
|
||||||
func (g *Gomu) setUnfocusPanel(panel Panel) {
|
func (g *Gomu) setUnfocusPanel(panel Panel) {
|
||||||
g.prevPanel.SetBorderColor(g.colors.background)
|
g.prevPanel.SetBorderColor(g.colors.foreground)
|
||||||
g.prevPanel.SetTitleColor(g.colors.background)
|
g.prevPanel.SetTitleColor(g.colors.foreground)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Quit the application and do the neccessary clean up
|
// Quit the application and do the neccessary clean up
|
||||||
|
@ -37,6 +37,7 @@ func newPlayingBar() *PlayingBar {
|
|||||||
|
|
||||||
textView := tview.NewTextView().SetTextAlign(tview.AlignCenter)
|
textView := tview.NewTextView().SetTextAlign(tview.AlignCenter)
|
||||||
textView.SetBackgroundColor(gomu.colors.background)
|
textView.SetBackgroundColor(gomu.colors.background)
|
||||||
|
textView.SetDynamicColors(true)
|
||||||
|
|
||||||
frame := tview.NewFrame(textView).SetBorders(1, 1, 1, 1, 1, 1)
|
frame := tview.NewFrame(textView).SetBorders(1, 1, 1, 1, 1, 1)
|
||||||
frame.SetBorder(true).SetTitle(" Now Playing ")
|
frame.SetBorder(true).SetTitle(" Now Playing ")
|
||||||
@ -107,10 +108,11 @@ func (p *PlayingBar) run() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gomu.app.QueueUpdateDraw(func() {
|
gomu.app.QueueUpdateDraw(func() {
|
||||||
p.text.SetText(fmt.Sprintf("%s ┃%s┫ %s\n\n%v",
|
p.text.SetText(fmt.Sprintf("%s ┃%s┫ %s\n\n[%s]%v[-]",
|
||||||
fmtDuration(start),
|
fmtDuration(start),
|
||||||
progressBar,
|
progressBar,
|
||||||
fmtDuration(end),
|
fmtDuration(end),
|
||||||
|
gomu.colors.subtitle,
|
||||||
lyricText,
|
lyricText,
|
||||||
))
|
))
|
||||||
})
|
})
|
||||||
|
17
playlist.go
17
playlist.go
@ -114,7 +114,7 @@ func newPlaylist(args Args) *Playlist {
|
|||||||
}
|
}
|
||||||
|
|
||||||
root := tview.NewTreeNode(rootTextView).
|
root := tview.NewTreeNode(rootTextView).
|
||||||
SetColor(gomu.colors.accent)
|
SetColor(gomu.colors.playlistDir)
|
||||||
|
|
||||||
tree := tview.NewTreeView().SetRoot(root)
|
tree := tview.NewTreeView().SetRoot(root)
|
||||||
tree.SetBackgroundColor(gomu.colors.background)
|
tree.SetBackgroundColor(gomu.colors.background)
|
||||||
@ -132,6 +132,7 @@ func newPlaylist(args Args) *Playlist {
|
|||||||
}
|
}
|
||||||
|
|
||||||
root.SetReference(rootAudioFile)
|
root.SetReference(rootAudioFile)
|
||||||
|
root.SetColor(gomu.colors.playlistDir)
|
||||||
|
|
||||||
playlist.
|
playlist.
|
||||||
SetTitle(playlist.defaultTitle).
|
SetTitle(playlist.defaultTitle).
|
||||||
@ -419,17 +420,19 @@ func (p *Playlist) createPlaylist(name string) error {
|
|||||||
func (p *Playlist) setHighlight(currNode *tview.TreeNode) {
|
func (p *Playlist) setHighlight(currNode *tview.TreeNode) {
|
||||||
|
|
||||||
if p.prevNode != nil {
|
if p.prevNode != nil {
|
||||||
p.prevNode.SetColor(gomu.colors.background)
|
if p.prevNode.GetReference().(*AudioFile).isAudioFile {
|
||||||
|
p.prevNode.SetColor(gomu.colors.foreground)
|
||||||
|
} else {
|
||||||
|
p.prevNode.SetColor(gomu.colors.playlistDir)
|
||||||
}
|
}
|
||||||
currNode.SetColor(gomu.colors.accent)
|
}
|
||||||
|
|
||||||
|
currNode.SetColor(gomu.colors.playlistHi)
|
||||||
p.SetCurrentNode(currNode)
|
p.SetCurrentNode(currNode)
|
||||||
|
|
||||||
if currNode.GetReference().(*AudioFile).isAudioFile {
|
|
||||||
p.prevNode = currNode
|
p.prevNode = currNode
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Traverses the playlist and finds the AudioFile struct
|
// Traverses the playlist and finds the AudioFile struct
|
||||||
// audioName must be hashed with sha1 first
|
// audioName must be hashed with sha1 first
|
||||||
func (p *Playlist) findAudioFile(audioName string) (*AudioFile, error) {
|
func (p *Playlist) findAudioFile(audioName string) (*AudioFile, error) {
|
||||||
@ -733,7 +736,7 @@ func populate(root *tview.TreeNode, rootPath string, sortMtime bool) error {
|
|||||||
displayText := setDisplayText(audioFile)
|
displayText := setDisplayText(audioFile)
|
||||||
|
|
||||||
child.SetReference(audioFile)
|
child.SetReference(audioFile)
|
||||||
child.SetColor(gomu.colors.accent)
|
child.SetColor(gomu.colors.playlistDir)
|
||||||
child.SetText(displayText)
|
child.SetText(displayText)
|
||||||
root.AddChild(child)
|
root.AddChild(child)
|
||||||
populate(child, path, sortMtime)
|
populate(child, path, sortMtime)
|
||||||
|
1
popup.go
1
popup.go
@ -271,6 +271,7 @@ func helpPopup(panel Panel) {
|
|||||||
"? toggle help",
|
"? toggle help",
|
||||||
"m open repl",
|
"m open repl",
|
||||||
"T switch lyrics",
|
"T switch lyrics",
|
||||||
|
"c show colors",
|
||||||
}
|
}
|
||||||
|
|
||||||
list := tview.NewList().ShowSecondaryText(false)
|
list := tview.NewList().ShowSecondaryText(false)
|
||||||
|
22
queue.go
22
queue.go
@ -358,10 +358,7 @@ func (q *Queue) shuffle() {
|
|||||||
// Initiliaze new queue with default values
|
// Initiliaze new queue with default values
|
||||||
func newQueue() *Queue {
|
func newQueue() *Queue {
|
||||||
|
|
||||||
list := tview.NewList().
|
list := tview.NewList()
|
||||||
ShowSecondaryText(false)
|
|
||||||
|
|
||||||
list.SetBackgroundColor(gomu.colors.background)
|
|
||||||
|
|
||||||
queue := &Queue{
|
queue := &Queue{
|
||||||
List: list,
|
List: list,
|
||||||
@ -409,12 +406,19 @@ func newQueue() *Queue {
|
|||||||
})
|
})
|
||||||
|
|
||||||
queue.updateTitle()
|
queue.updateTitle()
|
||||||
queue.SetBorder(true).SetTitleAlign(tview.AlignLeft)
|
|
||||||
queue.
|
queue.
|
||||||
SetSelectedBackgroundColor(tcell.ColorDarkCyan).
|
ShowSecondaryText(false).
|
||||||
SetSelectedTextColor(tcell.ColorWhite).
|
SetSelectedBackgroundColor(gomu.colors.queueHi).
|
||||||
SetHighlightFullLine(true).
|
SetSelectedTextColor(gomu.colors.foreground).
|
||||||
SetBorderPadding(0, 0, 1, 1)
|
SetHighlightFullLine(true)
|
||||||
|
|
||||||
|
queue.
|
||||||
|
SetBorder(true).
|
||||||
|
SetTitleAlign(tview.AlignLeft).
|
||||||
|
SetBorderPadding(0, 0, 1, 1).
|
||||||
|
SetBorderColor(gomu.colors.foreground).
|
||||||
|
SetBackgroundColor(gomu.colors.background)
|
||||||
|
|
||||||
return queue
|
return queue
|
||||||
|
|
||||||
|
20
start.go
20
start.go
@ -224,14 +224,19 @@ module Emoji {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module Color {
|
module Color {
|
||||||
# not all colors can be reproducible in terminal
|
# you may choose colors by pressing 'c'
|
||||||
# changing hex colors may or may not produce expected result
|
accent = "darkcyan"
|
||||||
accent = "#008B8B"
|
|
||||||
background = "none"
|
background = "none"
|
||||||
foreground = "#FFFFFF"
|
foreground = "white"
|
||||||
now_playing_title = "#017702"
|
popup = "black"
|
||||||
playlist = "#008B8B"
|
|
||||||
popup = "#0A0F14"
|
playlist_directory = "darkcyan"
|
||||||
|
playlist_highlight = "darkcyan"
|
||||||
|
|
||||||
|
queue_highlight = "darkcyan"
|
||||||
|
|
||||||
|
now_playing_title = "darkgreen"
|
||||||
|
subtitle = "darkgoldenrod"
|
||||||
}
|
}
|
||||||
|
|
||||||
# you can get the syntax highlighting for this language here:
|
# you can get the syntax highlighting for this language here:
|
||||||
@ -465,6 +470,7 @@ func start(application *tview.Application, args Args) {
|
|||||||
'B': "rewind_fast",
|
'B': "rewind_fast",
|
||||||
'm': "repl",
|
'm': "repl",
|
||||||
'T': "switch_lyric",
|
'T': "switch_lyric",
|
||||||
|
'c': "show_colors",
|
||||||
}
|
}
|
||||||
|
|
||||||
for key, cmd := range cmds {
|
for key, cmd := range cmds {
|
||||||
|
21
test/config
21
test/config
@ -32,14 +32,19 @@ module Emoji {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module Color {
|
module Color {
|
||||||
# not all colors can be reproducible in terminal
|
# you may choose colors by pressing 'c'
|
||||||
# changing hex colors may or may not produce expected result
|
accent = "darkcyan"
|
||||||
accent = "#008B8B"
|
|
||||||
background = "none"
|
background = "none"
|
||||||
foreground = "#FFFFFF"
|
foreground = "white"
|
||||||
now_playing_title = "#017702"
|
popup = "black"
|
||||||
playlist = "#008B8B"
|
|
||||||
popup = "#0A0F14"
|
playlist_directory = "darkcyan"
|
||||||
|
playlist_highlight = "darkcyan"
|
||||||
|
|
||||||
|
queue_highlight = "darkcyan"
|
||||||
|
|
||||||
|
now_playing_title = "darkgreen"
|
||||||
|
subtitle = "darkgoldenrod"
|
||||||
}
|
}
|
||||||
|
|
||||||
func fib(x) {
|
func fib(x) {
|
||||||
@ -115,6 +120,8 @@ Keybinds.def_q("i", func() {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Keybinds.def_g("c", show_colors)
|
||||||
|
|
||||||
# you can get the syntax highlighting for this language here:
|
# you can get the syntax highlighting for this language here:
|
||||||
# https://github.com/mattn/anko/tree/master/misc/vim
|
# https://github.com/mattn/anko/tree/master/misc/vim
|
||||||
# vim: ft=anko
|
# vim: ft=anko
|
||||||
|
Loading…
x
Reference in New Issue
Block a user