github.com/wtfutil/wtf@v0.43.0/modules/twitterstats/widget.go (about) 1 package twitterstats 2 3 import ( 4 "fmt" 5 6 "github.com/rivo/tview" 7 "github.com/wtfutil/wtf/view" 8 ) 9 10 type Widget struct { 11 view.TextWidget 12 13 client *Client 14 settings *Settings 15 } 16 17 func NewWidget(tviewApp *tview.Application, redrawChan chan bool, _ *tview.Pages, settings *Settings) *Widget { 18 widget := Widget{ 19 TextWidget: view.NewTextWidget(tviewApp, redrawChan, nil, settings.Common), 20 21 client: NewClient(settings), 22 settings: settings, 23 } 24 25 widget.View.SetBorderPadding(1, 1, 1, 1) 26 widget.View.SetWrap(false) 27 widget.View.SetWordWrap(true) 28 29 return &widget 30 } 31 32 func (widget *Widget) Refresh() { 33 widget.Redraw(widget.content) 34 } 35 36 func (widget *Widget) content() (string, string, bool) { 37 // Add header row 38 str := fmt.Sprintf( 39 "[%s]%-12s %10s %8s[white]\n", 40 widget.settings.Colors.Subheading, 41 "Username", 42 "Followers", 43 "Tweets", 44 ) 45 46 stats := widget.client.GetStats() 47 48 // Add rows for each of the followed usernames 49 for i, username := range widget.client.screenNames { 50 str += fmt.Sprintf( 51 "%-12s %10d %8d\n", 52 username, 53 stats[i].FollowerCount, 54 stats[i].TweetCount, 55 ) 56 } 57 58 return "Twitter Stats", str, false 59 }