forked from wtfutil/wtf
/
widget.go
59 lines (46 loc) · 1.11 KB
/
widget.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
package twitterstats
import (
"fmt"
"github.com/rivo/tview"
"github.com/wtfutil/wtf/view"
)
type Widget struct {
view.TextWidget
client *Client
settings *Settings
}
func NewWidget(tviewApp *tview.Application, redrawChan chan bool, _ *tview.Pages, settings *Settings) *Widget {
widget := Widget{
TextWidget: view.NewTextWidget(tviewApp, redrawChan, nil, settings.Common),
client: NewClient(settings),
settings: settings,
}
widget.View.SetBorderPadding(1, 1, 1, 1)
widget.View.SetWrap(false)
widget.View.SetWordWrap(true)
return &widget
}
func (widget *Widget) Refresh() {
widget.Redraw(widget.content)
}
func (widget *Widget) content() (string, string, bool) {
// Add header row
str := fmt.Sprintf(
"[%s]%-12s %10s %8s[white]\n",
widget.settings.Colors.Subheading,
"Username",
"Followers",
"Tweets",
)
stats := widget.client.GetStats()
// Add rows for each of the followed usernames
for i, username := range widget.client.screenNames {
str += fmt.Sprintf(
"%-12s %10d %8d\n",
username,
stats[i].FollowerCount,
stats[i].TweetCount,
)
}
return "Twitter Stats", str, false
}