Compare commits
5 Commits
79841c1b91
...
22e9aaf60e
Author | SHA1 | Date |
---|---|---|
Sasha Koshka | 22e9aaf60e | |
aditya-K2 | fb2e2a831e | |
aditya-K2 | b53e051694 | |
aditya-K2 | 387f01f531 | |
aditya-K2 | 06da246c3a |
|
@ -13,6 +13,8 @@ type FileNode struct {
|
|||
Parent *FileNode
|
||||
AbsolutePath string
|
||||
Title string
|
||||
Artist string
|
||||
Album string
|
||||
}
|
||||
|
||||
// Source Interface For Fuzzy Searching.
|
||||
|
@ -29,11 +31,11 @@ func (f FileNodes) Len() int {
|
|||
return len(f)
|
||||
}
|
||||
|
||||
func (f *FileNode) AddChildren(path string, title string) {
|
||||
func (f *FileNode) AddChildren(path string, title string, artist string, album string) {
|
||||
if f.Path != "" {
|
||||
f.Children = append(f.Children, FileNode{Children: make([]FileNode, 0), Path: path, Parent: f, AbsolutePath: f.AbsolutePath + "/" + path, Title: title})
|
||||
f.Children = append(f.Children, FileNode{Children: make([]FileNode, 0), Path: path, Parent: f, AbsolutePath: f.AbsolutePath + "/" + path, Title: title, Artist: artist, Album: album})
|
||||
} else {
|
||||
f.Children = append(f.Children, FileNode{Children: make([]FileNode, 0), Path: path, Parent: f, AbsolutePath: f.AbsolutePath + path, Title: title})
|
||||
f.Children = append(f.Children, FileNode{Children: make([]FileNode, 0), Path: path, Parent: f, AbsolutePath: f.AbsolutePath + path})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,7 +51,7 @@ func GenerateDirectoryTree(path []mpd.Attrs) *FileNode {
|
|||
sepPaths := strings.Split(path[i]["file"], "/")
|
||||
for j := range sepPaths {
|
||||
if len(head.Children) == 0 {
|
||||
head.AddChildren(sepPaths[j], path[i]["Title"])
|
||||
head.AddChildren(sepPaths[j], path[i]["Title"], path[i]["Artist"], path[i]["Album"])
|
||||
head = &(head.Children[len(head.Children)-1])
|
||||
} else {
|
||||
var headIsChanged = false
|
||||
|
@ -61,7 +63,7 @@ func GenerateDirectoryTree(path []mpd.Attrs) *FileNode {
|
|||
}
|
||||
}
|
||||
if !headIsChanged {
|
||||
head.AddChildren(sepPaths[j], path[i]["Title"])
|
||||
head.AddChildren(sepPaths[j], path[i]["Title"], path[i]["Artist"], path[i]["Album"])
|
||||
head = &(head.Children[len(head.Children)-1])
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
|
@ -39,7 +38,7 @@ func ReadConfig() {
|
|||
|
||||
err := viper.ReadInConfig()
|
||||
if err != nil {
|
||||
fmt.Println("Could Not Read Config file.")
|
||||
utils.Print("RED", "Could Not Read Config file.\n")
|
||||
}
|
||||
|
||||
// Expanding ~ to the User's Home Directory
|
||||
|
@ -66,7 +65,7 @@ func GenerateKeyMap(funcMap map[string]func()) {
|
|||
func getMusicDirectory() string {
|
||||
content, err := ioutil.ReadFile(HOME_DIR + "/.config/mpd/mpd.conf")
|
||||
if err != nil {
|
||||
fmt.Println("No Config File for mpd Found")
|
||||
utils.Print("RED", "No Config File for mpd Found.\n")
|
||||
panic(err)
|
||||
}
|
||||
ab := string(content)
|
||||
|
|
96
ui/app.go
96
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,
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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 "⏸︎"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -74,20 +74,17 @@ func (f FileView) Update(inputTable *tview.Table) {
|
|||
inputTable.Clear()
|
||||
for i, j := range client.DirTree.Children {
|
||||
if len(j.Children) == 0 {
|
||||
_songAttributes, err := client.Conn.ListAllInfo(j.AbsolutePath)
|
||||
if err == nil && _songAttributes[0]["Title"] != "" {
|
||||
if j.Title != "" {
|
||||
_, _, w, _ := inputTable.GetInnerRect()
|
||||
inputTable.SetCell(i, 0,
|
||||
GetCell(
|
||||
utils.GetFormattedString(_songAttributes[0]["Title"], w/3), tcell.ColorGreen, false))
|
||||
|
||||
utils.GetFormattedString(j.Title, w/3), tcell.ColorGreen, false))
|
||||
inputTable.SetCell(i, 1,
|
||||
GetCell(
|
||||
utils.GetFormattedString(_songAttributes[0]["Artist"], w/3), tcell.ColorPurple, false))
|
||||
utils.GetFormattedString(j.Artist, w/3), tcell.ColorPurple, false))
|
||||
inputTable.SetCell(i, 2,
|
||||
GetCell(_songAttributes[0]["Album"], tcell.ColorYellow, false))
|
||||
|
||||
} else if _songAttributes[0]["Title"] == "" {
|
||||
GetCell(j.Album, tcell.ColorYellow, false))
|
||||
} else if j.Title == "" {
|
||||
inputTable.SetCell(i, 0,
|
||||
GetCell(j.Path, tcell.ColorBlue, true))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue