1fa411fb1d
There are two ways the information is shown if the Node is a directory then the relativePath is shown else the attributes of the song are shown. For this Layout ( song attributes ) We can divide the Screen three Part | Title | Artist | Album | | | | | | | | | | | | | | | | | ~~~~~~~~~~~~~ Screen Width ~~~~~~~~~~~~~~~~~~~~~~ if the length of each of the attribute is less than ( Screen Width / 3 ) then we can add spaces to the end else we can shorten the string to fit into the screen width this functionality is done with the help of `getFormattedString()`
89 lines
2.3 KiB
Go
89 lines
2.3 KiB
Go
package main
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/fhs/gompd/mpd"
|
|
// "github.com/gdamore/tcell/v2"
|
|
"github.com/rivo/tview"
|
|
// "fmt"
|
|
)
|
|
|
|
func getFormattedString(s string, width int) string {
|
|
if len(s) < width {
|
|
s += strings.Repeat(" ", (width - len(s)))
|
|
} else {
|
|
s = s[:(width - 2)]
|
|
s += " "
|
|
}
|
|
return s
|
|
}
|
|
|
|
func togglePlayBack(connection mpd.Client) error {
|
|
status, err := connection.Status()
|
|
if status["state"] == "play" && err == nil {
|
|
connection.Pause(true)
|
|
} else if status["state"] == "pause" && err == nil {
|
|
connection.Play(-1)
|
|
}
|
|
return err
|
|
}
|
|
|
|
func UpdatePlaylist(conn mpd.Client, t *tview.Table) {
|
|
_playlistAttr, _ := conn.PlaylistInfo(-1, -1)
|
|
|
|
t.Clear()
|
|
for i, j := range _playlistAttr {
|
|
_, _, w, _ := t.GetInnerRect()
|
|
if j["Title"] == "" || j["Artist"] == "" || j["Album"] == "" {
|
|
t.SetCell(i, 0, tview.NewTableCell(getFormattedString(j["file"], w/3)))
|
|
} else {
|
|
t.SetCell(i, 0, tview.NewTableCell(getFormattedString("[green]"+j["Title"], w/3)))
|
|
t.SetCell(i, 1, tview.NewTableCell(getFormattedString("[magenta]"+j["Artist"], w/3)))
|
|
t.SetCell(i, 2, tview.NewTableCell("[yellow]"+j["Album"]))
|
|
}
|
|
}
|
|
}
|
|
|
|
func join(stringSlice []string) string {
|
|
var _s string = stringSlice[0]
|
|
for i := 1; i < len(stringSlice); i++ {
|
|
if _s != "" {
|
|
_s += ("/" + stringSlice[i])
|
|
}
|
|
}
|
|
return _s
|
|
}
|
|
|
|
func Update(conn mpd.Client, 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,
|
|
tview.NewTableCell("[#fbff00]"+getFormattedString(_songAttributes[0]["Title"], w/3)).
|
|
SetAlign(tview.AlignLeft))
|
|
|
|
inputTable.SetCell(i, 1,
|
|
tview.NewTableCell("[#fbff00]"+getFormattedString(_songAttributes[0]["Artist"], w/3)).
|
|
SetAlign(tview.AlignLeft))
|
|
|
|
inputTable.SetCell(i, 2,
|
|
tview.NewTableCell("[#ff0030]"+_songAttributes[0]["Album"]).
|
|
SetAlign(tview.AlignLeft))
|
|
|
|
} else if _songAttributes[0]["Title"] == "" {
|
|
inputTable.SetCell(i, 0,
|
|
tview.NewTableCell("[blue]"+j.path).
|
|
SetAlign(tview.AlignLeft))
|
|
}
|
|
} else {
|
|
inputTable.SetCell(i, 0,
|
|
tview.NewTableCell("[#fbff00::b]"+j.path).
|
|
SetAlign(tview.AlignLeft))
|
|
}
|
|
}
|
|
}
|