-
Notifications
You must be signed in to change notification settings - Fork 1
/
icons.go
78 lines (70 loc) · 1.92 KB
/
icons.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main
import (
"fmt"
"log"
"math/rand"
"os"
"path/filepath"
"strings"
aw "github.com/deanishe/awgo"
)
var (
newIcon = &aw.Icon{"icons/new.png", aw.IconTypeImage}
tagIcon = &aw.Icon{"icons/tag.png", aw.IconTypeImage}
collectionIcon = &aw.Icon{"icons/collection.png", aw.IconTypeImage}
languageIcon = &aw.Icon{"icons/language.png", aw.IconTypeImage}
tokenIcon = &aw.Icon{"icons/token.png", aw.IconTypeImage}
starIcon = &aw.Icon{"icons/star.png", aw.IconTypeImage}
forkIcon = &aw.Icon{"icons/forked.png", aw.IconTypeImage}
latestIcon = &aw.Icon{"icons/latest.png", aw.IconTypeImage}
iconAvailable = &aw.Icon{"icons/update-available.png", aw.IconTypeImage}
)
func randomOwnerIcon() *aw.Icon {
iconDir, err := os.Open("./icons/owners")
if err != nil {
log.Fatalf("failed opening directory: %s", err)
}
iconFile, err := iconDir.Readdirnames(0)
n := rand.Intn(len(iconFile))
return &aw.Icon{
Type: aw.IconTypeImage,
Value: fmt.Sprintf("./icons/owners/%s", iconFile[n]),
}
}
func loadIcons() map[string]string {
iconDir, err := os.Open("./icons")
if err != nil {
log.Fatalf("failed opening directory: %s", err)
}
defer iconDir.Close()
iconFile, err := iconDir.Readdirnames(0)
if err != nil {
log.Fatal(err)
}
iconSet = make(map[string]string, len(iconFile))
for _, val := range iconFile {
iconSet[strings.Replace(filepath.Base(val), ".png", "", 1)] = fmt.Sprintf("icons/%s", val)
}
return iconSet
}
func resolveIcon(i interface{}) *aw.Icon {
/*
If it is a language query always
*/
// If it is a language query return that result
if v, ok := iconSet[strings.ToLower(squery.language)]; ok {
return &aw.Icon{Type: aw.IconTypeImage,
Value: v}
}
// Otherwise convert string and return
{
switch t := i.(type) {
case string:
if v, ok := iconSet[strings.ToLower(t)]; ok {
return &aw.Icon{Type: aw.IconTypeImage,
Value: v}
}
}
}
return &aw.Icon{}
}