No need to use globals as a separate package to avoid import cycles
This commit is contained in:
parent
49c691e04e
commit
4ae005cbe7
@ -4,34 +4,28 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/aditya-K2/fuzzy"
|
||||||
|
"github.com/aditya-K2/gomp/notify"
|
||||||
"github.com/fhs/gompd/mpd"
|
"github.com/fhs/gompd/mpd"
|
||||||
|
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
CONN *mpd.Client
|
Conn *mpd.Client
|
||||||
ArtistTree map[string]map[string]map[string]string
|
ArtistTree map[string]map[string]map[string]string
|
||||||
NotificationServer interface {
|
|
||||||
Send(string)
|
|
||||||
}
|
|
||||||
WHITE_AND_BOLD string = "[white::b]"
|
WHITE_AND_BOLD string = "[white::b]"
|
||||||
|
DirTree *FileNode
|
||||||
|
Matches fuzzy.Matches
|
||||||
|
SearchContentSlice []interface{}
|
||||||
)
|
)
|
||||||
|
|
||||||
func SetNotificationServer(n interface{ Send(string) }) {
|
|
||||||
NotificationServer = n
|
|
||||||
}
|
|
||||||
|
|
||||||
func SetConnection(c *mpd.Client) {
|
|
||||||
CONN = c
|
|
||||||
}
|
|
||||||
|
|
||||||
func TogglePlayBack() error {
|
func TogglePlayBack() error {
|
||||||
status, err := CONN.Status()
|
status, err := Conn.Status()
|
||||||
if status["state"] == "play" && err == nil {
|
if status["state"] == "play" && err == nil {
|
||||||
CONN.Pause(true)
|
Conn.Pause(true)
|
||||||
} else if status["state"] == "pause" && err == nil {
|
} else if status["state"] == "pause" && err == nil {
|
||||||
CONN.Play(-1)
|
Conn.Play(-1)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -42,7 +36,7 @@ func TogglePlayBack() error {
|
|||||||
func GenerateContentSlice(selectedSuggestion string) ([]interface{}, error) {
|
func GenerateContentSlice(selectedSuggestion string) ([]interface{}, error) {
|
||||||
var ContentSlice []interface{}
|
var ContentSlice []interface{}
|
||||||
if strings.TrimRight(selectedSuggestion, " ") == "" {
|
if strings.TrimRight(selectedSuggestion, " ") == "" {
|
||||||
NotificationServer.Send("Empty Search!")
|
notify.Notify.Send("Empty Search!")
|
||||||
return nil, errors.New("empty Search String Provided")
|
return nil, errors.New("empty Search String Provided")
|
||||||
}
|
}
|
||||||
if _, ok := ArtistTree[selectedSuggestion]; ok {
|
if _, ok := ArtistTree[selectedSuggestion]; ok {
|
||||||
@ -84,7 +78,7 @@ func GenerateContentSlice(selectedSuggestion string) ([]interface{}, error) {
|
|||||||
// Album Tree is a map of the tracks in that particular album.
|
// Album Tree is a map of the tracks in that particular album.
|
||||||
func GenerateArtistTree() (map[string]map[string]map[string]string, error) {
|
func GenerateArtistTree() (map[string]map[string]map[string]string, error) {
|
||||||
ArtistTree = make(map[string]map[string]map[string]string)
|
ArtistTree = make(map[string]map[string]map[string]string)
|
||||||
AllInfo, err := CONN.ListAllInfo("/")
|
AllInfo, err := Conn.ListAllInfo("/")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
for _, i := range AllInfo {
|
for _, i := range AllInfo {
|
||||||
if _, ArtistExists := ArtistTree[i["Artist"]]; !ArtistExists {
|
if _, ArtistExists := ArtistTree[i["Artist"]]; !ArtistExists {
|
||||||
@ -118,12 +112,12 @@ func PrintArtistTree(a map[string]map[string]map[string]string) {
|
|||||||
// Adds All tracks from a specified album to a playlist
|
// Adds All tracks from a specified album to a playlist
|
||||||
func AddAlbum(a map[string]map[string]map[string]string, alb string, artist string) {
|
func AddAlbum(a map[string]map[string]map[string]string, alb string, artist string) {
|
||||||
for _, v := range a[artist][alb] {
|
for _, v := range a[artist][alb] {
|
||||||
err := CONN.Add(v)
|
err := Conn.Add(v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
NotificationServer.Send("Could Not Add Song : " + v)
|
notify.Notify.Send("Could Not Add Song : " + v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
NotificationServer.Send("Album Added : " + alb)
|
notify.Notify.Send("Album Added : " + alb)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adds All tracks from a specified artist to a playlist
|
// Adds All tracks from a specified artist to a playlist
|
||||||
@ -131,31 +125,31 @@ func AddArtist(a map[string]map[string]map[string]string, artist string) {
|
|||||||
if val, ok := a[artist]; ok {
|
if val, ok := a[artist]; ok {
|
||||||
for _, v := range val {
|
for _, v := range val {
|
||||||
for _, path := range v {
|
for _, path := range v {
|
||||||
err := CONN.Add(path)
|
err := Conn.Add(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
NotificationServer.Send("Could Not Add Song : " + path)
|
notify.Notify.Send("Could Not Add Song : " + path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
NotificationServer.Send("Artist Added : " + artist)
|
notify.Notify.Send("Artist Added : " + artist)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adds Specified Track to the Playlist
|
// Adds Specified Track to the Playlist
|
||||||
func AddTitle(a map[string]map[string]map[string]string, artist, alb, track string, addAndPlay bool) {
|
func AddTitle(a map[string]map[string]map[string]string, artist, alb, track string, addAndPlay bool) {
|
||||||
if addAndPlay {
|
if addAndPlay {
|
||||||
id, err := CONN.AddId(a[artist][alb][track], -1)
|
id, err := Conn.AddId(a[artist][alb][track], -1)
|
||||||
CONN.PlayId(id)
|
Conn.PlayId(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
NotificationServer.Send("Could Not Add Track : " + track)
|
notify.Notify.Send("Could Not Add Track : " + track)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
err := CONN.Add(a[artist][alb][track])
|
err := Conn.Add(a[artist][alb][track])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
NotificationServer.Send("Could Not Add Track : " + track)
|
notify.Notify.Send("Could Not Add Track : " + track)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
NotificationServer.Send("Track Added : " + track)
|
notify.Notify.Send("Track Added : " + track)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Querys the Artist Tree for a track and returns a TrackMap (i.e [3]string{artist, album, track} -> Path) which will help us
|
/* Querys the Artist Tree for a track and returns a TrackMap (i.e [3]string{artist, album, track} -> Path) which will help us
|
||||||
|
@ -1,20 +0,0 @@
|
|||||||
package globals
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/aditya-K2/fuzzy"
|
|
||||||
"github.com/aditya-K2/gomp/client"
|
|
||||||
"github.com/aditya-K2/gomp/notify"
|
|
||||||
"github.com/aditya-K2/gomp/render"
|
|
||||||
"github.com/aditya-K2/gomp/ui"
|
|
||||||
"github.com/fhs/gompd/mpd"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
Conn *mpd.Client
|
|
||||||
Notify *notify.NotificationServer
|
|
||||||
Renderer *render.Renderer
|
|
||||||
Ui *ui.Application
|
|
||||||
DirTree *client.FileNode
|
|
||||||
SearchContentSlice []interface{}
|
|
||||||
Matches fuzzy.Matches
|
|
||||||
)
|
|
131
main.go
131
main.go
@ -7,7 +7,6 @@ import (
|
|||||||
"github.com/aditya-K2/gomp/cache"
|
"github.com/aditya-K2/gomp/cache"
|
||||||
"github.com/aditya-K2/gomp/client"
|
"github.com/aditya-K2/gomp/client"
|
||||||
"github.com/aditya-K2/gomp/config"
|
"github.com/aditya-K2/gomp/config"
|
||||||
"github.com/aditya-K2/gomp/globals"
|
|
||||||
"github.com/aditya-K2/gomp/notify"
|
"github.com/aditya-K2/gomp/notify"
|
||||||
"github.com/aditya-K2/gomp/render"
|
"github.com/aditya-K2/gomp/render"
|
||||||
"github.com/aditya-K2/gomp/ui"
|
"github.com/aditya-K2/gomp/ui"
|
||||||
@ -31,30 +30,28 @@ func main() {
|
|||||||
} else if nt == "unix" && port != "" {
|
} else if nt == "unix" && port != "" {
|
||||||
port = ""
|
port = ""
|
||||||
}
|
}
|
||||||
globals.Conn, mpdConnectionError = mpd.Dial(nt,
|
client.Conn, mpdConnectionError = mpd.Dial(nt,
|
||||||
viper.GetString("NETWORK_ADDRESS")+del+port)
|
viper.GetString("NETWORK_ADDRESS")+del+port)
|
||||||
if mpdConnectionError != nil {
|
if mpdConnectionError != nil {
|
||||||
utils.Print("RED", "Could Not Connect to MPD Server\n")
|
utils.Print("RED", "Could Not Connect to MPD Server\n")
|
||||||
utils.Print("GREEN", "Make Sure You Mention the Correct MPD Port in the config file.\n")
|
utils.Print("GREEN", "Make Sure You Mention the Correct MPD Port in the config file.\n")
|
||||||
panic(mpdConnectionError)
|
panic(mpdConnectionError)
|
||||||
}
|
}
|
||||||
CONN := globals.Conn
|
CONN := client.Conn
|
||||||
defer CONN.Close()
|
defer CONN.Close()
|
||||||
|
|
||||||
client.SetConnection(CONN)
|
|
||||||
ui.SetConnection(CONN)
|
ui.SetConnection(CONN)
|
||||||
render.SetConnection(CONN)
|
|
||||||
|
|
||||||
cache.SetCacheDir(viper.GetString("CACHE_DIR"))
|
cache.SetCacheDir(viper.GetString("CACHE_DIR"))
|
||||||
|
|
||||||
globals.Renderer = render.NewRenderer()
|
render.Rendr = render.NewRenderer()
|
||||||
// Connecting the Renderer to the Main UI
|
// Connecting the Renderer to the Main UI
|
||||||
ui.ConnectRenderer(globals.Renderer)
|
ui.ConnectRenderer(render.Rendr)
|
||||||
|
|
||||||
globals.Ui = ui.NewApplication()
|
ui.Ui = ui.NewApplication()
|
||||||
|
|
||||||
// Connecting the Notification Server to the Main UI
|
// Connecting the Notification Server to the Main UI
|
||||||
notify.ConnectUI(globals.Ui)
|
notify.ConnectUI(ui.Ui)
|
||||||
|
|
||||||
fileMap, err := CONN.ListAllInfo("/")
|
fileMap, err := CONN.ListAllInfo("/")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -64,10 +61,10 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Generating the Directory Tree for File Navigation.
|
// Generating the Directory Tree for File Navigation.
|
||||||
globals.DirTree = client.GenerateDirectoryTree(fileMap)
|
client.DirTree = client.GenerateDirectoryTree(fileMap)
|
||||||
|
|
||||||
// Default View upon Opening is of Playlist.
|
// Default View upon Opening is of Playlist.
|
||||||
views.PView.Update(globals.Ui.ExpandedView)
|
views.PView.Update(ui.Ui.ExpandedView)
|
||||||
|
|
||||||
var Volume int64
|
var Volume int64
|
||||||
var Random, Repeat bool
|
var Random, Repeat bool
|
||||||
@ -92,30 +89,26 @@ func main() {
|
|||||||
// Used for Fuzzy Searching
|
// Used for Fuzzy Searching
|
||||||
ArtistTreeContent := utils.ConvertToArray(ArtistTree)
|
ArtistTreeContent := utils.ConvertToArray(ArtistTree)
|
||||||
|
|
||||||
globals.Notify = notify.NewNotificationServer()
|
notify.Notify = notify.NewNotificationServer()
|
||||||
globals.Notify.Start()
|
notify.Notify.Start()
|
||||||
|
|
||||||
if c, err := CONN.CurrentSong(); err != nil {
|
if c, err := CONN.CurrentSong(); err != nil {
|
||||||
utils.Print("RED", "Could Not Retrieve the Current Song\n")
|
utils.Print("RED", "Could Not Retrieve the Current Song\n")
|
||||||
panic(err)
|
panic(err)
|
||||||
} else {
|
} else {
|
||||||
if len(c) != 0 {
|
if len(c) != 0 {
|
||||||
globals.Renderer.Start(c["file"])
|
render.Rendr.Start(c["file"])
|
||||||
} else {
|
} else {
|
||||||
globals.Renderer.Start("stop")
|
render.Rendr.Start("stop")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Connecting Notification Server to Client and Rendering Module so that they can send Notifications
|
|
||||||
client.SetNotificationServer(globals.Notify)
|
|
||||||
render.SetNotificationServer(globals.Notify)
|
|
||||||
|
|
||||||
// This Function Is Responsible for Changing the Focus it uses the Focus Map and Based on it Chooses
|
// This Function Is Responsible for Changing the Focus it uses the Focus Map and Based on it Chooses
|
||||||
// the Draw Function
|
// the Draw Function
|
||||||
views.SetCurrentView(views.PView)
|
views.SetCurrentView(views.PView)
|
||||||
globals.Ui.ExpandedView.SetDrawFunc(func(s tcell.Screen, x, y, width, height int) (int, int, int, int) {
|
ui.Ui.ExpandedView.SetDrawFunc(func(s tcell.Screen, x, y, width, height int) (int, int, int, int) {
|
||||||
views.GetCurrentView().Update(globals.Ui.ExpandedView)
|
views.GetCurrentView().Update(ui.Ui.ExpandedView)
|
||||||
return globals.Ui.ExpandedView.GetInnerRect()
|
return ui.Ui.ExpandedView.GetInnerRect()
|
||||||
})
|
})
|
||||||
|
|
||||||
// Function Maps is used For Mapping Keys According to the Value mapped to the Key the respective Function is called
|
// Function Maps is used For Mapping Keys According to the Value mapped to the Key the respective Function is called
|
||||||
@ -127,7 +120,7 @@ func main() {
|
|||||||
},
|
},
|
||||||
"togglePlayBack": func() {
|
"togglePlayBack": func() {
|
||||||
if err := client.TogglePlayBack(); err != nil {
|
if err := client.TogglePlayBack(); err != nil {
|
||||||
globals.Notify.Send("Could not Toggle Play Back")
|
notify.Notify.Send("Could not Toggle Play Back")
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"showParentContent": func() {
|
"showParentContent": func() {
|
||||||
@ -135,19 +128,19 @@ func main() {
|
|||||||
},
|
},
|
||||||
"nextSong": func() {
|
"nextSong": func() {
|
||||||
if err := CONN.Next(); err != nil {
|
if err := CONN.Next(); err != nil {
|
||||||
globals.Notify.Send("Could not Select the Next Song")
|
notify.Notify.Send("Could not Select the Next Song")
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"clearPlaylist": func() {
|
"clearPlaylist": func() {
|
||||||
if err := CONN.Clear(); err != nil {
|
if err := CONN.Clear(); err != nil {
|
||||||
globals.Notify.Send("Could not Clear the Playlist")
|
notify.Notify.Send("Could not Clear the Playlist")
|
||||||
} else {
|
} else {
|
||||||
globals.Notify.Send("Playlist Cleared")
|
notify.Notify.Send("Playlist Cleared")
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"previousSong": func() {
|
"previousSong": func() {
|
||||||
if err := CONN.Previous(); err != nil {
|
if err := CONN.Previous(); err != nil {
|
||||||
globals.Notify.Send("Could Not Select the Previous Song")
|
notify.Notify.Send("Could Not Select the Previous Song")
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"addToPlaylist": func() {
|
"addToPlaylist": func() {
|
||||||
@ -170,7 +163,7 @@ func main() {
|
|||||||
Volume -= 10
|
Volume -= 10
|
||||||
}
|
}
|
||||||
if err := CONN.SetVolume(int(Volume)); err != nil {
|
if err := CONN.SetVolume(int(Volume)); err != nil {
|
||||||
globals.Notify.Send("Could Not Decrease the Volume")
|
notify.Notify.Send("Could Not Decrease the Volume")
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"increaseVolume": func() {
|
"increaseVolume": func() {
|
||||||
@ -180,50 +173,50 @@ func main() {
|
|||||||
Volume += 10
|
Volume += 10
|
||||||
}
|
}
|
||||||
if err := CONN.SetVolume(int(Volume)); err != nil {
|
if err := CONN.SetVolume(int(Volume)); err != nil {
|
||||||
globals.Notify.Send("Could Not Increase the Volume")
|
notify.Notify.Send("Could Not Increase the Volume")
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"navigateToFiles": func() {
|
"navigateToFiles": func() {
|
||||||
views.SetCurrentView(views.FView)
|
views.SetCurrentView(views.FView)
|
||||||
globals.Ui.Navbar.Select(1, 0)
|
ui.Ui.Navbar.Select(1, 0)
|
||||||
views.FView.Update(globals.Ui.ExpandedView)
|
views.FView.Update(ui.Ui.ExpandedView)
|
||||||
},
|
},
|
||||||
"navigateToPlaylist": func() {
|
"navigateToPlaylist": func() {
|
||||||
views.SetCurrentView(views.PView)
|
views.SetCurrentView(views.PView)
|
||||||
globals.Ui.Navbar.Select(0, 0)
|
ui.Ui.Navbar.Select(0, 0)
|
||||||
views.PView.Update(globals.Ui.ExpandedView)
|
views.PView.Update(ui.Ui.ExpandedView)
|
||||||
},
|
},
|
||||||
"navigateToMostPlayed": func() {
|
"navigateToMostPlayed": func() {
|
||||||
globals.Ui.Navbar.Select(2, 0)
|
ui.Ui.Navbar.Select(2, 0)
|
||||||
},
|
},
|
||||||
"navigateToSearch": func() {
|
"navigateToSearch": func() {
|
||||||
views.SetCurrentView(views.SView)
|
views.SetCurrentView(views.SView)
|
||||||
globals.Ui.Navbar.Select(3, 0)
|
ui.Ui.Navbar.Select(3, 0)
|
||||||
views.SView.Update(globals.Ui.ExpandedView)
|
views.SView.Update(ui.Ui.ExpandedView)
|
||||||
},
|
},
|
||||||
"quit": func() {
|
"quit": func() {
|
||||||
views.GetCurrentView().Quit()
|
views.GetCurrentView().Quit()
|
||||||
},
|
},
|
||||||
"stop": func() {
|
"stop": func() {
|
||||||
if err := CONN.Stop(); err != nil {
|
if err := CONN.Stop(); err != nil {
|
||||||
globals.Notify.Send("Could not Stop the Playback")
|
notify.Notify.Send("Could not Stop the Playback")
|
||||||
} else {
|
} else {
|
||||||
globals.Notify.Send("Playback Stopped")
|
notify.Notify.Send("Playback Stopped")
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"updateDB": func() {
|
"updateDB": func() {
|
||||||
_, err = CONN.Update("")
|
_, err = CONN.Update("")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
globals.Notify.Send("Could Not Update the Database")
|
notify.Notify.Send("Could Not Update the Database")
|
||||||
} else {
|
} else {
|
||||||
globals.Notify.Send("Database Updated")
|
notify.Notify.Send("Database Updated")
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"deleteSongFromPlaylist": func() {
|
"deleteSongFromPlaylist": func() {
|
||||||
views.GetCurrentView().DeleteSongFromPlaylist()
|
views.GetCurrentView().DeleteSongFromPlaylist()
|
||||||
},
|
},
|
||||||
"FocusSearch": func() {
|
"FocusSearch": func() {
|
||||||
globals.Ui.App.SetFocus(globals.Ui.SearchBar)
|
ui.Ui.App.SetFocus(ui.Ui.SearchBar)
|
||||||
},
|
},
|
||||||
"FocusBuffSearch": func() {
|
"FocusBuffSearch": func() {
|
||||||
views.GetCurrentView().FocusBuffSearchView()
|
views.GetCurrentView().FocusBuffSearchView()
|
||||||
@ -235,12 +228,12 @@ func main() {
|
|||||||
// for each event T, P, SPACE mapped to the same function togglePlayBack
|
// for each event T, P, SPACE mapped to the same function togglePlayBack
|
||||||
config.GenerateKeyMap(FuncMap)
|
config.GenerateKeyMap(FuncMap)
|
||||||
|
|
||||||
globals.Ui.SearchBar.SetAutocompleteFunc(func(c string) []string {
|
ui.Ui.SearchBar.SetAutocompleteFunc(func(c string) []string {
|
||||||
if views.GetCurrentView().GetViewName() == "BuffSearchView" {
|
if views.GetCurrentView().GetViewName() == "BuffSearchView" {
|
||||||
return nil
|
return nil
|
||||||
} else {
|
} else {
|
||||||
if c != "" && c != " " && c != " " {
|
if c != "" && c != " " && c != " " {
|
||||||
_, _, w, _ := globals.Ui.SearchBar.GetRect()
|
_, _, w, _ := ui.Ui.SearchBar.GetRect()
|
||||||
matches := fuzzy.Find(c, ArtistTreeContent)
|
matches := fuzzy.Find(c, ArtistTreeContent)
|
||||||
var suggestions []string
|
var suggestions []string
|
||||||
for i, match := range matches {
|
for i, match := range matches {
|
||||||
@ -257,7 +250,7 @@ func main() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Input Handler
|
// Input Handler
|
||||||
globals.Ui.ExpandedView.SetInputCapture(func(e *tcell.EventKey) *tcell.EventKey {
|
ui.Ui.ExpandedView.SetInputCapture(func(e *tcell.EventKey) *tcell.EventKey {
|
||||||
if val, ok := config.KEY_MAP[int(e.Rune())]; ok {
|
if val, ok := config.KEY_MAP[int(e.Rune())]; ok {
|
||||||
FuncMap[val]()
|
FuncMap[val]()
|
||||||
return nil
|
return nil
|
||||||
@ -265,18 +258,18 @@ func main() {
|
|||||||
if views.GetCurrentView().GetViewName() == "PlaylistView" {
|
if views.GetCurrentView().GetViewName() == "PlaylistView" {
|
||||||
if e.Rune() == 'j' || e.Rune() == 'k' {
|
if e.Rune() == 'j' || e.Rune() == 'k' {
|
||||||
if p, err := CONN.PlaylistInfo(-1, -1); err != nil {
|
if p, err := CONN.PlaylistInfo(-1, -1); err != nil {
|
||||||
globals.Notify.Send("Error Getting PlaylistInfo")
|
notify.Notify.Send("Error Getting PlaylistInfo")
|
||||||
} else {
|
} else {
|
||||||
if len(p) == 0 {
|
if len(p) == 0 {
|
||||||
globals.Notify.Send("Empty Playlist")
|
notify.Notify.Send("Empty Playlist")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if views.GetCurrentView().GetViewName() == "SearchView" {
|
} else if views.GetCurrentView().GetViewName() == "SearchView" {
|
||||||
if e.Rune() == 'j' || e.Rune() == 'k' {
|
if e.Rune() == 'j' || e.Rune() == 'k' {
|
||||||
if globals.SearchContentSlice == nil || len(globals.SearchContentSlice) == 0 {
|
if client.SearchContentSlice == nil || len(client.SearchContentSlice) == 0 {
|
||||||
globals.Notify.Send("No Search Results")
|
notify.Notify.Send("No Search Results")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -285,21 +278,21 @@ func main() {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
globals.Ui.SearchBar.SetDoneFunc(func(e tcell.Key) {
|
ui.Ui.SearchBar.SetDoneFunc(func(e tcell.Key) {
|
||||||
if e == tcell.KeyEnter {
|
if e == tcell.KeyEnter {
|
||||||
globals.Ui.ExpandedView.Select(0, 0)
|
ui.Ui.ExpandedView.Select(0, 0)
|
||||||
if views.GetCurrentView().GetViewName() == "BuffSearchView" {
|
if views.GetCurrentView().GetViewName() == "BuffSearchView" {
|
||||||
globals.Ui.App.SetFocus(globals.Ui.ExpandedView)
|
ui.Ui.App.SetFocus(ui.Ui.ExpandedView)
|
||||||
} else {
|
} else {
|
||||||
views.SetCurrentView(views.SView)
|
views.SetCurrentView(views.SView)
|
||||||
globals.SearchContentSlice = nil
|
client.SearchContentSlice = nil
|
||||||
globals.SearchContentSlice, err = client.GenerateContentSlice(globals.Ui.SearchBar.GetText())
|
client.SearchContentSlice, err = client.GenerateContentSlice(ui.Ui.SearchBar.GetText())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
globals.Notify.Send("Could Not Retrieve the Results")
|
notify.Notify.Send("Could Not Retrieve the Results")
|
||||||
} else {
|
} else {
|
||||||
globals.Ui.SearchBar.SetText("")
|
ui.Ui.SearchBar.SetText("")
|
||||||
globals.Ui.App.SetFocus(globals.Ui.ExpandedView)
|
ui.Ui.App.SetFocus(ui.Ui.ExpandedView)
|
||||||
globals.Ui.Navbar.Select(3, 0)
|
ui.Ui.Navbar.Select(3, 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -307,39 +300,39 @@ func main() {
|
|||||||
if views.GetCurrentView().GetViewName() == "SearchView" {
|
if views.GetCurrentView().GetViewName() == "SearchView" {
|
||||||
} else if views.GetCurrentView().GetViewName() == "BuffSearchView" {
|
} else if views.GetCurrentView().GetViewName() == "BuffSearchView" {
|
||||||
views.SetCurrentView(views.FView)
|
views.SetCurrentView(views.FView)
|
||||||
globals.Matches = nil
|
client.Matches = nil
|
||||||
}
|
}
|
||||||
globals.Ui.SearchBar.SetText("")
|
ui.Ui.SearchBar.SetText("")
|
||||||
globals.Ui.App.SetFocus(globals.Ui.ExpandedView)
|
ui.Ui.App.SetFocus(ui.Ui.ExpandedView)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
globals.Ui.ExpandedView.SetDoneFunc(func(e tcell.Key) {
|
ui.Ui.ExpandedView.SetDoneFunc(func(e tcell.Key) {
|
||||||
if e == tcell.KeyEscape {
|
if e == tcell.KeyEscape {
|
||||||
if views.GetCurrentView().GetViewName() == "BuffSearchView" {
|
if views.GetCurrentView().GetViewName() == "BuffSearchView" {
|
||||||
views.SetCurrentView(views.FView)
|
views.SetCurrentView(views.FView)
|
||||||
globals.Ui.SearchBar.SetText("")
|
ui.Ui.SearchBar.SetText("")
|
||||||
globals.Matches = nil
|
client.Matches = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
globals.Ui.SearchBar.SetChangedFunc(func(text string) {
|
ui.Ui.SearchBar.SetChangedFunc(func(text string) {
|
||||||
if views.GetCurrentView().GetViewName() == "BuffSearchView" {
|
if views.GetCurrentView().GetViewName() == "BuffSearchView" {
|
||||||
var f client.FileNodes = globals.DirTree.Children
|
var f client.FileNodes = client.DirTree.Children
|
||||||
globals.Matches = fuzzy.FindFrom(text, f)
|
client.Matches = fuzzy.FindFrom(text, f)
|
||||||
views.BuffSView.Update(globals.Ui.ExpandedView)
|
views.BuffSView.Update(ui.Ui.ExpandedView)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
globals.Ui.App.Draw()
|
ui.Ui.App.Draw()
|
||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if err := globals.Ui.App.Run(); err != nil {
|
if err := ui.Ui.App.Run(); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,18 +13,19 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
UI *ui.Application
|
UI *ui.Application
|
||||||
|
Notify *NotificationServer
|
||||||
)
|
)
|
||||||
|
|
||||||
func ConnectUI(a *ui.Application) {
|
|
||||||
UI = a
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Notification Primitive */
|
/* Notification Primitive */
|
||||||
type Notification struct {
|
type Notification struct {
|
||||||
*tview.Box
|
*tview.Box
|
||||||
Text string
|
Text string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ConnectUI(a *ui.Application) {
|
||||||
|
UI = a
|
||||||
|
}
|
||||||
|
|
||||||
/* Get A Pointer to A Notification Struct */
|
/* Get A Pointer to A Notification Struct */
|
||||||
func NewNotification(s string) *Notification {
|
func NewNotification(s string) *Notification {
|
||||||
return &Notification{
|
return &Notification{
|
||||||
|
@ -4,8 +4,9 @@ import (
|
|||||||
"image"
|
"image"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"github.com/aditya-K2/gomp/client"
|
||||||
|
"github.com/aditya-K2/gomp/notify"
|
||||||
"github.com/aditya-K2/gomp/ui"
|
"github.com/aditya-K2/gomp/ui"
|
||||||
"github.com/fhs/gompd/mpd"
|
|
||||||
|
|
||||||
"github.com/aditya-K2/gomp/cache"
|
"github.com/aditya-K2/gomp/cache"
|
||||||
"github.com/aditya-K2/gomp/utils"
|
"github.com/aditya-K2/gomp/utils"
|
||||||
@ -15,18 +16,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
CONN *mpd.Client
|
Rendr *Renderer
|
||||||
Notify interface{ Send(string) }
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func SetConnection(c *mpd.Client) {
|
|
||||||
CONN = c
|
|
||||||
}
|
|
||||||
|
|
||||||
func SetNotificationServer(n interface{ Send(string) }) {
|
|
||||||
Notify = n
|
|
||||||
}
|
|
||||||
|
|
||||||
// Renderer is just a channel on which we will send the Path to the song whose
|
// Renderer is just a channel on which we will send the Path to the song whose
|
||||||
// Image is to be Rendered. This channel is passed to the OpenImage which in turn is called
|
// Image is to be Rendered. This channel is passed to the OpenImage which in turn is called
|
||||||
// by the Start() function as a go routine.
|
// by the Start() function as a go routine.
|
||||||
@ -82,7 +74,7 @@ func (r *Renderer) Start(path string) {
|
|||||||
// rendered it checks first for the image in the cache
|
// rendered it checks first for the image in the cache
|
||||||
// else it adds the image to the cache and then extracts it and renders it.
|
// else it adds the image to the cache and then extracts it and renders it.
|
||||||
func GetImagePath(path string) string {
|
func GetImagePath(path string) string {
|
||||||
a, err := CONN.ListInfo(path)
|
a, err := client.Conn.ListInfo(path)
|
||||||
var extractedImage string
|
var extractedImage string
|
||||||
if err == nil && len(a) != 0 {
|
if err == nil && len(a) != 0 {
|
||||||
if cache.Exists(a[0]["artist"], a[0]["album"]) {
|
if cache.Exists(a[0]["artist"], a[0]["album"]) {
|
||||||
@ -95,13 +87,13 @@ func GetImagePath(path string) string {
|
|||||||
viper.GetString("GET_COVER_ART_FROM_LAST_FM") == "TRUE" {
|
viper.GetString("GET_COVER_ART_FROM_LAST_FM") == "TRUE" {
|
||||||
downloadedImage, err := getImageFromLastFM(a[0]["artist"], a[0]["album"], imagePath)
|
downloadedImage, err := getImageFromLastFM(a[0]["artist"], a[0]["album"], imagePath)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
Notify.Send("Image From LastFM")
|
notify.Notify.Send("Image From LastFM")
|
||||||
extractedImage = downloadedImage
|
extractedImage = downloadedImage
|
||||||
} else {
|
} else {
|
||||||
Notify.Send("Falling Back to Default Image.")
|
notify.Notify.Send("Falling Back to Default Image.")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Notify.Send("Extracted Image Successfully")
|
notify.Notify.Send("Extracted Image Successfully")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ var (
|
|||||||
ImgW int
|
ImgW int
|
||||||
ImgH int
|
ImgH int
|
||||||
ImgX int
|
ImgX int
|
||||||
|
Ui *Application
|
||||||
)
|
)
|
||||||
|
|
||||||
type Application struct {
|
type Application struct {
|
||||||
|
@ -3,7 +3,9 @@ package views
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/aditya-K2/gomp/globals"
|
"github.com/aditya-K2/gomp/client"
|
||||||
|
"github.com/aditya-K2/gomp/notify"
|
||||||
|
"github.com/aditya-K2/gomp/ui"
|
||||||
"github.com/aditya-K2/gomp/utils"
|
"github.com/aditya-K2/gomp/utils"
|
||||||
"github.com/aditya-K2/tview"
|
"github.com/aditya-K2/tview"
|
||||||
"github.com/gdamore/tcell/v2"
|
"github.com/gdamore/tcell/v2"
|
||||||
@ -17,57 +19,57 @@ func (s BuffSearchView) GetViewName() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s BuffSearchView) ShowChildrenContent() {
|
func (s BuffSearchView) ShowChildrenContent() {
|
||||||
UI := globals.Ui
|
UI := ui.Ui
|
||||||
CONN := globals.Conn
|
CONN := client.Conn
|
||||||
r, _ := UI.ExpandedView.GetSelection()
|
r, _ := UI.ExpandedView.GetSelection()
|
||||||
SetCurrentView(FView)
|
SetCurrentView(FView)
|
||||||
if len(globals.DirTree.Children[r].Children) == 0 {
|
if len(client.DirTree.Children[r].Children) == 0 {
|
||||||
if id, err := CONN.AddId(globals.DirTree.Children[globals.Matches[r].Index].AbsolutePath, -1); err != nil {
|
if id, err := CONN.AddId(client.DirTree.Children[client.Matches[r].Index].AbsolutePath, -1); err != nil {
|
||||||
globals.Notify.Send(fmt.Sprintf("Could Not add the Song %s to the Playlist",
|
notify.Notify.Send(fmt.Sprintf("Could Not add the Song %s to the Playlist",
|
||||||
globals.DirTree.Children[globals.Matches[r].Index].AbsolutePath))
|
client.DirTree.Children[client.Matches[r].Index].AbsolutePath))
|
||||||
} else {
|
} else {
|
||||||
if err := CONN.PlayId(id); err != nil {
|
if err := CONN.PlayId(id); err != nil {
|
||||||
globals.Notify.Send("Could not Play the Song")
|
notify.Notify.Send("Could not Play the Song")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
globals.DirTree = &globals.DirTree.Children[globals.Matches[r].Index]
|
client.DirTree = &client.DirTree.Children[client.Matches[r].Index]
|
||||||
FView.Update(UI.ExpandedView)
|
FView.Update(UI.ExpandedView)
|
||||||
}
|
}
|
||||||
UI.SearchBar.SetText("")
|
UI.SearchBar.SetText("")
|
||||||
// Resetting globals.Matches
|
// Resetting client.Matches
|
||||||
globals.Matches = nil
|
client.Matches = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s BuffSearchView) ShowParentContent() {
|
func (s BuffSearchView) ShowParentContent() {
|
||||||
globals.Notify.Send("Not Allowed in this View")
|
notify.Notify.Send("Not Allowed in this View")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s BuffSearchView) AddToPlaylist() {
|
func (s BuffSearchView) AddToPlaylist() {
|
||||||
UI := globals.Ui
|
UI := ui.Ui
|
||||||
CONN := globals.Conn
|
CONN := client.Conn
|
||||||
r, _ := UI.ExpandedView.GetSelection()
|
r, _ := UI.ExpandedView.GetSelection()
|
||||||
if err := CONN.Add(globals.DirTree.Children[globals.Matches[r].Index].AbsolutePath); err != nil {
|
if err := CONN.Add(client.DirTree.Children[client.Matches[r].Index].AbsolutePath); err != nil {
|
||||||
globals.Notify.Send(fmt.Sprintf("Could Not Add URI %s to the Playlist",
|
notify.Notify.Send(fmt.Sprintf("Could Not Add URI %s to the Playlist",
|
||||||
globals.DirTree.Children[globals.Matches[r].Index].Path))
|
client.DirTree.Children[client.Matches[r].Index].Path))
|
||||||
} else {
|
} else {
|
||||||
SetCurrentView(FView)
|
SetCurrentView(FView)
|
||||||
globals.Notify.Send(fmt.Sprintf("URI Added %s to the Playlist",
|
notify.Notify.Send(fmt.Sprintf("URI Added %s to the Playlist",
|
||||||
globals.DirTree.Children[globals.Matches[r].Index].Path))
|
client.DirTree.Children[client.Matches[r].Index].Path))
|
||||||
SetCurrentView(BuffSView)
|
SetCurrentView(BuffSView)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s BuffSearchView) Quit() {
|
func (s BuffSearchView) Quit() {
|
||||||
UI := globals.Ui
|
UI := ui.Ui
|
||||||
SetCurrentView(FView)
|
SetCurrentView(FView)
|
||||||
UI.SearchBar.SetText("")
|
UI.SearchBar.SetText("")
|
||||||
globals.Matches = nil
|
client.Matches = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f BuffSearchView) FocusBuffSearchView() {
|
func (f BuffSearchView) FocusBuffSearchView() {
|
||||||
UI := globals.Ui
|
UI := ui.Ui
|
||||||
SetCurrentView(BuffSView)
|
SetCurrentView(BuffSView)
|
||||||
UI.App.SetFocus(UI.SearchBar)
|
UI.App.SetFocus(UI.SearchBar)
|
||||||
}
|
}
|
||||||
@ -75,8 +77,8 @@ func (f BuffSearchView) FocusBuffSearchView() {
|
|||||||
func (f BuffSearchView) DeleteSongFromPlaylist() {}
|
func (f BuffSearchView) DeleteSongFromPlaylist() {}
|
||||||
|
|
||||||
func (s BuffSearchView) Update(inputTable *tview.Table) {
|
func (s BuffSearchView) Update(inputTable *tview.Table) {
|
||||||
m := globals.Matches
|
m := client.Matches
|
||||||
f := globals.DirTree.Children
|
f := client.DirTree.Children
|
||||||
inputTable.Clear()
|
inputTable.Clear()
|
||||||
if m == nil || len(m) == 0 {
|
if m == nil || len(m) == 0 {
|
||||||
FView.Update(inputTable)
|
FView.Update(inputTable)
|
||||||
|
@ -3,7 +3,9 @@ package views
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/aditya-K2/gomp/globals"
|
"github.com/aditya-K2/gomp/client"
|
||||||
|
"github.com/aditya-K2/gomp/notify"
|
||||||
|
"github.com/aditya-K2/gomp/ui"
|
||||||
"github.com/aditya-K2/gomp/utils"
|
"github.com/aditya-K2/gomp/utils"
|
||||||
"github.com/aditya-K2/tview"
|
"github.com/aditya-K2/tview"
|
||||||
"github.com/gdamore/tcell/v2"
|
"github.com/gdamore/tcell/v2"
|
||||||
@ -17,51 +19,51 @@ func (f FileView) GetViewName() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f FileView) ShowChildrenContent() {
|
func (f FileView) ShowChildrenContent() {
|
||||||
UI := globals.Ui
|
UI := ui.Ui
|
||||||
CONN := globals.Conn
|
CONN := client.Conn
|
||||||
r, _ := UI.ExpandedView.GetSelection()
|
r, _ := UI.ExpandedView.GetSelection()
|
||||||
SetCurrentView(FView)
|
SetCurrentView(FView)
|
||||||
if len(globals.DirTree.Children[r].Children) == 0 {
|
if len(client.DirTree.Children[r].Children) == 0 {
|
||||||
if id, err := CONN.AddId(globals.DirTree.Children[r].AbsolutePath, -1); err != nil {
|
if id, err := CONN.AddId(client.DirTree.Children[r].AbsolutePath, -1); err != nil {
|
||||||
globals.Notify.Send(fmt.Sprintf("Could not Add Song %s",
|
notify.Notify.Send(fmt.Sprintf("Could not Add Song %s",
|
||||||
globals.DirTree.Children[r].Path))
|
client.DirTree.Children[r].Path))
|
||||||
} else {
|
} else {
|
||||||
if err := CONN.PlayId(id); err != nil {
|
if err := CONN.PlayId(id); err != nil {
|
||||||
globals.Notify.Send(fmt.Sprintf("Could Not Play Song %s",
|
notify.Notify.Send(fmt.Sprintf("Could Not Play Song %s",
|
||||||
globals.DirTree.Children[r].Path))
|
client.DirTree.Children[r].Path))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
globals.DirTree = &globals.DirTree.Children[r]
|
client.DirTree = &client.DirTree.Children[r]
|
||||||
FView.Update(UI.ExpandedView)
|
FView.Update(UI.ExpandedView)
|
||||||
UI.ExpandedView.Select(0, 0)
|
UI.ExpandedView.Select(0, 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f FileView) ShowParentContent() {
|
func (f FileView) ShowParentContent() {
|
||||||
UI := globals.Ui
|
UI := ui.Ui
|
||||||
if globals.DirTree.Parent != nil {
|
if client.DirTree.Parent != nil {
|
||||||
globals.DirTree = globals.DirTree.Parent
|
client.DirTree = client.DirTree.Parent
|
||||||
FView.Update(UI.ExpandedView)
|
FView.Update(UI.ExpandedView)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f FileView) AddToPlaylist() {
|
func (f FileView) AddToPlaylist() {
|
||||||
UI := globals.Ui
|
UI := ui.Ui
|
||||||
CONN := globals.Conn
|
CONN := client.Conn
|
||||||
r, _ := UI.ExpandedView.GetSelection()
|
r, _ := UI.ExpandedView.GetSelection()
|
||||||
if err := CONN.Add(globals.DirTree.Children[r].AbsolutePath); err != nil {
|
if err := CONN.Add(client.DirTree.Children[r].AbsolutePath); err != nil {
|
||||||
globals.Notify.Send(fmt.Sprintf("Could not add %s to the Playlist",
|
notify.Notify.Send(fmt.Sprintf("Could not add %s to the Playlist",
|
||||||
globals.DirTree.Children[r].Path))
|
client.DirTree.Children[r].Path))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f FileView) Quit() {
|
func (f FileView) Quit() {
|
||||||
globals.Ui.App.Stop()
|
ui.Ui.App.Stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f FileView) FocusBuffSearchView() {
|
func (f FileView) FocusBuffSearchView() {
|
||||||
UI := globals.Ui
|
UI := ui.Ui
|
||||||
SetCurrentView(BuffSView)
|
SetCurrentView(BuffSView)
|
||||||
UI.App.SetFocus(UI.SearchBar)
|
UI.App.SetFocus(UI.SearchBar)
|
||||||
}
|
}
|
||||||
@ -70,9 +72,9 @@ func (f FileView) DeleteSongFromPlaylist() {}
|
|||||||
|
|
||||||
func (f FileView) Update(inputTable *tview.Table) {
|
func (f FileView) Update(inputTable *tview.Table) {
|
||||||
inputTable.Clear()
|
inputTable.Clear()
|
||||||
for i, j := range globals.DirTree.Children {
|
for i, j := range client.DirTree.Children {
|
||||||
if len(j.Children) == 0 {
|
if len(j.Children) == 0 {
|
||||||
_songAttributes, err := globals.Conn.ListAllInfo(j.AbsolutePath)
|
_songAttributes, err := client.Conn.ListAllInfo(j.AbsolutePath)
|
||||||
if err == nil && _songAttributes[0]["Title"] != "" {
|
if err == nil && _songAttributes[0]["Title"] != "" {
|
||||||
_, _, w, _ := inputTable.GetInnerRect()
|
_, _, w, _ := inputTable.GetInnerRect()
|
||||||
inputTable.SetCell(i, 0,
|
inputTable.SetCell(i, 0,
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
package views
|
package views
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/aditya-K2/gomp/globals"
|
"github.com/aditya-K2/gomp/client"
|
||||||
|
"github.com/aditya-K2/gomp/notify"
|
||||||
|
"github.com/aditya-K2/gomp/ui"
|
||||||
"github.com/aditya-K2/gomp/utils"
|
"github.com/aditya-K2/gomp/utils"
|
||||||
"github.com/aditya-K2/tview"
|
"github.com/aditya-K2/tview"
|
||||||
"github.com/gdamore/tcell/v2"
|
"github.com/gdamore/tcell/v2"
|
||||||
@ -24,38 +26,38 @@ func GetCell(text string, foreground tcell.Color, bold bool) *tview.TableCell {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p PlaylistView) ShowChildrenContent() {
|
func (p PlaylistView) ShowChildrenContent() {
|
||||||
UI := globals.Ui
|
UI := ui.Ui
|
||||||
CONN := globals.Conn
|
CONN := client.Conn
|
||||||
r, _ := UI.ExpandedView.GetSelection()
|
r, _ := UI.ExpandedView.GetSelection()
|
||||||
if err := CONN.Play(r); err != nil {
|
if err := CONN.Play(r); err != nil {
|
||||||
globals.Notify.Send("Could Not Play the Song")
|
notify.Notify.Send("Could Not Play the Song")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s PlaylistView) ShowParentContent() {
|
func (s PlaylistView) ShowParentContent() {
|
||||||
globals.Notify.Send("Not Allowed in this View")
|
notify.Notify.Send("Not Allowed in this View")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
func (p PlaylistView) AddToPlaylist() {}
|
func (p PlaylistView) AddToPlaylist() {}
|
||||||
|
|
||||||
func (p PlaylistView) Quit() {
|
func (p PlaylistView) Quit() {
|
||||||
globals.Ui.App.Stop()
|
ui.Ui.App.Stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p PlaylistView) FocusBuffSearchView() {}
|
func (p PlaylistView) FocusBuffSearchView() {}
|
||||||
|
|
||||||
func (p PlaylistView) DeleteSongFromPlaylist() {
|
func (p PlaylistView) DeleteSongFromPlaylist() {
|
||||||
UI := globals.Ui
|
UI := ui.Ui
|
||||||
CONN := globals.Conn
|
CONN := client.Conn
|
||||||
r, _ := UI.ExpandedView.GetSelection()
|
r, _ := UI.ExpandedView.GetSelection()
|
||||||
if err := CONN.Delete(r, -1); err != nil {
|
if err := CONN.Delete(r, -1); err != nil {
|
||||||
globals.Notify.Send("Could not Remove the Song from Playlist")
|
notify.Notify.Send("Could not Remove the Song from Playlist")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p PlaylistView) Update(inputTable *tview.Table) {
|
func (p PlaylistView) Update(inputTable *tview.Table) {
|
||||||
CONN := globals.Conn
|
CONN := client.Conn
|
||||||
_playlistAttr, _ := CONN.PlaylistInfo(-1, -1)
|
_playlistAttr, _ := CONN.PlaylistInfo(-1, -1)
|
||||||
|
|
||||||
inputTable.Clear()
|
inputTable.Clear()
|
||||||
|
@ -4,7 +4,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/aditya-K2/gomp/client"
|
"github.com/aditya-K2/gomp/client"
|
||||||
"github.com/aditya-K2/gomp/globals"
|
"github.com/aditya-K2/gomp/notify"
|
||||||
|
"github.com/aditya-K2/gomp/ui"
|
||||||
"github.com/aditya-K2/gomp/utils"
|
"github.com/aditya-K2/gomp/utils"
|
||||||
"github.com/aditya-K2/tview"
|
"github.com/aditya-K2/tview"
|
||||||
"github.com/gdamore/tcell/v2"
|
"github.com/gdamore/tcell/v2"
|
||||||
@ -17,10 +18,10 @@ func (s SearchView) GetViewName() string {
|
|||||||
return "SearchView"
|
return "SearchView"
|
||||||
}
|
}
|
||||||
func (s SearchView) ShowChildrenContent() {
|
func (s SearchView) ShowChildrenContent() {
|
||||||
UI := globals.Ui
|
UI := ui.Ui
|
||||||
SearchContentSlice := globals.SearchContentSlice
|
SearchContentSlice := client.SearchContentSlice
|
||||||
if len(globals.SearchContentSlice) <= 0 || globals.SearchContentSlice == nil {
|
if len(client.SearchContentSlice) <= 0 || client.SearchContentSlice == nil {
|
||||||
globals.Notify.Send("No Search Results")
|
notify.Notify.Send("No Search Results")
|
||||||
} else {
|
} else {
|
||||||
r, _ := UI.ExpandedView.GetSelection()
|
r, _ := UI.ExpandedView.GetSelection()
|
||||||
client.AddToPlaylist(SearchContentSlice[r], true)
|
client.AddToPlaylist(SearchContentSlice[r], true)
|
||||||
@ -28,15 +29,15 @@ func (s SearchView) ShowChildrenContent() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s SearchView) ShowParentContent() {
|
func (s SearchView) ShowParentContent() {
|
||||||
globals.Notify.Send("Not Allowed in this View")
|
notify.Notify.Send("Not Allowed in this View")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SearchView) AddToPlaylist() {
|
func (s SearchView) AddToPlaylist() {
|
||||||
UI := globals.Ui
|
UI := ui.Ui
|
||||||
SearchContentSlice := globals.SearchContentSlice
|
SearchContentSlice := client.SearchContentSlice
|
||||||
if len(globals.SearchContentSlice) <= 0 || globals.SearchContentSlice == nil {
|
if len(client.SearchContentSlice) <= 0 || client.SearchContentSlice == nil {
|
||||||
globals.Notify.Send("No Search Results")
|
notify.Notify.Send("No Search Results")
|
||||||
} else {
|
} else {
|
||||||
r, _ := UI.ExpandedView.GetSelection()
|
r, _ := UI.ExpandedView.GetSelection()
|
||||||
client.AddToPlaylist(SearchContentSlice[r], false)
|
client.AddToPlaylist(SearchContentSlice[r], false)
|
||||||
@ -44,7 +45,7 @@ func (s SearchView) AddToPlaylist() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p SearchView) Quit() {
|
func (p SearchView) Quit() {
|
||||||
globals.Ui.App.Stop()
|
ui.Ui.App.Stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s SearchView) FocusBuffSearchView() {}
|
func (s SearchView) FocusBuffSearchView() {}
|
||||||
@ -52,7 +53,7 @@ func (s SearchView) DeleteSongFromPlaylist() {}
|
|||||||
|
|
||||||
func (s SearchView) Update(inputTable *tview.Table) {
|
func (s SearchView) Update(inputTable *tview.Table) {
|
||||||
inputTable.Clear()
|
inputTable.Clear()
|
||||||
c := globals.SearchContentSlice
|
c := client.SearchContentSlice
|
||||||
_, _, width, _ := inputTable.GetInnerRect()
|
_, _, width, _ := inputTable.GetInnerRect()
|
||||||
for i, content := range c {
|
for i, content := range c {
|
||||||
switch content.(type) {
|
switch content.(type) {
|
||||||
|
Loading…
Reference in New Issue
Block a user