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