From ff6dff8a008408751229df4ba159a57b0624d89e Mon Sep 17 00:00:00 2001 From: Caleb Foust Date: Mon, 27 Nov 2023 06:46:35 -0500 Subject: [PATCH] feat: kinda working animations --- README.md | 2 +- cmd/stories/main.go | 4 ++-- docs/storybook.py | 4 ++-- pkg/anim/animation.go | 6 ++++-- pkg/anim/collapse.go | 4 +++- pkg/anim/conway.go | 4 +++- pkg/anim/form.go | 4 +++- pkg/anim/midjo.go | 4 +++- 8 files changed, 21 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 3ce3f96d..e9d561c1 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@

- cy main gif + cy main gif

> the time traveling terminal multiplexer diff --git a/cmd/stories/main.go b/cmd/stories/main.go index 002374e8..d6745d39 100644 --- a/cmd/stories/main.go +++ b/cmd/stories/main.go @@ -113,13 +113,13 @@ func main() { initial := createInitial(geom.DEFAULT_SIZE) for name, animation := range anim.Animations { - func(a anim.Animation) { + func(a anim.Creator) { stories.Register( fmt.Sprintf("animation/%s", name), func(ctx context.Context) mux.Screen { animator := anim.NewAnimator( ctx, - a, + a(), initial.Clone(), 23, ) diff --git a/docs/storybook.py b/docs/storybook.py index 5739c248..27e04989 100644 --- a/docs/storybook.py +++ b/docs/storybook.py @@ -87,9 +87,9 @@ def transform_chapter(chapter): Hide Type "./stories -s {command} && clear" Enter -Sleep 2s +Sleep 500ms Show -Sleep 10s +Sleep 8s """ elif filename.endswith(".png"): script = f""" diff --git a/pkg/anim/animation.go b/pkg/anim/animation.go index 00f914ae..7d61f25e 100644 --- a/pkg/anim/animation.go +++ b/pkg/anim/animation.go @@ -12,6 +12,8 @@ type Animation interface { Update(delta time.Duration) image.Image } +type Creator func() Animation + func RandomAnimation() Animation { anims := []Animation{ &Collapse{}, @@ -23,8 +25,8 @@ func RandomAnimation() Animation { return anims[rand.Int()%len(anims)] } -var Animations = map[string]Animation{} +var Animations = map[string]Creator{} -func registerAnimation(name string, animation Animation) { +func registerAnimation(name string, animation Creator) { Animations[name] = animation } diff --git a/pkg/anim/collapse.go b/pkg/anim/collapse.go index 6cdd4440..09cb4b1b 100644 --- a/pkg/anim/collapse.go +++ b/pkg/anim/collapse.go @@ -47,5 +47,7 @@ func (c *Collapse) Update(delta time.Duration) image.Image { } func init() { - registerAnimation("collapse", &Collapse{}) + registerAnimation("collapse", func() Animation { + return &Collapse{} + }) } diff --git a/pkg/anim/conway.go b/pkg/anim/conway.go index 85a12c8e..4d75ca07 100644 --- a/pkg/anim/conway.go +++ b/pkg/anim/conway.go @@ -96,5 +96,7 @@ func (c *Conway) Update(delta time.Duration) image.Image { } func init() { - registerAnimation("conway", &Conway{}) + registerAnimation("conway", func() Animation { + return &Conway{} + }) } diff --git a/pkg/anim/form.go b/pkg/anim/form.go index d7ce6663..41990fb8 100644 --- a/pkg/anim/form.go +++ b/pkg/anim/form.go @@ -53,5 +53,7 @@ func (c *Cyform) Update(delta time.Duration) image.Image { } func init() { - registerAnimation("cy", &Cyform{}) + registerAnimation("cy", func() Animation { + return &Cyform{} + }) } diff --git a/pkg/anim/midjo.go b/pkg/anim/midjo.go index c0a81993..d4e259d2 100644 --- a/pkg/anim/midjo.go +++ b/pkg/anim/midjo.go @@ -46,5 +46,7 @@ func (mid *Midjo) Update(delta time.Duration) image.Image { } func init() { - registerAnimation("midjo", &Midjo{}) + registerAnimation("midjo", func() Animation { + return &Midjo{} + }) }