1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00
wtf/status/widget.go
2018-04-12 12:00:11 -07:00

92 lines
1.6 KiB
Go
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package status
import (
"fmt"
"strings"
"time"
"github.com/gdamore/tcell"
"github.com/olebedev/config"
"github.com/rivo/tview"
"github.com/senorprogrammer/wtf/wtf"
)
var Config *config.Config
type Widget struct {
wtf.TextWidget
Current int
}
func NewWidget() *Widget {
widget := Widget{
TextWidget: wtf.NewTextWidget("Status", "status"),
Current: 0,
}
widget.addView()
return &widget
}
/* -------------------- Exported Functions -------------------- */
func (widget *Widget) Refresh() {
if widget.Disabled() {
return
}
widget.View.SetTitle(" 🎉 Status ")
widget.RefreshedAt = time.Now()
widget.View.Clear()
fmt.Fprintf(
widget.View,
"%107s\n%123s",
widget.animation(),
widget.timezones(),
)
}
/* -------------------- Unexported Functions -------------------- */
func (widget *Widget) addView() {
view := tview.NewTextView()
view.SetBorder(true)
view.SetBorderColor(tcell.ColorGray)
view.SetDynamicColors(true)
view.SetTitle(widget.Name)
view.SetWrap(false)
widget.View = view
}
func (widget *Widget) animation() string {
icons := []string{"👍", "🤜", "🤙", "🤜", "🤘", "🤜", "✊", "🤜", "👌", "🤜"}
next := icons[widget.Current]
widget.Current = widget.Current + 1
if widget.Current == len(icons) {
widget.Current = 0
}
return next
}
func (widget *Widget) timezones() string {
times := Timezones(wtf.ToStrs(Config.UList("wtf.mods.status.timezones")))
if len(times) == 0 {
return ""
}
formattedTimes := []string{}
for _, time := range times {
formattedTimes = append(formattedTimes, time.Format(wtf.TimeFormat))
}
return strings.Join(formattedTimes, " [yellow]•[white] ")
}