2021-12-25 11:48:23 -07:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/aditya-K2/fuzzy"
|
|
|
|
"github.com/aditya-K2/gomp/utils"
|
|
|
|
"github.com/aditya-K2/tview"
|
2021-12-29 09:52:34 -07:00
|
|
|
"github.com/gdamore/tcell/v2"
|
2021-12-25 11:48:23 -07:00
|
|
|
)
|
|
|
|
|
2021-12-30 06:03:39 -07:00
|
|
|
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))
|
|
|
|
}
|
|
|
|
|
2021-12-25 11:48:23 -07:00
|
|
|
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 {
|
2021-12-30 06:03:39 -07:00
|
|
|
inputTable.SetCell(k, 0,
|
|
|
|
GetCell(
|
|
|
|
utils.GetMatchedString(
|
|
|
|
utils.Unique(v.MatchedIndexes), f[v.Index].Path, "[blue:-:bi]"),
|
|
|
|
tcell.ColorYellow, true))
|
2021-12-25 11:48:23 -07:00
|
|
|
} else {
|
2021-12-30 06:03:39 -07:00
|
|
|
inputTable.SetCell(k, 0,
|
|
|
|
GetCell(
|
|
|
|
utils.GetMatchedString(
|
|
|
|
utils.Unique(v.MatchedIndexes), f[v.Index].Title, "[yellow:-:bi]"),
|
|
|
|
tcell.ColorGreen, true))
|
2021-12-25 11:48:23 -07:00
|
|
|
}
|
|
|
|
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"] == "" {
|
2021-12-30 06:03:39 -07:00
|
|
|
inputTable.SetCell(i, 0,
|
|
|
|
GetCell(
|
|
|
|
utils.GetFormattedString(j["file"], w/3), tcell.ColorBlue, true))
|
2021-12-29 09:52:34 -07:00
|
|
|
|
2021-12-25 11:48:23 -07:00
|
|
|
} else {
|
2021-12-30 06:03:39 -07:00
|
|
|
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))
|
2021-12-25 11:48:23 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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:
|
|
|
|
{
|
2021-12-30 06:03:39 -07:00
|
|
|
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))
|
2021-12-25 11:48:23 -07:00
|
|
|
}
|
|
|
|
case [2]string:
|
|
|
|
{
|
2021-12-30 06:03:39 -07:00
|
|
|
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))
|
2021-12-25 11:48:23 -07:00
|
|
|
}
|
|
|
|
case string:
|
|
|
|
{
|
|
|
|
b := content.(string)
|
|
|
|
if !strings.HasPrefix(b, WHITE_AND_BOLD) {
|
2021-12-30 06:03:39 -07:00
|
|
|
inputTable.SetCell(i, 0,
|
|
|
|
GetCell(content.(string), tcell.ColorPurple, false))
|
2021-12-25 11:48:23 -07:00
|
|
|
} else {
|
2021-12-30 06:03:39 -07:00
|
|
|
inputTable.SetCell(i, 0,
|
|
|
|
GetCell(content.(string), tcell.ColorWhite, true).SetSelectable(false))
|
2021-12-25 11:48:23 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
2021-12-30 06:03:39 -07:00
|
|
|
GetCell(
|
|
|
|
utils.GetFormattedString(_songAttributes[0]["Title"], w/3), tcell.ColorGreen, false))
|
2021-12-25 11:48:23 -07:00
|
|
|
|
|
|
|
inputTable.SetCell(i, 1,
|
2021-12-30 06:03:39 -07:00
|
|
|
GetCell(
|
|
|
|
utils.GetFormattedString(_songAttributes[0]["Artist"], w/3), tcell.ColorPurple, false))
|
2021-12-25 11:48:23 -07:00
|
|
|
inputTable.SetCell(i, 2,
|
2021-12-30 06:03:39 -07:00
|
|
|
GetCell(_songAttributes[0]["Album"], tcell.ColorYellow, false))
|
2021-12-25 11:48:23 -07:00
|
|
|
|
|
|
|
} else if _songAttributes[0]["Title"] == "" {
|
|
|
|
inputTable.SetCell(i, 0,
|
2021-12-30 06:03:39 -07:00
|
|
|
GetCell(j.Path, tcell.ColorBlue, true))
|
2021-12-25 11:48:23 -07:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
inputTable.SetCell(i, 0,
|
2021-12-30 06:03:39 -07:00
|
|
|
GetCell(j.Path, tcell.ColorYellow, true))
|
2021-12-25 11:48:23 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|