Skip to content

Commit

Permalink
feat: actions command palette
Browse files Browse the repository at this point in the history
  • Loading branch information
cfoust committed Nov 6, 2023
1 parent cdc6cc2 commit f08be9f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
21 changes: 13 additions & 8 deletions pkg/cy/cy-boot.janet
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)))
Expand All @@ -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)
Expand Down Expand Up @@ -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)
4 changes: 0 additions & 4 deletions pkg/cy/janet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit f08be9f

Please sign in to comment.