refactor: Minor Formatting Changes and Refactoring

This commit is contained in:
aditya-K2 2021-12-30 18:33:39 +05:30
parent 4a0a3e18f7
commit 010f2473ca

View File

@ -9,6 +9,15 @@ import (
"github.com/gdamore/tcell/v2" "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) { func UpdateBuffSearchView(inputTable *tview.Table, m fuzzy.Matches, f []FileNode) {
inputTable.Clear() inputTable.Clear()
if m == nil || len(m) == 0 { if m == nil || len(m) == 0 {
@ -16,19 +25,17 @@ func UpdateBuffSearchView(inputTable *tview.Table, m fuzzy.Matches, f []FileNode
} else { } else {
for k, v := range m { for k, v := range m {
if len(f[v.Index].Children) != 0 { if len(f[v.Index].Children) != 0 {
inputTable.SetCell(k, 0, tview.NewTableCell(utils.GetMatchedString(utils.Unique(v.MatchedIndexes), f[v.Index].Path, "[blue:-:bi]")). inputTable.SetCell(k, 0,
SetAlign(tview.AlignLeft). GetCell(
SetStyle(tcell.StyleDefault. utils.GetMatchedString(
Foreground(tcell.ColorYellow). utils.Unique(v.MatchedIndexes), f[v.Index].Path, "[blue:-:bi]"),
Background(tcell.ColorBlack). tcell.ColorYellow, true))
Bold(true)))
} else { } else {
inputTable.SetCell(k, 0, tview.NewTableCell(utils.GetMatchedString(utils.Unique(v.MatchedIndexes), f[v.Index].Title, "[yellow:-:bi]")). inputTable.SetCell(k, 0,
SetAlign(tview.AlignLeft). GetCell(
SetStyle(tcell.StyleDefault. utils.GetMatchedString(
Foreground(tcell.ColorGreen). utils.Unique(v.MatchedIndexes), f[v.Index].Title, "[yellow:-:bi]"),
Background(tcell.ColorBlack). tcell.ColorGreen, true))
Bold(true)))
} }
if k == 15 { if k == 15 {
break break
@ -44,29 +51,19 @@ func UpdatePlaylist(inputTable *tview.Table) {
for i, j := range _playlistAttr { for i, j := range _playlistAttr {
_, _, w, _ := inputTable.GetInnerRect() _, _, w, _ := inputTable.GetInnerRect()
if j["Title"] == "" || j["Artist"] == "" || j["Album"] == "" { if j["Title"] == "" || j["Artist"] == "" || j["Album"] == "" {
inputTable.SetCell(i, 0, tview.NewTableCell(utils.GetFormattedString(j["file"], w/3)). inputTable.SetCell(i, 0,
SetAlign(tview.AlignLeft). GetCell(
SetStyle(tcell.StyleDefault. utils.GetFormattedString(j["file"], w/3), tcell.ColorBlue, true))
Foreground(tcell.ColorBlue).
Background(tcell.ColorBlack).
Bold(true)))
} else { } else {
inputTable.SetCell(i, 0, tview.NewTableCell(utils.GetFormattedString(j["Title"], w/3)). inputTable.SetCell(i, 0,
SetAlign(tview.AlignLeft). GetCell(
SetStyle(tcell.StyleDefault. utils.GetFormattedString(j["Title"], w/3), tcell.ColorGreen, false))
Foreground(tcell.ColorGreen). inputTable.SetCell(i, 1,
Background(tcell.ColorBlack))) GetCell(
inputTable.SetCell(i, 1, tview.NewTableCell(utils.GetFormattedString(j["Artist"], w/3)). utils.GetFormattedString(j["Artist"], w/3), tcell.ColorPurple, false))
SetAlign(tview.AlignLeft). inputTable.SetCell(i, 2,
SetStyle(tcell.StyleDefault. GetCell(j["Album"], tcell.ColorYellow, false))
Foreground(tcell.ColorPurple).
Background(tcell.ColorBlack)))
inputTable.SetCell(i, 2, tview.NewTableCell(j["Album"]).
SetAlign(tview.AlignLeft).
SetStyle(tcell.StyleDefault.
Foreground(tcell.ColorYellow).
Background(tcell.ColorBlack)))
} }
} }
} }
@ -81,46 +78,33 @@ func UpdateSearchView(inputTable *tview.Table, c []interface{}) {
switch content.(type) { switch content.(type) {
case [3]string: case [3]string:
{ {
inputTable.SetCell(i, 0, tview.NewTableCell(utils.GetFormattedString(content.([3]string)[0], width/3)). inputTable.SetCell(i, 0,
SetAlign(tview.AlignLeft). GetCell(
SetStyle(tcell.StyleDefault. utils.GetFormattedString(content.([3]string)[0], width/3), tcell.ColorGreen, false))
Foreground(tcell.ColorGreen). inputTable.SetCell(i, 1,
Background(tcell.ColorBlack))) GetCell(
inputTable.SetCell(i, 1, tview.NewTableCell(utils.GetFormattedString(content.([3]string)[1], width/3)). utils.GetFormattedString(content.([3]string)[1], width/3), tcell.ColorPurple, false))
SetAlign(tview.AlignLeft). inputTable.SetCell(i, 2,
SetStyle(tcell.StyleDefault. GetCell(content.([3]string)[2], tcell.ColorYellow, false))
Foreground(tcell.ColorPurple).
Background(tcell.ColorBlack)))
inputTable.SetCell(i, 2, tview.NewTableCell(utils.GetFormattedString(content.([3]string)[2], width/3)).
SetAlign(tview.AlignLeft).
SetStyle(tcell.StyleDefault.
Foreground(tcell.ColorYellow).
Background(tcell.ColorBlack)))
} }
case [2]string: case [2]string:
{ {
inputTable.SetCell(i, 0, tview.NewTableCell(utils.GetFormattedString(content.([2]string)[0], width/3)). inputTable.SetCell(i, 0,
SetAlign(tview.AlignLeft). GetCell(
SetStyle(tcell.StyleDefault. utils.GetFormattedString(content.([2]string)[0], width/3), tcell.ColorYellow, false))
Foreground(tcell.ColorYellow). inputTable.SetCell(i, 1,
Background(tcell.ColorBlack))) GetCell(
inputTable.SetCell(i, 1, tview.NewTableCell(utils.GetFormattedString(content.([2]string)[1], width/3)). utils.GetFormattedString(content.([2]string)[1], width/3), tcell.ColorPurple, false))
SetAlign(tview.AlignLeft).
SetStyle(tcell.StyleDefault.
Foreground(tcell.ColorPurple).
Background(tcell.ColorBlack)))
} }
case string: case string:
{ {
b := content.(string) b := content.(string)
if !strings.HasPrefix(b, WHITE_AND_BOLD) { if !strings.HasPrefix(b, WHITE_AND_BOLD) {
inputTable.SetCell(i, 0, tview.NewTableCell(content.(string)). inputTable.SetCell(i, 0,
SetAlign(tview.AlignLeft). GetCell(content.(string), tcell.ColorPurple, false))
SetStyle(tcell.StyleDefault.
Foreground(tcell.ColorPurple).
Background(tcell.ColorBlack)))
} else { } else {
inputTable.SetCell(i, 0, tview.NewTableCell(content.(string)).SetSelectable(false)) inputTable.SetCell(i, 0,
GetCell(content.(string), tcell.ColorWhite, true).SetSelectable(false))
} }
} }
} }
@ -135,43 +119,22 @@ func Update(f []FileNode, inputTable *tview.Table) {
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,
tview.NewTableCell(utils.GetFormattedString(_songAttributes[0]["Title"], w/3)). GetCell(
SetAlign(tview.AlignLeft). utils.GetFormattedString(_songAttributes[0]["Title"], w/3), tcell.ColorGreen, false))
SetStyle(tcell.StyleDefault.
Foreground(tcell.ColorGreen).
Background(tcell.ColorBlack)))
inputTable.SetCell(i, 1, inputTable.SetCell(i, 1,
tview.NewTableCell(utils.GetFormattedString(_songAttributes[0]["Artist"], w/3)). GetCell(
SetAlign(tview.AlignLeft). utils.GetFormattedString(_songAttributes[0]["Artist"], w/3), tcell.ColorPurple, false))
SetStyle(tcell.StyleDefault.
Foreground(tcell.ColorPurple).
Background(tcell.ColorBlack)))
inputTable.SetCell(i, 2, inputTable.SetCell(i, 2,
tview.NewTableCell(_songAttributes[0]["Album"]). GetCell(_songAttributes[0]["Album"], tcell.ColorYellow, false))
SetAlign(tview.AlignLeft).
SetStyle(tcell.StyleDefault.
Foreground(tcell.ColorYellow).
Background(tcell.ColorBlack)))
} else if _songAttributes[0]["Title"] == "" { } else if _songAttributes[0]["Title"] == "" {
inputTable.SetCell(i, 0, inputTable.SetCell(i, 0,
tview.NewTableCell(j.Path). GetCell(j.Path, tcell.ColorBlue, true))
SetAlign(tview.AlignLeft).
SetStyle(tcell.StyleDefault.
Foreground(tcell.ColorBlue).
Background(tcell.ColorBlack).
Bold(true)))
} }
} else { } else {
inputTable.SetCell(i, 0, inputTable.SetCell(i, 0,
tview.NewTableCell(j.Path). GetCell(j.Path, tcell.ColorYellow, true))
SetAlign(tview.AlignLeft).
SetStyle(tcell.StyleDefault.
Foreground(tcell.ColorYellow).
Background(tcell.ColorBlack).
Bold(true)))
} }
} }
} }