Made it look cooler
This commit is contained in:
parent
fb2e2a831e
commit
22e9aaf60e
96
ui/app.go
96
ui/app.go
@ -24,59 +24,77 @@ type Application struct {
|
|||||||
|
|
||||||
func NewApplication() *Application {
|
func NewApplication() *Application {
|
||||||
|
|
||||||
pBar := NewProgressBar()
|
// progress bar
|
||||||
pBar.SetProgressFunc(ProgressFunction)
|
progressBar := NewProgressBar()
|
||||||
|
progressBar.SetProgressFunc(ProgressFunction)
|
||||||
|
|
||||||
|
// main view
|
||||||
expandedView := tview.NewTable()
|
expandedView := tview.NewTable()
|
||||||
Navbar := tview.NewTable()
|
expandedView.SetBackgroundColor(tcell.ColorDefault)
|
||||||
searchBar := tview.NewInputField()
|
expandedView.SetBorderPadding(0, 1, 1, 1).SetBorder(false)
|
||||||
searchBar.SetFieldBackgroundColor(tcell.ColorDefault)
|
expandedView.SetSelectable(true, false)
|
||||||
|
|
||||||
|
// image preview
|
||||||
imagePreviewer := tview.NewBox()
|
imagePreviewer := tview.NewBox()
|
||||||
imagePreviewer.SetBorder(true)
|
imagePreviewer.SetBorder(false)
|
||||||
imagePreviewer.SetDrawFunc(func(s tcell.Screen, x, y, width, height int) (int, int, int, int) {
|
imagePreviewer.SetDrawFunc(func(
|
||||||
|
screen tcell.Screen,
|
||||||
|
x, y,
|
||||||
|
width, height int,
|
||||||
|
) (
|
||||||
|
int, int,
|
||||||
|
int, int,
|
||||||
|
) {
|
||||||
ImgX, ImgY, ImgW, ImgH = imagePreviewer.GetRect()
|
ImgX, ImgY, ImgW, ImgH = imagePreviewer.GetRect()
|
||||||
return imagePreviewer.GetInnerRect()
|
return imagePreviewer.GetInnerRect()
|
||||||
})
|
})
|
||||||
|
|
||||||
expandedView.SetBackgroundColor(tcell.ColorDefault)
|
|
||||||
Navbar.SetBackgroundColor(tcell.ColorDefault)
|
|
||||||
searchBar.SetBackgroundColor(tcell.ColorDefault)
|
|
||||||
imagePreviewer.SetBackgroundColor(tcell.ColorDefault)
|
imagePreviewer.SetBackgroundColor(tcell.ColorDefault)
|
||||||
|
|
||||||
searchBar.SetTitle("Search").SetTitleAlign(tview.AlignLeft)
|
// nav bar
|
||||||
searchBar.SetAutocompleteBackgroundColor(tcell.ColorBlack)
|
navBar := tview.NewTable()
|
||||||
searchBar.SetAutocompleteSelectBackgroundColor(tcell.ColorWhite)
|
navBar.SetBackgroundColor(tcell.ColorDefault)
|
||||||
searchBar.SetAutocompleteMainTextColor(tcell.ColorDarkGray)
|
navBar.SetBorderPadding(1, 1, 2, 2).SetBorder(false)
|
||||||
searchBar.SetAutocompleteSelectedTextColor(tcell.ColorBlack)
|
navBar.SetBackgroundColor(tcell.ColorBlack)
|
||||||
Navbar.SetBorder(true)
|
navBar.SetSelectable(true, false)
|
||||||
Navbar.SetSelectable(true, false)
|
navBar.SetSelectedStyle(
|
||||||
Navbar.SetCell(0, 0, tview.NewTableCell("PlayList"))
|
tcell.Style{}.
|
||||||
Navbar.SetCell(1, 0, tview.NewTableCell("Files"))
|
Background(tcell.ColorGrey))
|
||||||
Navbar.SetCell(2, 0, tview.NewTableCell("Most Played"))
|
navBar.SetCell(0, 0, tview.NewTableCell("playlist"))
|
||||||
Navbar.SetCell(3, 0, tview.NewTableCell("Search"))
|
navBar.SetCell(1, 0, tview.NewTableCell("files"))
|
||||||
|
navBar.SetCell(2, 0, tview.NewTableCell("most played"))
|
||||||
|
navBar.SetCell(3, 0, tview.NewTableCell("search"))
|
||||||
|
|
||||||
searchNavFlex := tview.NewFlex().SetDirection(tview.FlexRow).
|
// search bar
|
||||||
AddItem(Navbar, 0, 4, false).
|
searchBar := tview.NewInputField()
|
||||||
|
searchBar.SetFieldBackgroundColor(tcell.ColorDefault)
|
||||||
|
searchBar.SetBackgroundColor(tcell.ColorDefault)
|
||||||
|
searchBar.SetTitle("search").SetTitleAlign(tview.AlignLeft)
|
||||||
|
searchBar.SetAutocompleteBackgroundColor(tcell.ColorBlack)
|
||||||
|
searchBar.SetAutocompleteSelectBackgroundColor(tcell.ColorGray)
|
||||||
|
searchBar.SetAutocompleteMainTextColor(tcell.ColorDefault)
|
||||||
|
searchBar.SetAutocompleteSelectedTextColor(tcell.ColorDefault)
|
||||||
|
searchBar.SetBorder(true)
|
||||||
|
searchBar.SetBorderColor(tcell.ColorGray)
|
||||||
|
|
||||||
|
// layout
|
||||||
|
sidebar := tview.NewFlex().SetDirection(tview.FlexRow).
|
||||||
|
AddItem(navBar, 0, 4, false).
|
||||||
AddItem(imagePreviewer, 9, 3, false)
|
AddItem(imagePreviewer, 9, 3, false)
|
||||||
|
|
||||||
sNavExpViewFlex := tview.NewFlex().
|
middleRow := tview.NewFlex().
|
||||||
AddItem(searchNavFlex, 17, 1, false).
|
AddItem(sidebar, 17, 1, false).
|
||||||
AddItem(expandedView, 0, 4, false)
|
AddItem(expandedView, 0, 4, false)
|
||||||
|
|
||||||
searchBar.SetBorder(true)
|
mainLayout := tview.NewFlex().SetDirection(tview.FlexRow).
|
||||||
searchBarFlex := tview.NewFlex().SetDirection(tview.FlexRow).
|
|
||||||
AddItem(searchBar, 3, 1, false).
|
AddItem(searchBar, 3, 1, false).
|
||||||
AddItem(sNavExpViewFlex, 0, 1, false)
|
AddItem(middleRow, 0, 1, false).
|
||||||
|
AddItem(progressBar, 5, 1, false)
|
||||||
MainFlex := tview.NewFlex().SetDirection(tview.FlexRow).
|
|
||||||
AddItem(searchBarFlex, 0, 8, false).
|
|
||||||
AddItem(pBar, 5, 1, false)
|
|
||||||
|
|
||||||
expandedView.SetBorderPadding(1, 1, 1, 1).SetBorder(true)
|
|
||||||
expandedView.SetSelectable(true, false)
|
|
||||||
|
|
||||||
|
// pages
|
||||||
rootPages := tview.NewPages()
|
rootPages := tview.NewPages()
|
||||||
rootPages.AddPage("Main", MainFlex, true, true)
|
rootPages.AddPage("Main", mainLayout, true, true)
|
||||||
|
|
||||||
|
// application
|
||||||
App := tview.NewApplication()
|
App := tview.NewApplication()
|
||||||
App.SetRoot(rootPages, true).SetFocus(expandedView)
|
App.SetRoot(rootPages, true).SetFocus(expandedView)
|
||||||
|
|
||||||
@ -92,9 +110,9 @@ func NewApplication() *Application {
|
|||||||
return &Application{
|
return &Application{
|
||||||
App: App,
|
App: App,
|
||||||
ExpandedView: expandedView,
|
ExpandedView: expandedView,
|
||||||
Navbar: Navbar,
|
Navbar: navBar,
|
||||||
SearchBar: searchBar,
|
SearchBar: searchBar,
|
||||||
ProgressBar: pBar,
|
ProgressBar: progressBar,
|
||||||
Pages: rootPages,
|
Pages: rootPages,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,8 +28,10 @@ func ConnectRenderer(r interface{ Send(string) }) {
|
|||||||
|
|
||||||
// ProgressBar is a two-lined Box. First line is the BarTitle
|
// ProgressBar is a two-lined Box. First line is the BarTitle
|
||||||
// Second being the actual progress done.
|
// Second being the actual progress done.
|
||||||
// Use SetProgressFunc to provide the callback which provides the Fields each time the ProgressBar will be Drawn.
|
// Use SetProgressFunc to provide the callback which provides the Fields each
|
||||||
// The progressFunc must return (BarTitle, BarTopTitle, BarText, percentage) respectively
|
// time the ProgressBar will be Drawn.
|
||||||
|
// The progressFunc must return (BarTitle, BarTopTitle, BarText, percentage)
|
||||||
|
// respectively
|
||||||
type ProgressBar struct {
|
type ProgressBar struct {
|
||||||
*tview.Box
|
*tview.Box
|
||||||
BarTitle string
|
BarTitle string
|
||||||
@ -41,7 +43,11 @@ type ProgressBar struct {
|
|||||||
percentage float64)
|
percentage float64)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *ProgressBar) SetProgressFunc(pfunc func() (string, string, string, float64)) *ProgressBar {
|
func (self *ProgressBar) SetProgressFunc(
|
||||||
|
pfunc func() (string, string, string, float64),
|
||||||
|
) (
|
||||||
|
*ProgressBar,
|
||||||
|
) {
|
||||||
self.progressFunc = pfunc
|
self.progressFunc = pfunc
|
||||||
return self
|
return self
|
||||||
}
|
}
|
||||||
@ -53,7 +59,7 @@ func NewProgressBar() *ProgressBar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetProgressGlyph(width, percentage float64, btext string) string {
|
func GetProgressGlyph(width, percentage float64, btext string) string {
|
||||||
q := "[black:white:b]"
|
q := "[default:gray:b]"
|
||||||
var a string
|
var a string
|
||||||
a += strings.Repeat(" ", int(width)-len(btext))
|
a += strings.Repeat(" ", int(width)-len(btext))
|
||||||
a = utils.InsertAt(a, btext, int(width/2)-10)
|
a = utils.InsertAt(a, btext, int(width/2)-10)
|
||||||
@ -66,15 +72,19 @@ func (self *ProgressBar) Draw(screen tcell.Screen) {
|
|||||||
var (
|
var (
|
||||||
OFFSET int = 1
|
OFFSET int = 1
|
||||||
)
|
)
|
||||||
self.Box.SetBorder(true)
|
self.Box.SetBorder(false)
|
||||||
self.Box.SetBackgroundColor(tcell.ColorDefault)
|
self.Box.SetBorderPadding(1, 1, 1, 1)
|
||||||
|
self.Box.SetBackgroundColor(tcell.ColorBlack)
|
||||||
var percentage float64
|
var percentage float64
|
||||||
self.BarTitle, self.BarTopTitle, self.BarText, percentage = self.progressFunc()
|
self.BarTitle, _, self.BarText, percentage =
|
||||||
|
self.progressFunc()
|
||||||
self.DrawForSubclass(screen, self.Box)
|
self.DrawForSubclass(screen, self.Box)
|
||||||
self.Box.SetTitle(self.BarTopTitle)
|
self.Box.SetTitle(self.BarTopTitle)
|
||||||
self.Box.SetTitleAlign(tview.AlignRight)
|
self.Box.SetTitleAlign(tview.AlignRight)
|
||||||
x, y, _width, _ := self.Box.GetInnerRect()
|
x, y, _width, _ := self.Box.GetInnerRect()
|
||||||
tview.Print(screen, self.BarTitle, x+OFFSET, y, _width, tview.AlignLeft, tcell.ColorWhite)
|
tview.Print(screen,
|
||||||
|
self.BarTitle,
|
||||||
|
x+OFFSET, y, _width, tview.AlignLeft, tcell.ColorWhite)
|
||||||
tview.Print(screen,
|
tview.Print(screen,
|
||||||
GetProgressGlyph(float64(_width-OFFSET-1),
|
GetProgressGlyph(float64(_width-OFFSET-1),
|
||||||
percentage,
|
percentage,
|
||||||
@ -82,38 +92,52 @@ func (self *ProgressBar) Draw(screen tcell.Screen) {
|
|||||||
x, y+2, _width-OFFSET, tview.AlignRight, tcell.ColorWhite)
|
x, y+2, _width-OFFSET, tview.AlignRight, tcell.ColorWhite)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ProgressFunction() (string, string, string, float64) {
|
func ProgressFunction() (
|
||||||
_currentAttributes, err := CONN.CurrentSong()
|
song string,
|
||||||
var song, top, text string
|
top string,
|
||||||
var percentage float64
|
text string,
|
||||||
|
percentage float64,
|
||||||
|
) {
|
||||||
|
// song info
|
||||||
|
currentAttributes, err := CONN.CurrentSong()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
song = "[green::bi]" +
|
song += "[green::bi]" +
|
||||||
_currentAttributes["Title"] + "[-:-:-] - " + "[blue::b]" +
|
currentAttributes["Title"] + "[-:-:-] - " + "[blue::b]" +
|
||||||
_currentAttributes["Artist"] + "\n"
|
currentAttributes["Artist"] + "\n"
|
||||||
if len(_currentAttributes) == 0 && CurrentSong != "" {
|
if len(currentAttributes) == 0 && CurrentSong != "" {
|
||||||
CurrentSong = ""
|
CurrentSong = ""
|
||||||
RENDERER.Send("stop")
|
RENDERER.Send("stop")
|
||||||
} else if song != CurrentSong && len(_currentAttributes) != 0 {
|
} else if song != CurrentSong && len(currentAttributes) != 0 {
|
||||||
RENDERER.Send(_currentAttributes["file"])
|
RENDERER.Send(currentAttributes["file"])
|
||||||
CurrentSong = song
|
CurrentSong = song
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
utils.Print("RED", "Error Retrieving Current Song\n")
|
utils.Print("RED", "Error Retrieving Current Song\n")
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
_status, err := CONN.Status()
|
|
||||||
el, err1 := strconv.ParseFloat(_status["elapsed"], 8)
|
// status
|
||||||
du, err := strconv.ParseFloat(_status["duration"], 8)
|
status, err := CONN.Status()
|
||||||
top = fmt.Sprintf("[[::i] %s [-:-:-]Shuffle: %s Repeat: %s Volume: %s ]",
|
el, err1 := strconv.ParseFloat(status["elapsed"], 8)
|
||||||
utils.FormatString(_status["state"]),
|
du, err := strconv.ParseFloat(status["duration"], 8)
|
||||||
utils.FormatString(_status["random"]),
|
song += fmt.Sprintf(
|
||||||
utils.FormatString(_status["repeat"]),
|
"[gray::-] | " +
|
||||||
_status["volume"])
|
"[[-:]%s[gray::-]] " +
|
||||||
|
"[[-:]shuf: %s[gray::-]] " +
|
||||||
|
"[[-:]rep: %s[gray::-]] " +
|
||||||
|
"[[-:]vol: %s[gray::-]] ",
|
||||||
|
utils.FormatString(status["state"]),
|
||||||
|
utils.FormatString(status["random"]),
|
||||||
|
utils.FormatString(status["repeat"]),
|
||||||
|
status["volume"])
|
||||||
|
|
||||||
|
// bar text
|
||||||
if du != 0 {
|
if du != 0 {
|
||||||
percentage = el / du * 100
|
percentage = el / du * 100
|
||||||
if err == nil && err1 == nil {
|
if err == nil && err1 == nil {
|
||||||
text = utils.StrTime(el) + " / " + utils.StrTime(du) +
|
text = utils.StrTime(el) + " / " + utils.StrTime(du) +
|
||||||
"(" + strconv.FormatFloat(percentage, 'f', 2, 32) + "%" + ")"
|
" (" + strconv.FormatFloat(
|
||||||
|
percentage, 'f', 2, 32) + "%" + ")"
|
||||||
} else {
|
} else {
|
||||||
text = ""
|
text = ""
|
||||||
}
|
}
|
||||||
@ -121,8 +145,12 @@ func ProgressFunction() (string, string, string, float64) {
|
|||||||
text = " ---:---"
|
text = " ---:---"
|
||||||
percentage = 0
|
percentage = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// percentage
|
||||||
if percentage > 100 {
|
if percentage > 100 {
|
||||||
percentage = 0
|
percentage = 0
|
||||||
}
|
}
|
||||||
return song, top, text, percentage
|
|
||||||
|
song = top + song
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
@ -78,15 +78,15 @@ func ConvertToArray(ArtistTree map[string]map[string]map[string]string) []string
|
|||||||
|
|
||||||
func FormatString(a interface{}) string {
|
func FormatString(a interface{}) string {
|
||||||
if a == "play" {
|
if a == "play" {
|
||||||
return "Playing"
|
return "⏵︎"
|
||||||
} else if a == "1" {
|
} else if a == "1" {
|
||||||
return "On"
|
return "✓"
|
||||||
} else if a == "0" {
|
} else if a == "0" {
|
||||||
return "Off"
|
return "x"
|
||||||
} else if a == "stop" {
|
} else if a == "⏹︎" {
|
||||||
return "Stopped"
|
return "stopped"
|
||||||
} else {
|
} else {
|
||||||
return "Paused"
|
return "⏸︎"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user