mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Hacky timezone display in Status
This commit is contained in:
committed by
Chris Cummer
parent
dd170c0ab3
commit
1bf6efdaf8
20
status/timezones.go
Normal file
20
status/timezones.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package status
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func Timezones(zones []string) []time.Time {
|
||||
times := []time.Time{}
|
||||
|
||||
for _, zone := range zones {
|
||||
loc, err := time.LoadLocation(zone)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
times = append(times, time.Now().In(loc))
|
||||
}
|
||||
|
||||
return times
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package status
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gdamore/tcell"
|
||||
@@ -40,7 +41,12 @@ func (widget *Widget) Refresh() {
|
||||
widget.RefreshedAt = time.Now()
|
||||
|
||||
widget.View.Clear()
|
||||
fmt.Fprintf(widget.View, " %s", widget.contentFrom())
|
||||
fmt.Fprintf(
|
||||
widget.View,
|
||||
"%107s\n%123s",
|
||||
widget.animation(),
|
||||
widget.timezones(),
|
||||
)
|
||||
}
|
||||
|
||||
/* -------------------- Unexported Functions -------------------- */
|
||||
@@ -52,11 +58,12 @@ func (widget *Widget) addView() {
|
||||
view.SetBorderColor(tcell.ColorGray)
|
||||
view.SetDynamicColors(true)
|
||||
view.SetTitle(widget.Name)
|
||||
view.SetWrap(false)
|
||||
|
||||
widget.View = view
|
||||
}
|
||||
|
||||
func (widget *Widget) contentFrom() string {
|
||||
func (widget *Widget) animation() string {
|
||||
icons := []string{"π", "π€", "π€", "π€", "π€", "π€", "β", "π€", "π", "π€"}
|
||||
next := icons[widget.Current]
|
||||
|
||||
@@ -67,3 +74,18 @@ func (widget *Widget) contentFrom() string {
|
||||
|
||||
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]Β ")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user