diff --git a/go.mod b/go.mod index 8f9d979..851595e 100644 --- a/go.mod +++ b/go.mod @@ -9,8 +9,13 @@ require ( git.milar.in/milarin/envvars/v2 v2.0.0 git.milar.in/milarin/gmath v0.0.3 git.milar.in/milarin/slices v0.0.6 + git.milar.in/milarin/tprint v0.0.7 git.milar.in/nyaanime/model v0.0.0-20230113095840-5eb2822653c3 git.milar.in/nyaanime/parsers v0.0.0-20221207192513-e7bce7c418d8 ) -require gopkg.in/vansante/go-ffprobe.v2 v2.1.1 // indirect +require ( + github.com/mattn/go-runewidth v0.0.13 // indirect + github.com/rivo/uniseg v0.3.4 // indirect + gopkg.in/vansante/go-ffprobe.v2 v2.1.1 // indirect +) diff --git a/go.sum b/go.sum index 1e22c8c..6d50ff1 100644 --- a/go.sum +++ b/go.sum @@ -10,9 +10,16 @@ git.milar.in/milarin/gmath v0.0.3 h1:ii6rKNItS55O/wtIFhD1cTN2BMwDZjTBmiOocKURvxM git.milar.in/milarin/gmath v0.0.3/go.mod h1:HDLftG5RLpiNGKiIWh+O2G1PYkNzyLDADO8Cd/1abiE= git.milar.in/milarin/slices v0.0.6 h1:AQoSarZ58WHYol9c6woWJSe8wFpPC2RC4cvIlZpfg9s= git.milar.in/milarin/slices v0.0.6/go.mod h1:NOr53AOeur/qscu/FBj3lsFR262PNYBccLYSTCAXRk4= +git.milar.in/milarin/tprint v0.0.7 h1:dvm4l4BhXOie4vtnRMZii0WTLTz2wju8wyUPB/lNeVo= +git.milar.in/milarin/tprint v0.0.7/go.mod h1:UwW/B+0cTCbN5hi0bQBE9rIRgLkq+x4V751rrS2KVoI= git.milar.in/nyaanime/model v0.0.0-20230113095840-5eb2822653c3 h1:mXcEA47FQQzeSDXE3UvhNfIt4fBfpDSq1/f0r+jbHpY= git.milar.in/nyaanime/model v0.0.0-20230113095840-5eb2822653c3/go.mod h1:kPWLDvFrhc1Uf77gxsBOxNeJ5JTVF2HhVs1IdVcw0tg= git.milar.in/nyaanime/parsers v0.0.0-20221207192513-e7bce7c418d8 h1:vb7jasvTdan0E8VY5snnRj1Xe+60NA7Lpn+GSYE6pW0= git.milar.in/nyaanime/parsers v0.0.0-20221207192513-e7bce7c418d8/go.mod h1:GG4vtUIfxopZc/+Y8OAa//vWJw/m6aeoGN7fw6SLiEM= +github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= +github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +github.com/rivo/uniseg v0.3.4 h1:3Z3Eu6FGHZWSfNKJTOUiPatWwfc7DzJRU04jFUqJODw= +github.com/rivo/uniseg v0.3.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= gopkg.in/vansante/go-ffprobe.v2 v2.1.1 h1:DIh5fMn+tlBvG7pXyUZdemVmLdERnf2xX6XOFF+0BBU= gopkg.in/vansante/go-ffprobe.v2 v2.1.1/go.mod h1:qF0AlAjk7Nqzqf3y333Ly+KxN3cKF2JqA3JT5ZheUGE= diff --git a/utils.go b/utils.go index 51221ff..141a1c2 100644 --- a/utils.go +++ b/utils.go @@ -1,10 +1,13 @@ package logic import ( + "sort" "strings" "git.milar.in/milarin/anilist" "git.milar.in/milarin/slices" + "git.milar.in/milarin/tprint" + "git.milar.in/nyaanime/model" ) var AllMediaListStatuses = []anilist.MediaListStatus{ @@ -29,3 +32,19 @@ func ParseMediaListStatus(str string) (anilist.MediaListStatus, error) { return s, nil } + +func Map2Table[K comparable](title string, m map[K]int) string { + table := tprint.NewTable(title, "priority") + + entries := make([]model.Pair[K, int], 0, len(m)) + for name, priority := range m { + entries = append(entries, model.Pair[K, int]{First: name, Second: priority}) + } + sort.Slice(entries, func(i, j int) bool { return entries[i].Second > entries[j].Second }) + + for _, entry := range entries { + table.AddRow(entry.First, entry.Second) + } + + return table.String() +}