Add Zukitchi widget with animated terminal pet and update README for new features
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
package widgets
|
||||
|
||||
import (
|
||||
"ArinDash/util"
|
||||
"ArinDash/widgets/zukitchi"
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/mum4k/termdash/cell"
|
||||
"github.com/mum4k/termdash/terminal/terminalapi"
|
||||
"github.com/mum4k/termdash/widgetapi"
|
||||
"github.com/mum4k/termdash/widgets/text"
|
||||
)
|
||||
|
||||
type ZukitchiOptions struct {
|
||||
}
|
||||
|
||||
func Zukitchi() ZukitchiOptions {
|
||||
widgetOptions["ZukitchiOptions"] = createZukitchi
|
||||
return ZukitchiOptions{}
|
||||
|
||||
}
|
||||
|
||||
var mood = make([]string, 0)
|
||||
var frames = 1
|
||||
var frame = 0
|
||||
var lastFrame = time.Now()
|
||||
|
||||
func createZukitchi(ctx context.Context, _ terminalapi.Terminal, _ interface{}) widgetapi.Widget {
|
||||
widget := util.PanicOnErrorWithResult(text.New())
|
||||
changeMood("sleep")
|
||||
go util.Periodic(ctx, util.RedrawInterval, func() error {
|
||||
return draw(widget)
|
||||
})
|
||||
|
||||
return widget
|
||||
}
|
||||
|
||||
func changeMood(moodToChangeTo string) {
|
||||
switch moodToChangeTo {
|
||||
case "sleep":
|
||||
mood = zukitchi.Sleep(0)
|
||||
break
|
||||
}
|
||||
frames = len(mood)
|
||||
frame = 0
|
||||
}
|
||||
|
||||
func draw(widget *text.Text) error {
|
||||
if time.Since(lastFrame) < 1*time.Second {
|
||||
return nil
|
||||
}
|
||||
widget.Reset()
|
||||
if err := widget.Write(mood[frame], text.WriteCellOpts(cell.FgColor(cell.ColorWhite))); err != nil {
|
||||
return err
|
||||
}
|
||||
frame = (frame + 1) % frames
|
||||
lastFrame = time.Now()
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user