-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
profile.go
95 lines (77 loc) · 1.62 KB
/
profile.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package tui
import (
"fmt"
"math"
// "time"
// "context"
"html"
strip "github.com/grokify/html-strip-tags-go"
"github.com/mattn/go-runewidth"
// "image/color"
// "github.com/eliukblau/pixterm/pkg/ansimage"
"github.com/mattn/go-mastodon"
// "github.com/mrusme/gomphotherium/mast"
)
func RenderProfile(
profile *mastodon.Account,
width int,
showImages bool) (string, error) {
var output string = ""
var err error = nil
account := profile.Acct
if account == "" {
account = profile.Username
}
bot := ""
if profile.Bot == true {
bot = "\xF0\x9F\xA4\x96"
}
output = fmt.Sprintf("%s[blue]%s[-] [grey]%s[-] [red]%s[-]\n%s\n\n",
output,
profile.DisplayName,
account,
bot,
runewidth.Truncate(
html.UnescapeString(strip.StripTags(profile.Note)),
width,
"...",
),
)
halfwidth := int(math.Floor(float64(width)))
fieldsNumber := len(profile.Fields)
if fieldsNumber > 4 {
fieldsNumber = 4
}
for i := 0; i < fieldsNumber; i++ {
field := profile.Fields[i]
output = fmt.Sprintf("%s[grey]%s:[-] [purple]%s[-]\n",
output,
runewidth.Truncate(
field.Name,
halfwidth,
"...",
),
runewidth.Truncate(
html.UnescapeString(strip.StripTags(field.Value)),
halfwidth,
"...",
),
)
}
for i := fieldsNumber; i < 4; i++ {
output = fmt.Sprintf("%s\n", output)
}
output = fmt.Sprintf("%s[blue]%d[-] [grey]toots[-] ",
output,
profile.StatusesCount,
)
output = fmt.Sprintf("%s[blue]%d[-] [grey]followers[-] ",
output,
profile.FollowersCount,
)
output = fmt.Sprintf("%s[blue]%d[-] [grey]following[-] ",
output,
profile.FollowingCount,
)
return output, err
}