Add Zukitchi widget with animated terminal pet and update README for new features

This commit is contained in:
2025-12-30 23:51:54 +01:00
parent dfbc6066c9
commit 7a846ee660
5 changed files with 150 additions and 1 deletions

60
widgets/zukitchi.go Normal file
View File

@@ -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
}

View File

@@ -0,0 +1,79 @@
package zukitchi
import "strings"
func Sleep(position int) []string {
return compileFrames(position, sleep0, sleep1)
}
func compileFrames(position int, idle ...string) []string {
var result = make([]string, len(idle))
for i, frame := range idle {
result[i] = cutFirstAndListLineAndMove(frame, position)
}
return result
}
func cutFirstAndListLineAndMove(frame string, position int) string {
position = position + 17
if position < 0 {
position = 0
}
if position > 35 {
position = 35
}
lines := strings.Split(frame, "\n")
result := make([]string, 0, len(lines))
for _, line := range lines {
result = append(result, strings.Repeat(" ", position)+line)
}
return strings.Join(result[1:len(result)-1], "\n")
}
//<editor-fold desc="Sprites">
// j
// k ▄
// i ▀
// l █
const sleep0 = `
▄▄▄ ▄▄▄
█ █ █ █
▀▄▄▄████▄▄ ▄▄███▄▄▄▀
██▀ ▀▀▄▄▄▄▄▄▄▄███ ▀█▀
██ ▄ ███▄ ▄████▄ ▄▀
██▀▀█▀▀████▀▀█▀▀██▄
█▀▀█████▄███████▄▄█▄▄
▄▄▀▀▀▀█▀▀ █ ▀▀▀▄
█ █ █ █
█ ▄▀▀▀▄▄▄▄█████▀▀▀▀▀█████▄ █
█ █▄▄▄▄█▀▀▀▀▀▀██████ ▀▀▀█ █
█ ██████ ██████ █ █
█ █▀▀▀▀███████ ███▄▄█ █
█ ▀▄▄▄▄███▀▀▀▀▀▀▀▀▀▀██████ █
█ ▀▀▀▀▀ █
█ ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄ █
▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀
`
const sleep1 = `
▄▄▄ ▄▄▄
█ █ █ █
▀▄▄▄█████▀▄▄ ▄▄▄▀████▄▄▄▀
██▄ ███▀▀▀████▀ █▀
██▄█▄████▄██████▄█
███████████████████
▄█▄▀ ▀▀█▄▄
▄▄▀▀ █ █ ▀▀▀▀▄
█ ▄█▄▄▄▄█████▀▀▀▀▀███▄ █
█ ▄▀ ▄█▀▀▀▀▀▀██████ ▀██▄ █
█ █▄████ ██████ ██ █ █
█ ███▀▀███████ ██▄▀▀█ █
█ █▀ ▄██▀▀▀▀▀▀▀▀▀▀▄███ █ █
█ ▀▄▄▀ ▀███ █
█ ▄▄▄▄▄▄▄▄▄▄▄▄▄ ▀ █
█ ▄▄▀▀▀ ▀ █ █ ▀ ▀▀▄▄ █
▀▀▀ ▀▀▀▀
`
//</editor-fold>

1
widgets/zukitchi/main.go Normal file
View File

@@ -0,0 +1 @@
package zukitchi