add more configurable color

This commit is contained in:
raziman 2021-03-16 11:47:35 +08:00
parent 866b87c6a3
commit 1e9c5864cf
6 changed files with 63 additions and 50 deletions

View File

@ -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
playlistHi tcell.Color
playlistDir tcell.Color
queueHi tcell.Color
subtitle string
}
func init() {
@ -28,9 +31,12 @@ func newColor() *Colors {
"Color.accent": "darkcyan",
"Color.background": "none",
"Color.foreground": "white",
"Color.now_playing_title": "darkgreen",
"Color.playlist": "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],
playlistDir: tcell.ColorNames[playlistDir],
playlistHi: tcell.ColorNames[playlistHi],
queueHi: tcell.ColorNames[queueHi],
title: tcell.ColorNames[title],
playlist: tcell.ColorNames[playlist],
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().

View File

@ -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,
))
})

View File

@ -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,17 +419,19 @@ func (p *Playlist) createPlaylist(name string) error {
func (p *Playlist) setHighlight(currNode *tview.TreeNode) {
if p.prevNode != nil {
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
}
}
// Traverses the playlist and finds the AudioFile struct
// audioName must be hashed with sha1 first
func (p *Playlist) findAudioFile(audioName string) (*AudioFile, error) {
@ -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)

View File

@ -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.

View File

@ -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:

View File

@ -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) {