Added Playlist Functionality
Using Switch case for mappings and removed Cycling The Feature of Cycling through all the windows now seems useless instead I am assigning each of the windows a number and one can cycle through them using the number keys. Also now the default window is the playlist window instead of the files tab. The mappings are separated with the help of the global boolean value InPlaylist
This commit is contained in:
parent
db9887c041
commit
c6d2e8d8af
140
main.go
140
main.go
@ -14,6 +14,7 @@ import (
|
||||
var Volume int64
|
||||
var Random bool
|
||||
var Repeat bool
|
||||
var InsidePlaylist bool = true
|
||||
|
||||
func main() {
|
||||
|
||||
@ -29,11 +30,11 @@ func main() {
|
||||
Navbar := tview.NewTable()
|
||||
searchBar := tview.NewTable()
|
||||
|
||||
searchBar.SetBorder(true)
|
||||
searchBar.SetBorder(true).SetTitle("Search").SetTitleAlign(tview.AlignLeft)
|
||||
Navbar.SetBorder(true)
|
||||
Navbar.SetSelectable(true, false)
|
||||
Navbar.SetCell(0, 0, tview.NewTableCell("Files"))
|
||||
Navbar.SetCell(1, 0, tview.NewTableCell("Playlist"))
|
||||
Navbar.SetCell(0, 0, tview.NewTableCell("PlayList"))
|
||||
Navbar.SetCell(1, 0, tview.NewTableCell("Files"))
|
||||
Navbar.SetCell(2, 0, tview.NewTableCell("Most Played"))
|
||||
|
||||
searchNavFlex := tview.NewFlex().SetDirection(tview.FlexRow).
|
||||
@ -53,84 +54,93 @@ func main() {
|
||||
expandedView.SetBorderPadding(1, 1, 1, 1).SetBorder(true)
|
||||
expandedView.SetSelectable(true, false)
|
||||
|
||||
a, err := conn.GetFiles()
|
||||
aer := generateDirectoryTree(a)
|
||||
fileMap, err := conn.GetFiles()
|
||||
dirTree := generateDirectoryTree(fileMap)
|
||||
|
||||
Update(*conn, aer.children, expandedView)
|
||||
UpdatePlaylist(*conn, expandedView)
|
||||
|
||||
Navbar.SetDoneFunc(func(key tcell.Key) {
|
||||
if key == tcell.KeyTAB {
|
||||
App.SetFocus(searchBar)
|
||||
} else if key == tcell.KeyBacktab {
|
||||
App.SetFocus(expandedView)
|
||||
}
|
||||
})
|
||||
expandedView.SetDoneFunc(func(key tcell.Key) {
|
||||
if key == tcell.KeyTAB {
|
||||
App.SetFocus(Navbar)
|
||||
} else if key == tcell.KeyBacktab {
|
||||
App.SetFocus(searchBar)
|
||||
}
|
||||
})
|
||||
searchBar.SetDoneFunc(func(key tcell.Key) {
|
||||
if key == tcell.KeyTAB {
|
||||
App.SetFocus(expandedView)
|
||||
} else if key == tcell.KeyBacktab {
|
||||
App.SetFocus(Navbar)
|
||||
}
|
||||
})
|
||||
|
||||
v, _ := conn.Status()
|
||||
Volume, _ = strconv.ParseInt(v["volume"], 10, 64)
|
||||
Random, _ = strconv.ParseBool(v["random"])
|
||||
Repeat, _ = strconv.ParseBool(v["repeat"])
|
||||
_v, _ := conn.Status()
|
||||
Volume, _ = strconv.ParseInt(_v["volume"], 10, 64)
|
||||
Random, _ = strconv.ParseBool(_v["random"])
|
||||
Repeat, _ = strconv.ParseBool(_v["repeat"])
|
||||
|
||||
expandedView.SetInputCapture(func(e *tcell.EventKey) *tcell.EventKey {
|
||||
if e.Rune() == 108 {
|
||||
switch e.Rune() {
|
||||
case 108: // L : Key
|
||||
{
|
||||
r, _ := expandedView.GetSelection()
|
||||
if len(aer.children[r].children) == 0 {
|
||||
id, _ := conn.AddId(aer.children[r].absolutePath, -1)
|
||||
if !InsidePlaylist {
|
||||
if len(dirTree.children[r].children) == 0 {
|
||||
id, _ := conn.AddId(dirTree.children[r].absolutePath, -1)
|
||||
conn.PlayId(id)
|
||||
} else {
|
||||
Update(*conn, aer.children[r].children, expandedView)
|
||||
aer = &aer.children[r]
|
||||
Update(*conn, dirTree.children[r].children, expandedView)
|
||||
dirTree = &dirTree.children[r]
|
||||
}
|
||||
} else {
|
||||
conn.Play(r)
|
||||
}
|
||||
return nil
|
||||
} else if e.Rune() == 112 {
|
||||
}
|
||||
case 112: // P : Key
|
||||
{
|
||||
togglePlayBack(*conn)
|
||||
return nil
|
||||
} else if e.Rune() == 104 {
|
||||
if aer.parent != nil {
|
||||
Update(*conn, aer.parent.children, expandedView)
|
||||
aer = aer.parent
|
||||
}
|
||||
case 104: // H : Key
|
||||
{
|
||||
if !InsidePlaylist {
|
||||
if dirTree.parent != nil {
|
||||
Update(*conn, dirTree.parent.children, expandedView)
|
||||
dirTree = dirTree.parent
|
||||
}
|
||||
}
|
||||
return nil
|
||||
} else if e.Rune() == 110 {
|
||||
}
|
||||
case 110: // N : Key
|
||||
{
|
||||
conn.Next()
|
||||
return nil
|
||||
} else if e.Rune() == 99 {
|
||||
}
|
||||
case 99: // C : Key
|
||||
{
|
||||
conn.Clear()
|
||||
if InsidePlaylist {
|
||||
UpdatePlaylist(*conn, expandedView)
|
||||
}
|
||||
return nil
|
||||
} else if e.Rune() == 78 {
|
||||
}
|
||||
case 78: // Shift - N : Key
|
||||
{
|
||||
conn.Previous()
|
||||
return nil
|
||||
} else if e.Rune() == 97 {
|
||||
}
|
||||
case 97: // A : Key
|
||||
{
|
||||
if !InsidePlaylist {
|
||||
r, _ := expandedView.GetSelection()
|
||||
conn.Add(aer.children[r].absolutePath)
|
||||
conn.Add(dirTree.children[r].absolutePath)
|
||||
}
|
||||
return nil
|
||||
} else if e.Rune() == 122 {
|
||||
}
|
||||
case 122: // Z : Key
|
||||
{
|
||||
err := conn.Random(!Random)
|
||||
if err == nil {
|
||||
Random = !Random
|
||||
}
|
||||
return nil
|
||||
} else if e.Rune() == 114 {
|
||||
}
|
||||
case 114: // R : Key
|
||||
{
|
||||
err := conn.Repeat(!Repeat)
|
||||
if err == nil {
|
||||
Repeat = !Repeat
|
||||
}
|
||||
return nil
|
||||
} else if e.Rune() == 45 {
|
||||
}
|
||||
case 45: // Minus : Key
|
||||
{
|
||||
if Volume <= 0 {
|
||||
Volume = 0
|
||||
} else {
|
||||
@ -138,7 +148,9 @@ func main() {
|
||||
}
|
||||
conn.SetVolume(int(Volume))
|
||||
return nil
|
||||
} else if e.Rune() == 61 {
|
||||
}
|
||||
case 61: // Plus : Key
|
||||
{
|
||||
if Volume >= 100 {
|
||||
Volume = 100
|
||||
} else {
|
||||
@ -146,10 +158,32 @@ func main() {
|
||||
}
|
||||
conn.SetVolume(int(Volume))
|
||||
return nil
|
||||
} else {
|
||||
// fmt.Println(e.Rune())
|
||||
}
|
||||
case 50: // 2 : Key
|
||||
{
|
||||
InsidePlaylist = false
|
||||
Navbar.Select(1, 0)
|
||||
Update(*conn, dirTree.children, expandedView)
|
||||
return nil
|
||||
}
|
||||
case 49: // 1 : Key
|
||||
{
|
||||
InsidePlaylist = true
|
||||
Navbar.Select(0, 0)
|
||||
UpdatePlaylist(*conn, expandedView)
|
||||
return nil
|
||||
}
|
||||
case 51: // 3 : Key
|
||||
{
|
||||
InsidePlaylist = false
|
||||
Navbar.Select(2, 0)
|
||||
return nil
|
||||
}
|
||||
default:
|
||||
{
|
||||
return e
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
go func() {
|
||||
|
Loading…
Reference in New Issue
Block a user