From f08be9fdbd634ba483f6c8dfdbfb0b7d15c145d6 Mon Sep 17 00:00:00 2001 From: Caleb Foust Date: Sun, 5 Nov 2023 19:46:00 -0500 Subject: [PATCH] feat: actions command palette --- pkg/cy/cy-boot.janet | 21 +++++++++++++-------- pkg/cy/janet.go | 4 ---- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/pkg/cy/cy-boot.janet b/pkg/cy/cy-boot.janet index 98b200d0..743e9b34 100644 --- a/pkg/cy/cy-boot.janet +++ b/pkg/cy/cy-boot.janet @@ -3,12 +3,22 @@ (def projects (group/new (tree/root) :name "projects")) (def shells (group/new (tree/root) :name "shells")) +(def- actions @[]) + (defmacro key/def "register an action" [name docstring & body] ~(upscope (def ,name (fn ,name [&] ,;body)) - (,key/new ,docstring ,name))) + (,array/push actions [,docstring ,name]))) + +(key/def + cy/command-palette + "open command palette" + (-?>> + actions + (fzf/find) + (apply))) (key/def ot/new-shell @@ -115,13 +125,13 @@ (key/bind :root [prefix "l"] ot/jump-shell) (key/bind :root ["ctrl+l"] ot/next-pane) +(key/bind :root [prefix "ctrl+p"] cy/command-palette) (key/bind :root [prefix "x"] cy/kill-current-pane) (key/bind :root [prefix "g"] cy/toggle-margins) (key/bind :root [prefix "1"] cy/margins-80) (key/bind :root [prefix "2"] cy/margins-160) (key/bind :root [prefix "+"] cy/margins-smaller) (key/bind :root [prefix "-"] cy/margins-bigger) - #(key/bind :root [prefix "q"] "kill the cy server" (fn [&] (cy/kill-server))) #(key/bind :root [prefix "d"] "detach from the cy server" (fn [&] (cy/detach))) #(key/bind :root [prefix "p"] "enter replay mode" (fn [&] (cy/replay))) @@ -131,12 +141,6 @@ (key/bind :root [prefix "p"] cy/replay) (key/bind :root [prefix "P"] cy/paste) -# should actions just be functions with docstrings? -#(key/action increase-margins "increase margins by 5 columns" -#(def [lines cols] (frame/size)) -#(frame/set-size [lines (- cols 10)])) -#(key/bind [prefix "-"] increase-margins) - (key/bind :replay ["q"] replay/quit) (key/bind :replay ["ctrl+c"] replay/quit) (key/bind :replay ["esc"] replay/quit) @@ -165,3 +169,4 @@ (key/bind :replay ["!"] (fn [&] (replay/time-playback-rate -1))) (key/bind :replay ["@"] (fn [&] (replay/time-playback-rate -2))) (key/bind :replay ["#"] (fn [&] (replay/time-playback-rate -5))) +(pp actions) diff --git a/pkg/cy/janet.go b/pkg/cy/janet.go index 36ca2c38..faf53aaf 100644 --- a/pkg/cy/janet.go +++ b/pkg/cy/janet.go @@ -196,10 +196,6 @@ func (c *Cy) initJanet(ctx context.Context) (*janet.VM, error) { return nil, ctx.Err() } }, - "key/new": func(doc string, callback *janet.Function) error { - c.log.Info().Msgf("registered action: %+v", doc) - return nil - }, "key/bind": func(target *janet.Value, sequence []string, callback *janet.Function) error { defer target.Free()