Merge pull request #28 from aditya-K2/refactor
Seeking Functionality. Refactoring ProgressBar, FuncMap, and others
This commit is contained in:
commit
bc794b3743
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,3 +2,4 @@ gomp
|
||||
.idea
|
||||
*.jpg
|
||||
e.go
|
||||
.fuse*
|
||||
|
@ -4,34 +4,28 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/fhs/gompd/mpd"
|
||||
"github.com/aditya-K2/fuzzy"
|
||||
"github.com/aditya-K2/gomp/notify"
|
||||
"github.com/fhs/gompd/v2/mpd"
|
||||
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
CONN *mpd.Client
|
||||
Conn *mpd.Client
|
||||
ArtistTree map[string]map[string]map[string]string
|
||||
NotificationServer interface {
|
||||
Send(string)
|
||||
}
|
||||
WHITE_AND_BOLD string = "[white::b]"
|
||||
DirTree *FileNode
|
||||
Matches fuzzy.Matches
|
||||
SearchContentSlice []interface{}
|
||||
)
|
||||
|
||||
func SetConnection(c *mpd.Client) {
|
||||
CONN = c
|
||||
}
|
||||
|
||||
func SetNotificationServer(n interface{ Send(string) }) {
|
||||
NotificationServer = n
|
||||
}
|
||||
|
||||
func TogglePlayBack() error {
|
||||
status, err := CONN.Status()
|
||||
status, err := Conn.Status()
|
||||
if status["state"] == "play" && err == nil {
|
||||
CONN.Pause(true)
|
||||
Conn.Pause(true)
|
||||
} else if status["state"] == "pause" && err == nil {
|
||||
CONN.Play(-1)
|
||||
Conn.Play(-1)
|
||||
}
|
||||
return err
|
||||
}
|
||||
@ -42,7 +36,7 @@ func TogglePlayBack() error {
|
||||
func GenerateContentSlice(selectedSuggestion string) ([]interface{}, error) {
|
||||
var ContentSlice []interface{}
|
||||
if strings.TrimRight(selectedSuggestion, " ") == "" {
|
||||
NotificationServer.Send("Empty Search!")
|
||||
notify.Notify.Send("Empty Search!")
|
||||
return nil, errors.New("empty Search String Provided")
|
||||
}
|
||||
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.
|
||||
func GenerateArtistTree() (map[string]map[string]map[string]string, error) {
|
||||
ArtistTree = make(map[string]map[string]map[string]string)
|
||||
AllInfo, err := CONN.ListAllInfo("/")
|
||||
AllInfo, err := Conn.ListAllInfo("/")
|
||||
if err == nil {
|
||||
for _, i := range AllInfo {
|
||||
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
|
||||
func AddAlbum(a map[string]map[string]map[string]string, alb string, artist string) {
|
||||
for _, v := range a[artist][alb] {
|
||||
err := CONN.Add(v)
|
||||
err := Conn.Add(v)
|
||||
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
|
||||
@ -131,31 +125,31 @@ func AddArtist(a map[string]map[string]map[string]string, artist string) {
|
||||
if val, ok := a[artist]; ok {
|
||||
for _, v := range val {
|
||||
for _, path := range v {
|
||||
err := CONN.Add(path)
|
||||
err := Conn.Add(path)
|
||||
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
|
||||
func AddTitle(a map[string]map[string]map[string]string, artist, alb, track string, addAndPlay bool) {
|
||||
if addAndPlay {
|
||||
id, err := CONN.AddId(a[artist][alb][track], -1)
|
||||
CONN.PlayId(id)
|
||||
id, err := Conn.AddID(a[artist][alb][track], -1)
|
||||
Conn.PlayID(id)
|
||||
if err != nil {
|
||||
NotificationServer.Send("Could Not Add Track : " + track)
|
||||
notify.Notify.Send("Could Not Add Track : " + track)
|
||||
}
|
||||
} else {
|
||||
err := CONN.Add(a[artist][alb][track])
|
||||
err := Conn.Add(a[artist][alb][track])
|
||||
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
|
||||
|
@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/fhs/gompd/mpd"
|
||||
"github.com/fhs/gompd/v2/mpd"
|
||||
)
|
||||
|
||||
type FileNode struct {
|
||||
|
@ -1,140 +0,0 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/aditya-K2/fuzzy"
|
||||
"github.com/aditya-K2/gomp/utils"
|
||||
"github.com/aditya-K2/tview"
|
||||
"github.com/gdamore/tcell/v2"
|
||||
)
|
||||
|
||||
func GetCell(text string, foreground tcell.Color, bold bool) *tview.TableCell {
|
||||
return tview.NewTableCell(text).
|
||||
SetAlign(tview.AlignLeft).
|
||||
SetStyle(tcell.StyleDefault.
|
||||
Foreground(foreground).
|
||||
Background(tcell.ColorBlack).
|
||||
Bold(bold))
|
||||
}
|
||||
|
||||
func UpdateBuffSearchView(inputTable *tview.Table, m fuzzy.Matches, f []FileNode) {
|
||||
inputTable.Clear()
|
||||
if m == nil || len(m) == 0 {
|
||||
Update(f, inputTable)
|
||||
} else {
|
||||
for k, v := range m {
|
||||
if len(f[v.Index].Children) != 0 {
|
||||
inputTable.SetCell(k, 0,
|
||||
GetCell(
|
||||
utils.GetMatchedString(
|
||||
utils.Unique(v.MatchedIndexes), f[v.Index].Path, "[blue:-:bi]"),
|
||||
tcell.ColorYellow, true))
|
||||
} else {
|
||||
inputTable.SetCell(k, 0,
|
||||
GetCell(
|
||||
utils.GetMatchedString(
|
||||
utils.Unique(v.MatchedIndexes), f[v.Index].Title, "[yellow:-:bi]"),
|
||||
tcell.ColorGreen, true))
|
||||
}
|
||||
if k == 15 {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func UpdatePlaylist(inputTable *tview.Table) {
|
||||
_playlistAttr, _ := CONN.PlaylistInfo(-1, -1)
|
||||
|
||||
inputTable.Clear()
|
||||
for i, j := range _playlistAttr {
|
||||
_, _, w, _ := inputTable.GetInnerRect()
|
||||
if j["Title"] == "" || j["Artist"] == "" || j["Album"] == "" {
|
||||
inputTable.SetCell(i, 0,
|
||||
GetCell(
|
||||
utils.GetFormattedString(j["file"], w/3), tcell.ColorBlue, true))
|
||||
|
||||
} else {
|
||||
inputTable.SetCell(i, 0,
|
||||
GetCell(
|
||||
utils.GetFormattedString(j["Title"], w/3), tcell.ColorGreen, false))
|
||||
inputTable.SetCell(i, 1,
|
||||
GetCell(
|
||||
utils.GetFormattedString(j["Artist"], w/3), tcell.ColorPurple, false))
|
||||
inputTable.SetCell(i, 2,
|
||||
GetCell(j["Album"], tcell.ColorYellow, false))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// UpdateSearchView as the name suggests Updates the Search View the idea is to basically keep a fourth option called
|
||||
// Search in the Navigation bar which will render things from a global ContentSlice at least in the context of the main
|
||||
// function this will also help in persisting the Search Results.
|
||||
func UpdateSearchView(inputTable *tview.Table, c []interface{}) {
|
||||
inputTable.Clear()
|
||||
_, _, width, _ := inputTable.GetInnerRect()
|
||||
for i, content := range c {
|
||||
switch content.(type) {
|
||||
case [3]string:
|
||||
{
|
||||
inputTable.SetCell(i, 0,
|
||||
GetCell(
|
||||
utils.GetFormattedString(content.([3]string)[0], width/3), tcell.ColorGreen, false))
|
||||
inputTable.SetCell(i, 1,
|
||||
GetCell(
|
||||
utils.GetFormattedString(content.([3]string)[1], width/3), tcell.ColorPurple, false))
|
||||
inputTable.SetCell(i, 2,
|
||||
GetCell(content.([3]string)[2], tcell.ColorYellow, false))
|
||||
}
|
||||
case [2]string:
|
||||
{
|
||||
inputTable.SetCell(i, 0,
|
||||
GetCell(
|
||||
utils.GetFormattedString(content.([2]string)[0], width/3), tcell.ColorYellow, false))
|
||||
inputTable.SetCell(i, 1,
|
||||
GetCell(
|
||||
utils.GetFormattedString(content.([2]string)[1], width/3), tcell.ColorPurple, false))
|
||||
}
|
||||
case string:
|
||||
{
|
||||
b := content.(string)
|
||||
if !strings.HasPrefix(b, WHITE_AND_BOLD) {
|
||||
inputTable.SetCell(i, 0,
|
||||
GetCell(content.(string), tcell.ColorPurple, false))
|
||||
} else {
|
||||
inputTable.SetCell(i, 0,
|
||||
GetCell(content.(string), tcell.ColorWhite, true).SetSelectable(false))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func Update(f []FileNode, inputTable *tview.Table) {
|
||||
inputTable.Clear()
|
||||
for i, j := range f {
|
||||
if len(j.Children) == 0 {
|
||||
_songAttributes, err := CONN.ListAllInfo(j.AbsolutePath)
|
||||
if err == nil && _songAttributes[0]["Title"] != "" {
|
||||
_, _, w, _ := inputTable.GetInnerRect()
|
||||
inputTable.SetCell(i, 0,
|
||||
GetCell(
|
||||
utils.GetFormattedString(_songAttributes[0]["Title"], w/3), tcell.ColorGreen, false))
|
||||
|
||||
inputTable.SetCell(i, 1,
|
||||
GetCell(
|
||||
utils.GetFormattedString(_songAttributes[0]["Artist"], w/3), tcell.ColorPurple, false))
|
||||
inputTable.SetCell(i, 2,
|
||||
GetCell(_songAttributes[0]["Album"], tcell.ColorYellow, false))
|
||||
|
||||
} else if _songAttributes[0]["Title"] == "" {
|
||||
inputTable.SetCell(i, 0,
|
||||
GetCell(j.Path, tcell.ColorBlue, true))
|
||||
}
|
||||
} else {
|
||||
inputTable.SetCell(i, 0,
|
||||
GetCell(j.Path, tcell.ColorYellow, true))
|
||||
}
|
||||
}
|
||||
}
|
@ -24,6 +24,7 @@ var (
|
||||
"PORT": "6600",
|
||||
"DEFAULT_IMAGE_PATH": "default.jpg",
|
||||
"CACHE_DIR": utils.CheckDirectoryFmt(USER_CACHE_DIR),
|
||||
"SEEK_OFFSET": 1,
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -50,6 +50,8 @@ var (
|
||||
100: "deleteSongFromPlaylist",
|
||||
63: "FocusSearch",
|
||||
47: "FocusBuffSearch",
|
||||
98: "SeekBackward",
|
||||
102: "SeekForward",
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -68,6 +68,13 @@ This is the Fallback Image that will be rendered if gomp doesn't find the embedd
|
||||
```yml
|
||||
DEFAULT_IMAGE_PATH : "/path/to/default/image"
|
||||
```
|
||||
## Seek Offset
|
||||
|
||||
The amount of seconds by which the current song should seek forward or backward.
|
||||
|
||||
```yml
|
||||
SEEK_OFFSET : 5
|
||||
```
|
||||
|
||||
## Additional Padding and Extra Image Width
|
||||
|
||||
@ -187,6 +194,8 @@ Following functions are provided :
|
||||
| deleteSongFromPlaylist | <kbd>d</kbd> |
|
||||
| FocusSearch | <kbd>?</kbd> |
|
||||
| FocusBuffSearch | <kbd>/</kbd> |
|
||||
| SeekForward | <kbd>f</kbd> |
|
||||
| SeekBackward | <kbd>b</kbd> |
|
||||
|
||||
## Getting Album Art from [LastFm API](https://www.last.fm/api)
|
||||
|
||||
|
2
go.mod
2
go.mod
@ -6,7 +6,7 @@ require (
|
||||
github.com/aditya-K2/fuzzy v0.1.1-0.20211128173834-d0023b66cdd4
|
||||
github.com/aditya-K2/tview v0.0.0-20211115161300-6b99c2c2658c
|
||||
github.com/bogem/id3v2 v1.2.0
|
||||
github.com/fhs/gompd v1.0.1
|
||||
github.com/fhs/gompd/v2 v2.2.0
|
||||
github.com/gdamore/tcell/v2 v2.4.1-0.20210905002822-f057f0a857a1
|
||||
github.com/mewkiz/flac v1.0.7
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
|
||||
|
4
go.sum
4
go.sum
@ -90,8 +90,8 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.m
|
||||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
||||
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
|
||||
github.com/fhs/gompd v1.0.1 h1:kBcAhjnAPJQAylZXR0TeH+d2vpjawXlTtKYguqNlF4A=
|
||||
github.com/fhs/gompd v1.0.1/go.mod h1:b219/mNa9PvRqvkUip51b23hGL3iX4d4q3gNXdtrD04=
|
||||
github.com/fhs/gompd/v2 v2.2.0 h1:zdSYAAOzQ5cCCgYa5CoXkL0Vr0Cqb/b5JmTobirLc90=
|
||||
github.com/fhs/gompd/v2 v2.2.0/go.mod h1:nNdZtcpD5VpmzZbRl5rV6RhxeMmAWTxEsSIMBkmMIy4=
|
||||
github.com/fsnotify/fsnotify v1.5.1 h1:mZcQUHVQUQWoPXXtuf9yuEXKudkV2sx1E06UadKWpgI=
|
||||
github.com/fsnotify/fsnotify v1.5.1/go.mod h1:T3375wBYaZdLLcVNkcVbzGHY7f1l/uK5T5Ai1i3InKU=
|
||||
github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko=
|
||||
|
331
main.go
331
main.go
@ -1,20 +1,20 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/aditya-K2/gomp/cache"
|
||||
"github.com/aditya-K2/gomp/client"
|
||||
"github.com/aditya-K2/gomp/config"
|
||||
"github.com/aditya-K2/gomp/notify"
|
||||
"github.com/aditya-K2/gomp/render"
|
||||
"github.com/aditya-K2/gomp/ui"
|
||||
"github.com/aditya-K2/gomp/ui/notify"
|
||||
"github.com/aditya-K2/gomp/utils"
|
||||
"github.com/aditya-K2/gomp/views"
|
||||
|
||||
"github.com/aditya-K2/fuzzy"
|
||||
"github.com/fhs/gompd/mpd"
|
||||
"github.com/fhs/gompd/v2/mpd"
|
||||
"github.com/gdamore/tcell/v2"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
@ -30,33 +30,27 @@ func main() {
|
||||
} else if nt == "unix" && port != "" {
|
||||
port = ""
|
||||
}
|
||||
CONN, mpdConnectionError := mpd.Dial(nt,
|
||||
client.Conn, mpdConnectionError = mpd.Dial(nt,
|
||||
viper.GetString("NETWORK_ADDRESS")+del+port)
|
||||
if mpdConnectionError != nil {
|
||||
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")
|
||||
panic(mpdConnectionError)
|
||||
}
|
||||
defer CONN.Close()
|
||||
Conn := client.Conn
|
||||
defer Conn.Close()
|
||||
|
||||
ui.GenerateFocusMap()
|
||||
|
||||
client.SetConnection(CONN)
|
||||
ui.SetConnection(CONN)
|
||||
render.SetConnection(CONN)
|
||||
ui.SetConnection(Conn)
|
||||
|
||||
cache.SetCacheDir(viper.GetString("CACHE_DIR"))
|
||||
|
||||
Renderer := render.NewRenderer()
|
||||
render.Rendr = render.NewRenderer()
|
||||
// Connecting the Renderer to the Main UI
|
||||
ui.ConnectRenderer(Renderer)
|
||||
ui.ConnectRenderer(render.Rendr)
|
||||
|
||||
UI := ui.NewApplication()
|
||||
ui.Ui = ui.NewApplication()
|
||||
|
||||
// Connecting the Notification Server to the Main UI
|
||||
notify.ConnectUI(UI)
|
||||
|
||||
fileMap, err := CONN.ListAllInfo("/")
|
||||
fileMap, err := Conn.ListAllInfo("/")
|
||||
if err != nil {
|
||||
utils.Print("RED", "Could Not Generate the File Map\n")
|
||||
utils.Print("GREEN", "Make Sure You Mention the Correct MPD Port in the config file.\n")
|
||||
@ -64,15 +58,33 @@ func main() {
|
||||
}
|
||||
|
||||
// Generating the Directory Tree for File Navigation.
|
||||
dirTree := client.GenerateDirectoryTree(fileMap)
|
||||
client.DirTree = client.GenerateDirectoryTree(fileMap)
|
||||
|
||||
// Default View upon Opening is of Playlist.
|
||||
client.UpdatePlaylist(UI.ExpandedView)
|
||||
views.PView.Update(ui.Ui.ExpandedView)
|
||||
|
||||
var Volume int64
|
||||
var Random, Repeat bool
|
||||
var SeekOffset = viper.GetInt("SEEK_OFFSET")
|
||||
var SeekFunc = func(back bool) {
|
||||
if status, err := Conn.Status(); err != nil {
|
||||
notify.Notify.Send("Could not get MPD Status")
|
||||
} else {
|
||||
if status["state"] == "play" {
|
||||
var stime time.Duration
|
||||
if back {
|
||||
stime = -1 * time.Second * time.Duration(SeekOffset)
|
||||
} else {
|
||||
stime = time.Second * time.Duration(SeekOffset)
|
||||
}
|
||||
if err := Conn.SeekCur(stime, true); err != nil {
|
||||
notify.Notify.Send("Could Not Seek Forward in the Song")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if _v, err := CONN.Status(); err != nil {
|
||||
if _v, err := Conn.Status(); err != nil {
|
||||
utils.Print("RED", "Could Not Get the MPD Status\n")
|
||||
panic(err)
|
||||
} else {
|
||||
@ -92,41 +104,26 @@ func main() {
|
||||
// Used for Fuzzy Searching
|
||||
ArtistTreeContent := utils.ConvertToArray(ArtistTree)
|
||||
|
||||
Notify := notify.NewNotificationServer()
|
||||
Notify.Start()
|
||||
notify.Notify = notify.NewNotificationServer()
|
||||
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")
|
||||
panic(err)
|
||||
} else {
|
||||
if len(c) != 0 {
|
||||
Renderer.Start(c["file"])
|
||||
render.Rendr.Start(c["file"])
|
||||
} else {
|
||||
Renderer.Start("stop")
|
||||
render.Rendr.Start("stop")
|
||||
}
|
||||
}
|
||||
|
||||
// Connecting Notification Server to Client and Rendering Module so that they can send Notifications
|
||||
client.SetNotificationServer(Notify)
|
||||
render.SetNotificationServer(Notify)
|
||||
|
||||
// This is the Slice that is used to Display Content in the SearchView
|
||||
var SearchContentSlice []interface{}
|
||||
var Matches fuzzy.Matches
|
||||
|
||||
// This Function Is Responsible for Changing the Focus it uses the Focus Map and Based on it Chooses
|
||||
// the Draw Function
|
||||
UI.ExpandedView.SetDrawFunc(func(s tcell.Screen, x, y, width, height int) (int, int, int, int) {
|
||||
if ui.HasFocus("Playlist") {
|
||||
client.UpdatePlaylist(UI.ExpandedView)
|
||||
} else if ui.HasFocus("SearchView") {
|
||||
client.UpdateSearchView(UI.ExpandedView, SearchContentSlice)
|
||||
} else if ui.HasFocus("FileBrowser") {
|
||||
client.Update(dirTree.Children, UI.ExpandedView)
|
||||
} else if ui.HasFocus("BuffSearchView") {
|
||||
client.UpdateBuffSearchView(UI.ExpandedView, Matches, dirTree.Children)
|
||||
}
|
||||
return UI.ExpandedView.GetInnerRect()
|
||||
views.SetCurrentView(views.PView)
|
||||
ui.Ui.ExpandedView.SetDrawFunc(func(s tcell.Screen, x, y, width, height int) (int, int, int, int) {
|
||||
views.GetCurrentView().Update(ui.Ui.ExpandedView)
|
||||
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
|
||||
@ -134,116 +131,43 @@ func main() {
|
||||
// the respective function in this case togglePlayBack is called.
|
||||
var FuncMap = map[string]func(){
|
||||
"showChildrenContent": func() {
|
||||
if ui.HasFocus("FileBrowser") {
|
||||
r, _ := UI.ExpandedView.GetSelection()
|
||||
ui.SetFocus("FileBrowser")
|
||||
if len(dirTree.Children[r].Children) == 0 {
|
||||
if id, err := CONN.AddId(dirTree.Children[r].AbsolutePath, -1); err != nil {
|
||||
Notify.Send(fmt.Sprintf("Could not Add Song %s",
|
||||
dirTree.Children[r].Path))
|
||||
} else {
|
||||
if err := CONN.PlayId(id); err != nil {
|
||||
Notify.Send(fmt.Sprintf("Could Not Play Song %s",
|
||||
dirTree.Children[r].Path))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
client.Update(dirTree.Children[r].Children, UI.ExpandedView)
|
||||
dirTree = &dirTree.Children[r]
|
||||
UI.ExpandedView.Select(0, 0)
|
||||
}
|
||||
} else if ui.HasFocus("Playlist") {
|
||||
r, _ := UI.ExpandedView.GetSelection()
|
||||
if err := CONN.Play(r); err != nil {
|
||||
Notify.Send("Could Not Play the Song")
|
||||
}
|
||||
} else if ui.HasFocus("SearchView") {
|
||||
r, _ := UI.ExpandedView.GetSelection()
|
||||
client.AddToPlaylist(SearchContentSlice[r], true)
|
||||
} else if ui.HasFocus("BuffSearchView") {
|
||||
r, _ := UI.ExpandedView.GetSelection()
|
||||
ui.SetFocus("FileBrowser")
|
||||
if len(dirTree.Children[r].Children) == 0 {
|
||||
if id, err := CONN.AddId(dirTree.Children[Matches[r].Index].AbsolutePath, -1); err != nil {
|
||||
Notify.Send(fmt.Sprintf("Could Not add the Song %s to the Playlist",
|
||||
dirTree.Children[Matches[r].Index].AbsolutePath))
|
||||
} else {
|
||||
if err := CONN.PlayId(id); err != nil {
|
||||
Notify.Send("Could not Play the Song")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
client.Update(dirTree.Children[Matches[r].Index].Children, UI.ExpandedView)
|
||||
dirTree = &dirTree.Children[Matches[r].Index]
|
||||
}
|
||||
UI.SearchBar.SetText("")
|
||||
// Resetting Matches
|
||||
Matches = nil
|
||||
}
|
||||
views.GetCurrentView().ShowChildrenContent()
|
||||
},
|
||||
"togglePlayBack": func() {
|
||||
if err := client.TogglePlayBack(); err != nil {
|
||||
Notify.Send("Could not Toggle Play Back")
|
||||
notify.Notify.Send("Could not Toggle Play Back")
|
||||
}
|
||||
},
|
||||
"showParentContent": func() {
|
||||
if ui.HasFocus("FileBrowser") {
|
||||
if dirTree.Parent != nil {
|
||||
client.Update(dirTree.Parent.Children, UI.ExpandedView)
|
||||
dirTree = dirTree.Parent
|
||||
}
|
||||
} else {
|
||||
Notify.Send("Not Allowed in this View")
|
||||
return
|
||||
}
|
||||
views.GetCurrentView().ShowParentContent()
|
||||
},
|
||||
"nextSong": func() {
|
||||
if err := CONN.Next(); err != nil {
|
||||
Notify.Send("Could not Select the Next Song")
|
||||
if err := Conn.Next(); err != nil {
|
||||
notify.Notify.Send("Could not Select the Next Song")
|
||||
}
|
||||
},
|
||||
"clearPlaylist": func() {
|
||||
if err := CONN.Clear(); err != nil {
|
||||
Notify.Send("Could not Clear the Playlist")
|
||||
if err := Conn.Clear(); err != nil {
|
||||
notify.Notify.Send("Could not Clear the Playlist")
|
||||
} else {
|
||||
Notify.Send("Playlist Cleared")
|
||||
notify.Notify.Send("Playlist Cleared")
|
||||
}
|
||||
},
|
||||
"previousSong": func() {
|
||||
if err := CONN.Previous(); err != nil {
|
||||
Notify.Send("Could Not Select the Previous Song")
|
||||
if err := Conn.Previous(); err != nil {
|
||||
notify.Notify.Send("Could Not Select the Previous Song")
|
||||
}
|
||||
},
|
||||
"addToPlaylist": func() {
|
||||
if ui.HasFocus("FileBrowser") {
|
||||
r, _ := UI.ExpandedView.GetSelection()
|
||||
if err := CONN.Add(dirTree.Children[r].AbsolutePath); err != nil {
|
||||
Notify.Send(fmt.Sprintf("Could not add %s to the Playlist",
|
||||
dirTree.Children[r].Path))
|
||||
}
|
||||
} else if ui.HasFocus("SearchView") {
|
||||
r, _ := UI.ExpandedView.GetSelection()
|
||||
client.AddToPlaylist(SearchContentSlice[r], false)
|
||||
} else if ui.HasFocus("BuffSearchView") {
|
||||
r, _ := UI.ExpandedView.GetSelection()
|
||||
if err := CONN.Add(dirTree.Children[Matches[r].Index].AbsolutePath); err != nil {
|
||||
Notify.Send(fmt.Sprintf("Could Not Add URI %s to the Playlist",
|
||||
dirTree.Children[Matches[r].Index].Path))
|
||||
} else {
|
||||
ui.SetFocus("FileBrowser")
|
||||
Notify.Send(fmt.Sprintf("URI Added %s to the Playlist",
|
||||
dirTree.Children[Matches[r].Index].Path))
|
||||
ui.SetFocus("BuffSearchView")
|
||||
}
|
||||
}
|
||||
views.GetCurrentView().AddToPlaylist()
|
||||
},
|
||||
"toggleRandom": func() {
|
||||
if err := CONN.Random(!Random); err == nil {
|
||||
if err := Conn.Random(!Random); err == nil {
|
||||
Random = !Random
|
||||
}
|
||||
},
|
||||
"toggleRepeat": func() {
|
||||
if err := CONN.Repeat(!Repeat); err == nil {
|
||||
if err := Conn.Repeat(!Repeat); err == nil {
|
||||
Repeat = !Repeat
|
||||
}
|
||||
},
|
||||
@ -253,8 +177,8 @@ func main() {
|
||||
} else {
|
||||
Volume -= 10
|
||||
}
|
||||
if err := CONN.SetVolume(int(Volume)); err != nil {
|
||||
Notify.Send("Could Not Decrease the Volume")
|
||||
if err := Conn.SetVolume(int(Volume)); err != nil {
|
||||
notify.Notify.Send("Could Not Decrease the Volume")
|
||||
}
|
||||
},
|
||||
"increaseVolume": func() {
|
||||
@ -263,67 +187,60 @@ func main() {
|
||||
} else {
|
||||
Volume += 10
|
||||
}
|
||||
if err := CONN.SetVolume(int(Volume)); err != nil {
|
||||
Notify.Send("Could Not Increase the Volume")
|
||||
if err := Conn.SetVolume(int(Volume)); err != nil {
|
||||
notify.Notify.Send("Could Not Increase the Volume")
|
||||
}
|
||||
},
|
||||
"navigateToFiles": func() {
|
||||
ui.SetFocus("FileBrowser")
|
||||
UI.Navbar.Select(1, 0)
|
||||
client.Update(dirTree.Children, UI.ExpandedView)
|
||||
views.SetCurrentView(views.FView)
|
||||
ui.Ui.Navbar.Select(1, 0)
|
||||
views.FView.Update(ui.Ui.ExpandedView)
|
||||
},
|
||||
"navigateToPlaylist": func() {
|
||||
ui.SetFocus("Playlist")
|
||||
UI.Navbar.Select(0, 0)
|
||||
client.UpdatePlaylist(UI.ExpandedView)
|
||||
views.SetCurrentView(views.PView)
|
||||
ui.Ui.Navbar.Select(0, 0)
|
||||
views.PView.Update(ui.Ui.ExpandedView)
|
||||
},
|
||||
"navigateToMostPlayed": func() {
|
||||
UI.Navbar.Select(2, 0)
|
||||
ui.Ui.Navbar.Select(2, 0)
|
||||
},
|
||||
"navigateToSearch": func() {
|
||||
ui.SetFocus("SearchView")
|
||||
UI.Navbar.Select(3, 0)
|
||||
views.SetCurrentView(views.SView)
|
||||
ui.Ui.Navbar.Select(3, 0)
|
||||
views.SView.Update(ui.Ui.ExpandedView)
|
||||
},
|
||||
"quit": func() {
|
||||
if ui.HasFocus("BuffSearchView") {
|
||||
ui.SetFocus("FileBrowser")
|
||||
UI.SearchBar.SetText("")
|
||||
Matches = nil
|
||||
} else {
|
||||
UI.App.Stop()
|
||||
}
|
||||
views.GetCurrentView().Quit()
|
||||
},
|
||||
"stop": func() {
|
||||
if err := CONN.Stop(); err != nil {
|
||||
Notify.Send("Could not Stop the Playback")
|
||||
if err := Conn.Stop(); err != nil {
|
||||
notify.Notify.Send("Could not Stop the Playback")
|
||||
} else {
|
||||
Notify.Send("Playback Stopped")
|
||||
notify.Notify.Send("Playback Stopped")
|
||||
}
|
||||
},
|
||||
"updateDB": func() {
|
||||
_, err = CONN.Update("")
|
||||
_, err = Conn.Update("")
|
||||
if err != nil {
|
||||
Notify.Send("Could Not Update the Database")
|
||||
notify.Notify.Send("Could Not Update the Database")
|
||||
} else {
|
||||
Notify.Send("Database Updated")
|
||||
notify.Notify.Send("Database Updated")
|
||||
}
|
||||
},
|
||||
"deleteSongFromPlaylist": func() {
|
||||
if ui.HasFocus("Playlist") {
|
||||
r, _ := UI.ExpandedView.GetSelection()
|
||||
if err := CONN.Delete(r, -1); err != nil {
|
||||
Notify.Send("Could not Remove the Song from Playlist")
|
||||
}
|
||||
}
|
||||
views.GetCurrentView().DeleteSongFromPlaylist()
|
||||
},
|
||||
"FocusSearch": func() {
|
||||
UI.App.SetFocus(UI.SearchBar)
|
||||
ui.Ui.App.SetFocus(ui.Ui.SearchBar)
|
||||
},
|
||||
"FocusBuffSearch": func() {
|
||||
if ui.HasFocus("FileBrowser") || ui.HasFocus("BuffSearchView") {
|
||||
ui.SetFocus("BuffSearchView")
|
||||
UI.App.SetFocus(UI.SearchBar)
|
||||
}
|
||||
views.GetCurrentView().FocusBuffSearchView()
|
||||
},
|
||||
"SeekForward": func() {
|
||||
SeekFunc(false)
|
||||
},
|
||||
"SeekBackward": func() {
|
||||
SeekFunc(true)
|
||||
},
|
||||
}
|
||||
|
||||
@ -332,12 +249,12 @@ func main() {
|
||||
// for each event T, P, SPACE mapped to the same function togglePlayBack
|
||||
config.GenerateKeyMap(FuncMap)
|
||||
|
||||
UI.SearchBar.SetAutocompleteFunc(func(c string) []string {
|
||||
if ui.HasFocus("BuffSearchView") {
|
||||
ui.Ui.SearchBar.SetAutocompleteFunc(func(c string) []string {
|
||||
if views.GetCurrentView().GetViewName() == "BuffSearchView" {
|
||||
return nil
|
||||
} else {
|
||||
if c != "" && c != " " && c != " " {
|
||||
_, _, w, _ := UI.SearchBar.GetRect()
|
||||
_, _, w, _ := ui.Ui.SearchBar.GetRect()
|
||||
matches := fuzzy.Find(c, ArtistTreeContent)
|
||||
var suggestions []string
|
||||
for i, match := range matches {
|
||||
@ -354,83 +271,87 @@ func main() {
|
||||
})
|
||||
|
||||
// Input Handler
|
||||
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 {
|
||||
FuncMap[val]()
|
||||
return nil
|
||||
} else {
|
||||
if ui.HasFocus("Playlist") {
|
||||
if views.GetCurrentView().GetViewName() == "PlaylistView" {
|
||||
if e.Rune() == 'j' || e.Rune() == 'k' {
|
||||
if p, err := CONN.PlaylistInfo(-1, -1); err != nil {
|
||||
Notify.Send("Error Getting PlaylistInfo")
|
||||
if p, err := Conn.PlaylistInfo(-1, -1); err != nil {
|
||||
notify.Notify.Send("Error Getting PlaylistInfo")
|
||||
} else {
|
||||
if len(p) == 0 {
|
||||
Notify.Send("Empty Playlist")
|
||||
notify.Notify.Send("Empty Playlist")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if views.GetCurrentView().GetViewName() == "SearchView" {
|
||||
if e.Rune() == 'j' || e.Rune() == 'k' {
|
||||
if client.SearchContentSlice == nil || len(client.SearchContentSlice) == 0 {
|
||||
notify.Notify.Send("No Search Results")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return e
|
||||
}
|
||||
})
|
||||
|
||||
UI.SearchBar.SetDoneFunc(func(e tcell.Key) {
|
||||
ui.Ui.SearchBar.SetDoneFunc(func(e tcell.Key) {
|
||||
if e == tcell.KeyEnter {
|
||||
UI.ExpandedView.Select(0, 0)
|
||||
if ui.HasFocus("BuffSearchView") {
|
||||
UI.App.SetFocus(UI.ExpandedView)
|
||||
ui.Ui.ExpandedView.Select(0, 0)
|
||||
if views.GetCurrentView().GetViewName() == "BuffSearchView" {
|
||||
ui.Ui.App.SetFocus(ui.Ui.ExpandedView)
|
||||
} else {
|
||||
ui.SetFocus("SearchView")
|
||||
SearchContentSlice = nil
|
||||
SearchContentSlice, err = client.GenerateContentSlice(UI.SearchBar.GetText())
|
||||
views.SetCurrentView(views.SView)
|
||||
client.SearchContentSlice = nil
|
||||
client.SearchContentSlice, err = client.GenerateContentSlice(ui.Ui.SearchBar.GetText())
|
||||
if err != nil {
|
||||
Notify.Send("Could Not Retrieve the Results")
|
||||
notify.Notify.Send("Could Not Retrieve the Results")
|
||||
} else {
|
||||
UI.SearchBar.SetText("")
|
||||
UI.App.SetFocus(UI.ExpandedView)
|
||||
UI.Navbar.Select(3, 0)
|
||||
ui.Ui.SearchBar.SetText("")
|
||||
ui.Ui.App.SetFocus(ui.Ui.ExpandedView)
|
||||
ui.Ui.Navbar.Select(3, 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
if e == tcell.KeyEscape {
|
||||
if ui.HasFocus("SearchView") {
|
||||
ui.FocusMap["SearchView"] = false
|
||||
} else if ui.HasFocus("BuffSearchView") {
|
||||
ui.SetFocus("FileBrowser")
|
||||
Matches = nil
|
||||
if views.GetCurrentView().GetViewName() == "BuffSearchView" {
|
||||
client.Matches = nil
|
||||
}
|
||||
UI.SearchBar.SetText("")
|
||||
UI.App.SetFocus(UI.ExpandedView)
|
||||
ui.Ui.SearchBar.SetText("")
|
||||
ui.Ui.App.SetFocus(ui.Ui.ExpandedView)
|
||||
}
|
||||
})
|
||||
|
||||
UI.ExpandedView.SetDoneFunc(func(e tcell.Key) {
|
||||
ui.Ui.ExpandedView.SetDoneFunc(func(e tcell.Key) {
|
||||
if e == tcell.KeyEscape {
|
||||
if ui.HasFocus("BuffSearchView") {
|
||||
ui.SetFocus("FileBrowser")
|
||||
UI.SearchBar.SetText("")
|
||||
Matches = nil
|
||||
if views.GetCurrentView().GetViewName() == "BuffSearchView" {
|
||||
views.SetCurrentView(views.FView)
|
||||
ui.Ui.SearchBar.SetText("")
|
||||
client.Matches = nil
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
UI.SearchBar.SetChangedFunc(func(text string) {
|
||||
if ui.HasFocus("BuffSearchView") {
|
||||
var f client.FileNodes = dirTree.Children
|
||||
Matches = fuzzy.FindFrom(text, f)
|
||||
client.UpdateBuffSearchView(UI.ExpandedView, Matches, dirTree.Children)
|
||||
ui.Ui.SearchBar.SetChangedFunc(func(text string) {
|
||||
if views.GetCurrentView().GetViewName() == "BuffSearchView" {
|
||||
var f client.FileNodes = client.DirTree.Children
|
||||
client.Matches = fuzzy.FindFrom(text, f)
|
||||
views.BuffSView.Update(ui.Ui.ExpandedView)
|
||||
}
|
||||
})
|
||||
|
||||
go func() {
|
||||
for {
|
||||
UI.App.Draw()
|
||||
ui.Ui.App.Draw()
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
}()
|
||||
|
||||
if err := UI.App.Run(); err != nil {
|
||||
if err := ui.Ui.App.Run(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/aditya-K2/gomp/ui"
|
||||
|
||||
"github.com/aditya-K2/gomp/utils"
|
||||
|
||||
"github.com/aditya-K2/tview"
|
||||
@ -12,13 +11,9 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
UI *ui.Application
|
||||
Notify *NotificationServer
|
||||
)
|
||||
|
||||
func ConnectUI(a *ui.Application) {
|
||||
UI = a
|
||||
}
|
||||
|
||||
/* Notification Primitive */
|
||||
type Notification struct {
|
||||
*tview.Box
|
||||
@ -79,11 +74,11 @@ func NotificationRoutine(c chan string, s string) {
|
||||
if s != "EMPTY NOTIFICATION" {
|
||||
go func() {
|
||||
currentTime := time.Now().String()
|
||||
UI.Pages.AddPage(currentTime, NewNotification(s), false, true)
|
||||
UI.App.SetFocus(UI.ExpandedView)
|
||||
ui.Ui.Pages.AddPage(currentTime, NewNotification(s), false, true)
|
||||
ui.Ui.App.SetFocus(ui.Ui.ExpandedView)
|
||||
time.Sleep(time.Second * 1)
|
||||
UI.Pages.RemovePage(currentTime)
|
||||
UI.App.SetFocus(UI.ExpandedView)
|
||||
ui.Ui.Pages.RemovePage(currentTime)
|
||||
ui.Ui.App.SetFocus(ui.Ui.ExpandedView)
|
||||
}()
|
||||
}
|
||||
NewNotification := <-c
|
@ -4,8 +4,9 @@ import (
|
||||
"image"
|
||||
"os"
|
||||
|
||||
"github.com/aditya-K2/gomp/client"
|
||||
"github.com/aditya-K2/gomp/notify"
|
||||
"github.com/aditya-K2/gomp/ui"
|
||||
"github.com/fhs/gompd/mpd"
|
||||
|
||||
"github.com/aditya-K2/gomp/cache"
|
||||
"github.com/aditya-K2/gomp/utils"
|
||||
@ -15,18 +16,9 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
CONN *mpd.Client
|
||||
Notify interface{ Send(string) }
|
||||
Rendr *Renderer
|
||||
)
|
||||
|
||||
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
|
||||
// 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.
|
||||
@ -82,7 +74,7 @@ func (r *Renderer) Start(path string) {
|
||||
// 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.
|
||||
func GetImagePath(path string) string {
|
||||
a, err := CONN.ListInfo(path)
|
||||
a, err := client.Conn.ListInfo(path)
|
||||
var extractedImage string
|
||||
if err == nil && len(a) != 0 {
|
||||
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" {
|
||||
downloadedImage, err := getImageFromLastFM(a[0]["artist"], a[0]["album"], imagePath)
|
||||
if err == nil {
|
||||
Notify.Send("Image From LastFM")
|
||||
notify.Notify.Send("Image From LastFM")
|
||||
extractedImage = downloadedImage
|
||||
} else {
|
||||
Notify.Send("Falling Back to Default Image.")
|
||||
notify.Notify.Send("Falling Back to Default Image.")
|
||||
}
|
||||
} else {
|
||||
Notify.Send("Extracted Image Successfully")
|
||||
notify.Notify.Send("Extracted Image Successfully")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -63,6 +63,10 @@ DEFAULT_IMAGE_PATH: "default.jpg"
|
||||
# Note It is neccessary to use /home/your_user_name instead of ~
|
||||
# Read more about it here: https://github.com/aditya-K2/gomp/issues/1#issuecomment-1205090265
|
||||
|
||||
SEEK_OFFSET : 1
|
||||
# The amount of seconds by which the song should seek forward or backward
|
||||
# Defaults to 1 if not provided
|
||||
|
||||
GET_COVER_ART_FROM_LAST_FM : "TRUE" # Turn On Getting Album art from lastfm api
|
||||
LASTFM_API_KEY: "YOUR API KEY HERE"
|
||||
LASTFM_API_SECRET: "YOUR API SECRET HERE"
|
||||
|
@ -10,6 +10,7 @@ var (
|
||||
ImgW int
|
||||
ImgH int
|
||||
ImgX int
|
||||
Ui *Application
|
||||
)
|
||||
|
||||
type Application struct {
|
||||
@ -17,13 +18,14 @@ type Application struct {
|
||||
ExpandedView *tview.Table
|
||||
Navbar *tview.Table
|
||||
SearchBar *tview.InputField
|
||||
ProgressBar *progressBar
|
||||
ProgressBar *ProgressBar
|
||||
Pages *tview.Pages
|
||||
}
|
||||
|
||||
func NewApplication() *Application {
|
||||
|
||||
var pBar *progressBar = newProgressBar()
|
||||
pBar := NewProgressBar()
|
||||
pBar.SetProgressFunc(progressFunction)
|
||||
expandedView := tview.NewTable()
|
||||
Navbar := tview.NewTable()
|
||||
searchBar := tview.NewInputField()
|
||||
@ -67,7 +69,7 @@ func NewApplication() *Application {
|
||||
|
||||
MainFlex := tview.NewFlex().SetDirection(tview.FlexRow).
|
||||
AddItem(searchBarFlex, 0, 8, false).
|
||||
AddItem(pBar.t, 5, 1, false)
|
||||
AddItem(pBar, 5, 1, false)
|
||||
|
||||
expandedView.SetBorderPadding(1, 1, 1, 1).SetBorder(true)
|
||||
expandedView.SetSelectable(true, false)
|
||||
|
25
ui/focus.go
25
ui/focus.go
@ -1,25 +0,0 @@
|
||||
package ui
|
||||
|
||||
// The Focus Map Helps to keep track of which UI Element Currently Has the Focus It can be queried to get the Current
|
||||
// UI Element with Focus and also can set UI Focus keep in mind that it isn't Focus Map that is Responsible to change
|
||||
// the Focus that is Done through the Update Function of UI.ExpandedView */
|
||||
var FocusMap map[string]bool
|
||||
|
||||
func GenerateFocusMap() {
|
||||
FocusMap = make(map[string]bool)
|
||||
FocusMap["Playlist"] = true
|
||||
FocusMap["FileBrowser"] = false
|
||||
FocusMap["SearchView"] = false
|
||||
FocusMap["BuffSearchView"] = false
|
||||
}
|
||||
|
||||
func HasFocus(s string) bool {
|
||||
return FocusMap[s]
|
||||
}
|
||||
|
||||
func SetFocus(s string) {
|
||||
for k := range FocusMap {
|
||||
FocusMap[k] = false
|
||||
}
|
||||
FocusMap[s] = true
|
||||
}
|
@ -3,17 +3,17 @@ package ui
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/fhs/gompd/mpd"
|
||||
"github.com/fhs/gompd/v2/mpd"
|
||||
"github.com/gdamore/tcell/v2"
|
||||
|
||||
"github.com/aditya-K2/gomp/utils"
|
||||
|
||||
"github.com/aditya-K2/tview"
|
||||
"github.com/gdamore/tcell/v2"
|
||||
)
|
||||
|
||||
var (
|
||||
CurrentSong string
|
||||
CurrentSong string = ""
|
||||
CONN *mpd.Client
|
||||
RENDERER interface{ Send(string) }
|
||||
)
|
||||
@ -26,48 +26,70 @@ func ConnectRenderer(r interface{ Send(string) }) {
|
||||
RENDERER = r
|
||||
}
|
||||
|
||||
// The progressBar is just a string which is separated by the color formatting String
|
||||
// for e.g
|
||||
// "[:#fbff00:]******************`innerText`[-:-:-] "
|
||||
// the above string shows represents the progress until [-:-:-]
|
||||
// [-:-:-] this string represents resetting colors so the substring before it would be with a
|
||||
// colored background. this is done by calculating the innerRect of the table and taking that length as
|
||||
// 100% and then representing the rest of the information in relation to it
|
||||
type progressBar struct {
|
||||
t *tview.Table
|
||||
// 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
|
||||
type ProgressBar struct {
|
||||
*tview.Box
|
||||
BarTitle string
|
||||
BarText string
|
||||
BarTopTitle string
|
||||
progressFunc func() (BarTitle string,
|
||||
BarTopTitle string,
|
||||
BarText string,
|
||||
percentage float64)
|
||||
}
|
||||
|
||||
// This Function returns a progressBar with a table of two rows
|
||||
// the First row will contain information about the current Song
|
||||
// and the Second one will contain the progressBar
|
||||
func newProgressBar() *progressBar {
|
||||
p := progressBar{}
|
||||
|
||||
a := tview.NewTable().
|
||||
SetCell(0, 0, tview.NewTableCell("")).
|
||||
SetCell(1, 0, tview.NewTableCell("")).
|
||||
SetCell(2, 0, tview.NewTableCell(""))
|
||||
|
||||
a.SetBackgroundColor(tcell.ColorDefault)
|
||||
a.SetBorder(true)
|
||||
|
||||
a.SetDrawFunc(func(s tcell.Screen, x, y, width, height int) (int, int, int, int) {
|
||||
p.updateTitle()
|
||||
p.updateProgress()
|
||||
return p.t.GetInnerRect()
|
||||
})
|
||||
|
||||
CurrentSong = ""
|
||||
|
||||
p = progressBar{a}
|
||||
return &p
|
||||
func (self *ProgressBar) SetProgressFunc(pfunc func() (string, string, string, float64)) *ProgressBar {
|
||||
self.progressFunc = pfunc
|
||||
return self
|
||||
}
|
||||
|
||||
func (s *progressBar) updateTitle() {
|
||||
func NewProgressBar() *ProgressBar {
|
||||
return &ProgressBar{
|
||||
Box: tview.NewBox(),
|
||||
}
|
||||
}
|
||||
|
||||
func GetProgressGlyph(width, percentage float64, btext string) string {
|
||||
q := "[black:white:b]"
|
||||
var a string
|
||||
a += strings.Repeat(" ", int(width)-len(btext))
|
||||
a = utils.InsertAt(a, btext, int(width/2)-10)
|
||||
a = utils.InsertAt(a, "[-:-:-]", int(width*percentage/100))
|
||||
q += a
|
||||
return q
|
||||
}
|
||||
|
||||
func (self *ProgressBar) Draw(screen tcell.Screen) {
|
||||
var (
|
||||
OFFSET int = 1
|
||||
)
|
||||
self.Box.SetBorder(true)
|
||||
self.Box.SetBackgroundColor(tcell.ColorDefault)
|
||||
var percentage float64
|
||||
self.BarTitle, self.BarTopTitle, 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,
|
||||
GetProgressGlyph(float64(_width-OFFSET-1),
|
||||
percentage,
|
||||
self.BarText),
|
||||
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
|
||||
if err == nil {
|
||||
song := "[green::bi]" + _currentAttributes["Title"] + "[-:-:-] - " + "[blue::b]" + _currentAttributes["Artist"] + "\n"
|
||||
s.t.GetCell(0, 0).Text = song
|
||||
song = "[green::bi]" +
|
||||
_currentAttributes["Title"] + "[-:-:-] - " + "[blue::b]" +
|
||||
_currentAttributes["Artist"] + "\n"
|
||||
if len(_currentAttributes) == 0 && CurrentSong != "" {
|
||||
CurrentSong = ""
|
||||
RENDERER.Send("stop")
|
||||
@ -75,39 +97,32 @@ func (s *progressBar) updateTitle() {
|
||||
RENDERER.Send(_currentAttributes["file"])
|
||||
CurrentSong = song
|
||||
}
|
||||
} else {
|
||||
utils.Print("RED", "Error Retrieving Current Song\n")
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *progressBar) updateProgress() {
|
||||
_status, err := CONN.Status()
|
||||
_, _, _width, _ := s.t.GetInnerRect()
|
||||
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"])
|
||||
if du != 0 {
|
||||
percentage := el / du * 100
|
||||
percentage = el / du * 100
|
||||
if err == nil && err1 == nil {
|
||||
s.t.SetTitle(fmt.Sprintf("[[::i] %s [-:-:-]Shuffle: %s Repeat: %s Volume: %s ]",
|
||||
utils.FormatString(_status["state"]),
|
||||
utils.FormatString(_status["random"]),
|
||||
utils.FormatString(_status["repeat"]),
|
||||
_status["volume"])).
|
||||
SetTitleAlign(tview.AlignRight)
|
||||
s.t.GetCell(2, 0).Text = utils.GetText(float64(_width), percentage, 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 {
|
||||
s.t.SetTitle(fmt.Sprintf("[[::i] %s [-:-:-]Shuffle: %s Repeat: %s]",
|
||||
utils.FormatString(_status["state"]),
|
||||
utils.FormatString(_status["random"]),
|
||||
utils.FormatString(_status["repeat"]))).
|
||||
SetTitleAlign(tview.AlignRight)
|
||||
s.t.GetCell(2, 0).Text = ""
|
||||
text = ""
|
||||
}
|
||||
} else {
|
||||
s.t.SetTitle(fmt.Sprintf("[[::i] %s [-:-:-]Shuffle: %s Repeat: %s Volume: %s ]",
|
||||
utils.FormatString(_status["state"]),
|
||||
utils.FormatString(_status["random"]),
|
||||
utils.FormatString(_status["repeat"]),
|
||||
_status["volume"])).
|
||||
SetTitleAlign(tview.AlignRight)
|
||||
s.t.GetCell(2, 0).Text = utils.GetText(float64(_width), 0, " ---:---")
|
||||
text = " ---:---"
|
||||
percentage = 0
|
||||
}
|
||||
if percentage > 100 {
|
||||
percentage = 0
|
||||
}
|
||||
return song, top, text, percentage
|
||||
}
|
||||
|
@ -58,16 +58,6 @@ func InsertAt(inputString, stringTobeInserted string, index int) string {
|
||||
return s
|
||||
}
|
||||
|
||||
func GetText(width, percentage float64, eta string) string {
|
||||
q := "[black:white:b]"
|
||||
var a string
|
||||
a += strings.Repeat(" ", int(width)-len(eta))
|
||||
a = InsertAt(a, eta, int(width/2)-10)
|
||||
a = InsertAt(a, "[-:-:-]", int(width*percentage/100))
|
||||
q += a
|
||||
return q
|
||||
}
|
||||
|
||||
func ConvertToArray(ArtistTree map[string]map[string]map[string]string) []string {
|
||||
var p []string
|
||||
for k2, v := range ArtistTree {
|
||||
|
105
views/buffsearchview.go
Normal file
105
views/buffsearchview.go
Normal file
@ -0,0 +1,105 @@
|
||||
package views
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"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/tview"
|
||||
"github.com/gdamore/tcell/v2"
|
||||
)
|
||||
|
||||
type BuffSearchView struct {
|
||||
}
|
||||
|
||||
func (s BuffSearchView) GetViewName() string {
|
||||
return "BuffSearchView"
|
||||
}
|
||||
|
||||
func (s BuffSearchView) ShowChildrenContent() {
|
||||
UI := ui.Ui
|
||||
CONN := client.Conn
|
||||
r, _ := UI.ExpandedView.GetSelection()
|
||||
SetCurrentView(FView)
|
||||
if len(client.DirTree.Children[r].Children) == 0 {
|
||||
if id, err := CONN.AddID(client.DirTree.Children[client.Matches[r].Index].AbsolutePath, -1); err != nil {
|
||||
notify.Notify.Send(fmt.Sprintf("Could Not add the Song %s to the Playlist",
|
||||
client.DirTree.Children[client.Matches[r].Index].AbsolutePath))
|
||||
} else {
|
||||
if err := CONN.PlayID(id); err != nil {
|
||||
notify.Notify.Send("Could not Play the Song")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
client.DirTree = &client.DirTree.Children[client.Matches[r].Index]
|
||||
FView.Update(UI.ExpandedView)
|
||||
}
|
||||
UI.SearchBar.SetText("")
|
||||
// Resetting client.Matches
|
||||
client.Matches = nil
|
||||
}
|
||||
|
||||
func (s BuffSearchView) ShowParentContent() {
|
||||
notify.Notify.Send("Not Allowed in this View")
|
||||
return
|
||||
}
|
||||
|
||||
func (s BuffSearchView) AddToPlaylist() {
|
||||
UI := ui.Ui
|
||||
CONN := client.Conn
|
||||
r, _ := UI.ExpandedView.GetSelection()
|
||||
if err := CONN.Add(client.DirTree.Children[client.Matches[r].Index].AbsolutePath); err != nil {
|
||||
notify.Notify.Send(fmt.Sprintf("Could Not Add URI %s to the Playlist",
|
||||
client.DirTree.Children[client.Matches[r].Index].Path))
|
||||
} else {
|
||||
SetCurrentView(FView)
|
||||
notify.Notify.Send(fmt.Sprintf("URI Added %s to the Playlist",
|
||||
client.DirTree.Children[client.Matches[r].Index].Path))
|
||||
SetCurrentView(BuffSView)
|
||||
}
|
||||
}
|
||||
|
||||
func (s BuffSearchView) Quit() {
|
||||
UI := ui.Ui
|
||||
SetCurrentView(FView)
|
||||
UI.SearchBar.SetText("")
|
||||
client.Matches = nil
|
||||
}
|
||||
|
||||
func (f BuffSearchView) FocusBuffSearchView() {
|
||||
UI := ui.Ui
|
||||
SetCurrentView(BuffSView)
|
||||
UI.App.SetFocus(UI.SearchBar)
|
||||
}
|
||||
|
||||
func (f BuffSearchView) DeleteSongFromPlaylist() {}
|
||||
|
||||
func (s BuffSearchView) Update(inputTable *tview.Table) {
|
||||
m := client.Matches
|
||||
f := client.DirTree.Children
|
||||
inputTable.Clear()
|
||||
if m == nil || len(m) == 0 {
|
||||
FView.Update(inputTable)
|
||||
} else {
|
||||
for k, v := range m {
|
||||
if len(f[v.Index].Children) != 0 {
|
||||
inputTable.SetCell(k, 0,
|
||||
GetCell(
|
||||
utils.GetMatchedString(
|
||||
utils.Unique(v.MatchedIndexes), f[v.Index].Path, "[blue:-:bi]"),
|
||||
tcell.ColorYellow, true))
|
||||
} else {
|
||||
inputTable.SetCell(k, 0,
|
||||
GetCell(
|
||||
utils.GetMatchedString(
|
||||
utils.Unique(v.MatchedIndexes), f[v.Index].Title, "[yellow:-:bi]"),
|
||||
tcell.ColorGreen, true))
|
||||
}
|
||||
if k == 15 {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
99
views/fileview.go
Normal file
99
views/fileview.go
Normal file
@ -0,0 +1,99 @@
|
||||
package views
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"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/tview"
|
||||
"github.com/gdamore/tcell/v2"
|
||||
)
|
||||
|
||||
type FileView struct {
|
||||
}
|
||||
|
||||
func (f FileView) GetViewName() string {
|
||||
return "FileView"
|
||||
}
|
||||
|
||||
func (f FileView) ShowChildrenContent() {
|
||||
UI := ui.Ui
|
||||
CONN := client.Conn
|
||||
r, _ := UI.ExpandedView.GetSelection()
|
||||
SetCurrentView(FView)
|
||||
if len(client.DirTree.Children[r].Children) == 0 {
|
||||
if id, err := CONN.AddID(client.DirTree.Children[r].AbsolutePath, -1); err != nil {
|
||||
notify.Notify.Send(fmt.Sprintf("Could not Add Song %s",
|
||||
client.DirTree.Children[r].Path))
|
||||
} else {
|
||||
if err := CONN.PlayID(id); err != nil {
|
||||
notify.Notify.Send(fmt.Sprintf("Could Not Play Song %s",
|
||||
client.DirTree.Children[r].Path))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
client.DirTree = &client.DirTree.Children[r]
|
||||
FView.Update(UI.ExpandedView)
|
||||
UI.ExpandedView.Select(0, 0)
|
||||
}
|
||||
}
|
||||
|
||||
func (f FileView) ShowParentContent() {
|
||||
UI := ui.Ui
|
||||
if client.DirTree.Parent != nil {
|
||||
client.DirTree = client.DirTree.Parent
|
||||
FView.Update(UI.ExpandedView)
|
||||
}
|
||||
}
|
||||
|
||||
func (f FileView) AddToPlaylist() {
|
||||
UI := ui.Ui
|
||||
CONN := client.Conn
|
||||
r, _ := UI.ExpandedView.GetSelection()
|
||||
if err := CONN.Add(client.DirTree.Children[r].AbsolutePath); err != nil {
|
||||
notify.Notify.Send(fmt.Sprintf("Could not add %s to the Playlist",
|
||||
client.DirTree.Children[r].Path))
|
||||
}
|
||||
}
|
||||
|
||||
func (f FileView) Quit() {
|
||||
ui.Ui.App.Stop()
|
||||
}
|
||||
|
||||
func (f FileView) FocusBuffSearchView() {
|
||||
UI := ui.Ui
|
||||
SetCurrentView(BuffSView)
|
||||
UI.App.SetFocus(UI.SearchBar)
|
||||
}
|
||||
|
||||
func (f FileView) DeleteSongFromPlaylist() {}
|
||||
|
||||
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"] != "" {
|
||||
_, _, w, _ := inputTable.GetInnerRect()
|
||||
inputTable.SetCell(i, 0,
|
||||
GetCell(
|
||||
utils.GetFormattedString(_songAttributes[0]["Title"], w/3), tcell.ColorGreen, false))
|
||||
|
||||
inputTable.SetCell(i, 1,
|
||||
GetCell(
|
||||
utils.GetFormattedString(_songAttributes[0]["Artist"], w/3), tcell.ColorPurple, false))
|
||||
inputTable.SetCell(i, 2,
|
||||
GetCell(_songAttributes[0]["Album"], tcell.ColorYellow, false))
|
||||
|
||||
} else if _songAttributes[0]["Title"] == "" {
|
||||
inputTable.SetCell(i, 0,
|
||||
GetCell(j.Path, tcell.ColorBlue, true))
|
||||
}
|
||||
} else {
|
||||
inputTable.SetCell(i, 0,
|
||||
GetCell(j.Path, tcell.ColorYellow, true))
|
||||
}
|
||||
}
|
||||
}
|
82
views/playlistview.go
Normal file
82
views/playlistview.go
Normal file
@ -0,0 +1,82 @@
|
||||
package views
|
||||
|
||||
import (
|
||||
"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/tview"
|
||||
"github.com/gdamore/tcell/v2"
|
||||
)
|
||||
|
||||
type PlaylistView struct {
|
||||
}
|
||||
|
||||
func (s PlaylistView) GetViewName() string {
|
||||
return "PlaylistView"
|
||||
}
|
||||
|
||||
func GetCell(text string, foreground tcell.Color, bold bool) *tview.TableCell {
|
||||
return tview.NewTableCell(text).
|
||||
SetAlign(tview.AlignLeft).
|
||||
SetStyle(tcell.StyleDefault.
|
||||
Foreground(foreground).
|
||||
Background(tcell.ColorBlack).
|
||||
Bold(bold))
|
||||
}
|
||||
|
||||
func (p PlaylistView) ShowChildrenContent() {
|
||||
UI := ui.Ui
|
||||
CONN := client.Conn
|
||||
r, _ := UI.ExpandedView.GetSelection()
|
||||
if err := CONN.Play(r); err != nil {
|
||||
notify.Notify.Send("Could Not Play the Song")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func (s PlaylistView) ShowParentContent() {
|
||||
notify.Notify.Send("Not Allowed in this View")
|
||||
return
|
||||
}
|
||||
func (p PlaylistView) AddToPlaylist() {}
|
||||
|
||||
func (p PlaylistView) Quit() {
|
||||
ui.Ui.App.Stop()
|
||||
}
|
||||
|
||||
func (p PlaylistView) FocusBuffSearchView() {}
|
||||
|
||||
func (p PlaylistView) DeleteSongFromPlaylist() {
|
||||
UI := ui.Ui
|
||||
CONN := client.Conn
|
||||
r, _ := UI.ExpandedView.GetSelection()
|
||||
if err := CONN.Delete(r, -1); err != nil {
|
||||
notify.Notify.Send("Could not Remove the Song from Playlist")
|
||||
}
|
||||
}
|
||||
|
||||
func (p PlaylistView) Update(inputTable *tview.Table) {
|
||||
CONN := client.Conn
|
||||
_playlistAttr, _ := CONN.PlaylistInfo(-1, -1)
|
||||
|
||||
inputTable.Clear()
|
||||
for i, j := range _playlistAttr {
|
||||
_, _, w, _ := inputTable.GetInnerRect()
|
||||
if j["Title"] == "" || j["Artist"] == "" || j["Album"] == "" {
|
||||
inputTable.SetCell(i, 0,
|
||||
GetCell(
|
||||
utils.GetFormattedString(j["file"], w/3), tcell.ColorBlue, true))
|
||||
|
||||
} else {
|
||||
inputTable.SetCell(i, 0,
|
||||
GetCell(
|
||||
utils.GetFormattedString(j["Title"], w/3), tcell.ColorGreen, false))
|
||||
inputTable.SetCell(i, 1,
|
||||
GetCell(
|
||||
utils.GetFormattedString(j["Artist"], w/3), tcell.ColorPurple, false))
|
||||
inputTable.SetCell(i, 2,
|
||||
GetCell(j["Album"], tcell.ColorYellow, false))
|
||||
}
|
||||
}
|
||||
}
|
93
views/searchview.go
Normal file
93
views/searchview.go
Normal file
@ -0,0 +1,93 @@
|
||||
package views
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"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/tview"
|
||||
"github.com/gdamore/tcell/v2"
|
||||
)
|
||||
|
||||
type SearchView struct {
|
||||
}
|
||||
|
||||
func (s SearchView) GetViewName() string {
|
||||
return "SearchView"
|
||||
}
|
||||
func (s SearchView) ShowChildrenContent() {
|
||||
UI := ui.Ui
|
||||
SearchContentSlice := client.SearchContentSlice
|
||||
if len(client.SearchContentSlice) <= 0 || client.SearchContentSlice == nil {
|
||||
notify.Notify.Send("No Search Results")
|
||||
} else {
|
||||
r, _ := UI.ExpandedView.GetSelection()
|
||||
client.AddToPlaylist(SearchContentSlice[r], true)
|
||||
}
|
||||
}
|
||||
|
||||
func (s SearchView) ShowParentContent() {
|
||||
notify.Notify.Send("Not Allowed in this View")
|
||||
return
|
||||
}
|
||||
|
||||
func (s SearchView) AddToPlaylist() {
|
||||
UI := ui.Ui
|
||||
SearchContentSlice := client.SearchContentSlice
|
||||
if len(client.SearchContentSlice) <= 0 || client.SearchContentSlice == nil {
|
||||
notify.Notify.Send("No Search Results")
|
||||
} else {
|
||||
r, _ := UI.ExpandedView.GetSelection()
|
||||
client.AddToPlaylist(SearchContentSlice[r], false)
|
||||
}
|
||||
}
|
||||
|
||||
func (p SearchView) Quit() {
|
||||
ui.Ui.App.Stop()
|
||||
}
|
||||
|
||||
func (s SearchView) FocusBuffSearchView() {}
|
||||
func (s SearchView) DeleteSongFromPlaylist() {}
|
||||
|
||||
func (s SearchView) Update(inputTable *tview.Table) {
|
||||
inputTable.Clear()
|
||||
c := client.SearchContentSlice
|
||||
_, _, width, _ := inputTable.GetInnerRect()
|
||||
for i, content := range c {
|
||||
switch content.(type) {
|
||||
case [3]string:
|
||||
{
|
||||
inputTable.SetCell(i, 0,
|
||||
GetCell(
|
||||
utils.GetFormattedString(content.([3]string)[0], width/3), tcell.ColorGreen, false))
|
||||
inputTable.SetCell(i, 1,
|
||||
GetCell(
|
||||
utils.GetFormattedString(content.([3]string)[1], width/3), tcell.ColorPurple, false))
|
||||
inputTable.SetCell(i, 2,
|
||||
GetCell(content.([3]string)[2], tcell.ColorYellow, false))
|
||||
}
|
||||
case [2]string:
|
||||
{
|
||||
inputTable.SetCell(i, 0,
|
||||
GetCell(
|
||||
utils.GetFormattedString(content.([2]string)[0], width/3), tcell.ColorYellow, false))
|
||||
inputTable.SetCell(i, 1,
|
||||
GetCell(
|
||||
utils.GetFormattedString(content.([2]string)[1], width/3), tcell.ColorPurple, false))
|
||||
}
|
||||
case string:
|
||||
{
|
||||
b := content.(string)
|
||||
if !strings.HasPrefix(b, client.WHITE_AND_BOLD) {
|
||||
inputTable.SetCell(i, 0,
|
||||
GetCell(content.(string), tcell.ColorPurple, false))
|
||||
} else {
|
||||
inputTable.SetCell(i, 0,
|
||||
GetCell(content.(string), tcell.ColorWhite, true).SetSelectable(false))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
32
views/views.go
Normal file
32
views/views.go
Normal file
@ -0,0 +1,32 @@
|
||||
package views
|
||||
|
||||
import (
|
||||
"github.com/aditya-K2/tview"
|
||||
)
|
||||
|
||||
var (
|
||||
CurrentView View
|
||||
BuffSView BuffSearchView
|
||||
SView SearchView
|
||||
FView FileView
|
||||
PView PlaylistView
|
||||
)
|
||||
|
||||
type View interface {
|
||||
Update(inputTable *tview.Table)
|
||||
ShowChildrenContent()
|
||||
ShowParentContent()
|
||||
AddToPlaylist()
|
||||
Quit()
|
||||
FocusBuffSearchView()
|
||||
DeleteSongFromPlaylist()
|
||||
GetViewName() string
|
||||
}
|
||||
|
||||
func SetCurrentView(v View) {
|
||||
CurrentView = v
|
||||
}
|
||||
|
||||
func GetCurrentView() View {
|
||||
return CurrentView
|
||||
}
|
Loading…
Reference in New Issue
Block a user