improved printing results
This commit is contained in:
@@ -5,41 +5,53 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"gitea.elara.ws/Hazel/music-kraken/internal/data"
|
||||
"gitea.elara.ws/Hazel/music-kraken/internal/plugin"
|
||||
)
|
||||
|
||||
func zeroPad(num int, length int) string {
|
||||
str := strconv.Itoa(num)
|
||||
if len(str) >= length {
|
||||
return str
|
||||
}
|
||||
return strings.Repeat("0", length-len(str)) + str
|
||||
}
|
||||
|
||||
func printResults(musicObjects []data.MusicObject) {
|
||||
if len(musicObjects) <= 0 {
|
||||
return
|
||||
}
|
||||
|
||||
for _, m := range musicObjects {
|
||||
if a, ok := m.(data.Artist); ok {
|
||||
fmt.Print("#a " + a.Name)
|
||||
results := make([]string, len(musicObjects))
|
||||
|
||||
for i, m := range musicObjects {
|
||||
results[i] = zeroPad(i, 2) + ": "
|
||||
|
||||
if a, ok := m.(data.Artist); ok {
|
||||
results[i] += "#a " + a.Name
|
||||
} else if a, ok := m.(data.Album); ok {
|
||||
fmt.Print("#r " + a.Name)
|
||||
results[i] += "#r " + a.Name
|
||||
|
||||
for _, artist := range a.Artists {
|
||||
fmt.Print(" - " + artist.Name)
|
||||
results[i] += " - " + artist.Name
|
||||
}
|
||||
} else if a, ok := m.(data.Song); ok {
|
||||
fmt.Print("#s " + a.Name)
|
||||
results[i] += "#s " + a.Name
|
||||
|
||||
if a.Album.Name != "" {
|
||||
fmt.Print(" - " + a.Album.Name)
|
||||
results[i] += " - " + a.Album.Name
|
||||
}
|
||||
|
||||
for _, artist := range a.Artists {
|
||||
fmt.Print(" - " + artist.Name)
|
||||
results[i] += " - " + artist.Name
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
fmt.Println(strings.Join(results, "\n"))
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user