-
Notifications
You must be signed in to change notification settings - Fork 2
/
view_search.go
124 lines (114 loc) · 2.86 KB
/
view_search.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package ui
import (
"fmt"
"strings"
"github.com/aditya-K2/gomp/client"
"github.com/aditya-K2/utils"
"github.com/aditya-K2/tview"
)
type SearchView struct {
}
func addToPlaylist(a interface{}, addAndPlay bool) {
switch a.(type) {
case [3]string:
{
b := a.([3]string)
if err := client.AddTitle(b[0], addAndPlay); err != nil {
SendNotification(err.Error())
} else {
SendNotification(fmt.Sprintf(
"%s Added Succesfully!", b[0]))
}
}
case [2]string:
{
b := a.([2]string)
if err := client.AddAlbum(b[0]); err != nil {
SendNotification(err.Error())
} else {
SendNotification(fmt.Sprintf(
"%s Added Succesfully!", b[0]))
}
}
case string:
{
b := a.(string)
if err := client.AddArtist(b); err != nil {
SendNotification(err.Error())
} else {
SendNotification(fmt.Sprintf(
"%s Added Succesfully!", b))
}
}
}
}
func (s SearchView) Name() string {
return "SearchView"
}
func (s SearchView) ShowChildrenContent() {
SearchContentSlice := client.SearchContentSlice
if len(client.SearchContentSlice) <= 0 || client.SearchContentSlice == nil {
SendNotification("No Search Results")
} else {
r, _ := Ui.MainS.GetSelection()
addToPlaylist(SearchContentSlice[r], true)
}
}
func (s SearchView) ShowParentContent() {
SendNotification("Not Allowed in this View")
return
}
func (s SearchView) AddToPlaylist() {
SearchContentSlice := client.SearchContentSlice
if len(client.SearchContentSlice) <= 0 || client.SearchContentSlice == nil {
SendNotification("No Search Results")
} else {
r, _ := Ui.MainS.GetSelection()
addToPlaylist(SearchContentSlice[r], false)
}
}
func (p SearchView) Quit() {
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), clr.Track))
inputTable.SetCell(i, 1,
GetCell(
utils.GetFormattedString(content.([3]string)[1], width/3), clr.Artist))
inputTable.SetCell(i, 2,
GetCell(content.([3]string)[2], clr.Album))
}
case [2]string:
{
inputTable.SetCell(i, 0,
GetCell(
utils.GetFormattedString(content.([2]string)[0], width/3), clr.Album))
inputTable.SetCell(i, 1,
GetCell(
utils.GetFormattedString(content.([2]string)[1], width/3), clr.Artist))
}
case string:
{
b := content.(string)
if !strings.HasPrefix(b, client.WHITE_AND_BOLD) {
inputTable.SetCell(i, 0,
GetCell(content.(string), clr.Artist))
} else {
inputTable.SetCell(i, 0,
GetCell(content.(string), clr.Null).SetSelectable(false))
}
}
}
}
}