From 1e9c5864cfd9a472f0c7df7dea87ffaa4983e330 Mon Sep 17 00:00:00 2001 From: raziman Date: Tue, 16 Mar 2021 11:47:35 +0800 Subject: [PATCH] add more configurable color --- colors.go | 64 +++++++++++++++++++++++++-------------------------- playingbar.go | 4 +++- playlist.go | 20 ++++++++-------- queue.go | 4 ++-- start.go | 10 ++++++-- test/config | 11 ++++++--- 6 files changed, 63 insertions(+), 50 deletions(-) diff --git a/colors.go b/colors.go index 9e7b7f9..599100f 100644 --- a/colors.go +++ b/colors.go @@ -10,12 +10,15 @@ import ( type Colors struct { accent tcell.Color - foreground tcell.Color background tcell.Color + foreground tcell.Color // title refers to now_playing_title in config file - title tcell.Color - popup tcell.Color - playlist tcell.Color + title tcell.Color + popup tcell.Color + playlistHi tcell.Color + playlistDir tcell.Color + queueHi tcell.Color + subtitle string } func init() { @@ -25,12 +28,15 @@ func init() { func newColor() *Colors { defaultColors := map[string]string{ - "Color.accent": "darkcyan", - "Color.background": "none", - "Color.foreground": "white", - "Color.now_playing_title": "darkgreen", - "Color.playlist": "white", - "Color.popup": "black", + "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 @@ -47,38 +53,30 @@ func newColor() *Colors { } } - accent := anko.GetString("Color.accent") - foreground := anko.GetString("Color.foreground") 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") - playlist := anko.GetString("Color.playlist") + subtitle := anko.GetString("Color.subtitle") color := &Colors{ - accent: tcell.ColorNames[accent], - foreground: tcell.ColorNames[foreground], - background: tcell.ColorNames[background], - popup: tcell.ColorNames[popup], - title: tcell.ColorNames[title], - playlist: tcell.ColorNames[playlist], + 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 isValidColor(x tcell.Color) bool { - return (x == tcell.ColorDefault) || x >= tcell.ColorBlack && x <= tcell.ColorYellowGreen -} - -func intToColor(x int) tcell.Color { - - if x == -1 { - return tcell.ColorDefault - } - - return tcell.Color(x) + tcell.ColorBlack -} - func colorsPopup() tview.Primitive { textView := tview.NewTextView(). @@ -99,7 +97,7 @@ func colorsPopup() tview.Primitive { fmt.Fprintf(textView, "%20s [:%s]%s[:-] ", name, name, colorPad) if i == 2 { - fmt.Fprint(textView, "\n") + fmt.Fprint(textView, "\n") i = 0 continue } diff --git a/playingbar.go b/playingbar.go index 3a54f76..20c0e79 100644 --- a/playingbar.go +++ b/playingbar.go @@ -43,6 +43,7 @@ func newPlayingBar() *PlayingBar { textView := tview.NewTextView().SetTextAlign(tview.AlignCenter) textView.SetBackgroundColor(gomu.colors.background) + textView.SetDynamicColors(true) frame := tview.NewFrame(textView).SetBorders(1, 1, 1, 1, 1, 1) frame.SetBorder(true).SetTitle(" Now Playing ") @@ -113,10 +114,11 @@ func (p *PlayingBar) run() error { } 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), progressBar, fmtDuration(end), + gomu.colors.subtitle, lyricText, )) }) diff --git a/playlist.go b/playlist.go index 1a7f02f..aff2640 100644 --- a/playlist.go +++ b/playlist.go @@ -110,7 +110,7 @@ func newPlaylist(args Args) *Playlist { } root := tview.NewTreeNode(rootTextView). - SetColor(gomu.colors.accent) + SetColor(gomu.colors.playlistDir) tree := tview.NewTreeView().SetRoot(root) tree.SetBackgroundColor(gomu.colors.background) @@ -128,7 +128,7 @@ func newPlaylist(args Args) *Playlist { } root.SetReference(rootAudioFile) - root.SetColor(gomu.colors.playlist) + root.SetColor(gomu.colors.playlistDir) playlist. SetTitle(playlist.defaultTitle). @@ -419,15 +419,17 @@ func (p *Playlist) createPlaylist(name string) error { func (p *Playlist) setHighlight(currNode *tview.TreeNode) { if p.prevNode != nil { - p.prevNode.SetColor(gomu.colors.foreground) + if p.prevNode.GetReference().(*AudioFile).isAudioFile { + p.prevNode.SetColor(gomu.colors.foreground) + } else { + p.prevNode.SetColor(gomu.colors.playlistDir) + } } - currNode.SetColor(gomu.colors.playlist) + + currNode.SetColor(gomu.colors.playlistHi) p.SetCurrentNode(currNode) - if currNode.GetReference().(*AudioFile).isAudioFile { - p.prevNode = currNode - } - + p.prevNode = currNode } // Traverses the playlist and finds the AudioFile struct @@ -719,7 +721,7 @@ func populate(root *tview.TreeNode, rootPath string) error { displayText := setDisplayText(audioFile) child.SetReference(audioFile) - child.SetColor(gomu.colors.playlist) + child.SetColor(gomu.colors.playlistDir) child.SetText(displayText) root.AddChild(child) populate(child, path) diff --git a/queue.go b/queue.go index 4d9b41d..cb1ee29 100644 --- a/queue.go +++ b/queue.go @@ -409,8 +409,8 @@ func newQueue() *Queue { queue. ShowSecondaryText(false). - SetSelectedBackgroundColor(gomu.colors.accent). - SetSelectedTextColor(tcell.ColorWhite). + SetSelectedBackgroundColor(gomu.colors.queueHi). + SetSelectedTextColor(gomu.colors.foreground). SetHighlightFullLine(true) queue. diff --git a/start.go b/start.go index 2d7ce5a..8c635e7 100644 --- a/start.go +++ b/start.go @@ -227,9 +227,15 @@ module Color { accent = "darkcyan" background = "none" foreground = "white" - now_playing_title = "darkgreen" - playlist = "white" popup = "black" + + 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: diff --git a/test/config b/test/config index d7d018d..d6b91e2 100644 --- a/test/config +++ b/test/config @@ -35,10 +35,15 @@ module Color { accent = "darkcyan" background = "none" foreground = "white" - now_playing_title = "darkgreen" - # the color of the directory in playlist - playlist = "darkslategray" popup = "black" + + playlist_directory = "darkcyan" + playlist_highlight = "darkcyan" + + queue_highlight = "darkcyan" + + now_playing_title = "darkgreen" + subtitle = "darkgoldenrod" } func fib(x) {