-
Notifications
You must be signed in to change notification settings - Fork 1
/
templates.go
33 lines (29 loc) · 989 Bytes
/
templates.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package main
import (
"github.com/aqatl/mal/mal"
"math"
"text/template"
)
const PrettyListTemplate = `No{{printf "%57s" "Title"}}{{printf "%8s" "Eps"}}{{printf "%6s" "Score"}}{{printf "%7s" "ID"}}
================================================================================{{range $index, $var := .List}}
{{if eq .ID $.SelectedID}}{{"\033[93;1m"}}{{end}}{{len $.List | minus $index | abs | printf "%2d"}}{{.Title | printf " %56.56s"}}{{printf "%d/%d" .WatchedEpisodes .Episodes | printf "%8s"}}{{.MyScore | printf "%6d"}}{{.ID | printf "%7d"}}{{if eq .ID $.SelectedID}}{{"\033[0m "}}{{end}}{{end}}
`
var PrettyList = template.Must(
template.New("prettyList").
Funcs(template.FuncMap{
"plus": func(a, b int) int {
return a + b
},
"minus": func(a, b int) int {
return a - b
},
"abs": func(a int) int {
return int(math.Abs(float64(a)))
},
}).
Parse(PrettyListTemplate),
)
type PrettyListData struct {
List []*mal.Anime
SelectedID int
}