API
This is a complete listing of all of the API functions that cy
provides in the top-level Janet environment (ie you do not need to import
or use
anything.)
Janet code executed with cy
can also access everything from Janet's standard library except for anything in spork
. In addition, Janet's ev
family of functions probably will not work; I have never tested them.
Concepts
Binding
Several API functions related to binding keys return a Binding
. A Binding
table represents a single key sequence and its associated function. Each table has the following properties:
:node
: the NodeID where the binding is defined.:sequence
: a list of strings representing the key sequence that will execute this action. If the original call to key/bind used a regex, it will be returned as a string with are:
prefix.:function
: the Janet function that will be called when this sequence is executed.
For example:
{
:node 1
:sequence ["ctrl+a" "t"]
:function <some function>
}
Color
Some API functions, such as style/render, accept colors as input. cy
supports True Color colors specified in hexadecimal along with ANSI 16 and ANSI-256 colors. Under the hood, cy
uses charmbracelet/lipgloss and thus supports its color references.
You can read more about color support in terminal emulators here.
Examples of valid colors:
"#ffffff" # true color
"#123456" # true color
"255" # ANSI 256
"0" # ANSI 16
Color map
A color map is a mapping from one color to another. They can represented by Janet structs or tables:
# The "zenburn" color map
# This maps the default 16 ANSI colors to hand-picked RGB colors
@{"0" "#383838"
"1" "#dca3a3"
"2" "#5f7f5f"
"3" "#e0cf9f"
"4" "#7cb8bb"
"5" "#dc8cc3"
"6" "#93e0e3"
"7" "#dcdccc"
"8" "#6f6f6f"
"9" "#dfaf8f"
"10" "#404040"
"11" "#606060"
"12" "#808080"
"13" "#c0c0c0"
"14" "#000000"
"15" "#ffffff"}
For more information about color maps, see the relevant section in the parameters chapter.
Command
cmd/query and {{api/commands}} return Commands, which are structs that look like this:
{:text "echo 'Hello, World!'" # The command that was run
:directory "/some/dir"
# When the command started executing
:executed-at {} # Time
# When it finished
:completed-at {} # Time
# These three properties only have internal meaning for now
:prompted 23
:executed 26
:completed 52
:pending false
# Input and output are Selections, which can currently only be passed to
# input/find previews. Refer to the standard library.
:input @[{:from (97 6)
:to (97 7)}]
:output {:from (98 0)
:to (98 42)}}
NodeID
Many API functions have a parameter of type NodeID
, which can be one of two values:
:root
which is a short way of referring tocy
's top-level group.- An integer that refers to a node in
cy
's node tree. You cannot infer these yourself, but they are returned from API functions like pane/current and group/children.
Time
The (time/*)
family of functions works with Time
values, which are similar (but not identical) to the value returned by Janet's built-in (os/date)
function.
Time values are structs with the following properties:
{:dst false # unused, just to mimic (os/date)
:hours 10
:milliseconds 624
:minutes 15
:month 9
:month-day 15
:seconds 31
:utc false # if false, properties are in local time
:week-day 0
:year 2024
:year-day 259}
For specifics on the range of each scalar property, consult the documentation for Go's time package, such as for time.Weekday().
Symbols
action/add-node action/browse-animations action/choose-frame action/clear-layout action/command-palette action/cpu-profile action/ctrl-r action/detach action/jump-command action/jump-group-pane action/jump-history-command action/jump-pane action/jump-pane-command action/jump-project action/jump-screen-lines action/jump-shell action/kill-and-reattach action/kill-layout-pane action/kill-pane action/kill-server action/margins-160 action/margins-80 action/margins-bigger action/margins-smaller action/move-down action/move-left action/move-right action/move-up action/new-project action/new-shell action/new-tab action/next-pane action/next-tab action/open-log action/open-replay action/paste action/paste-clipboard action/prev-pane action/prev-tab action/random-frame action/recall-command action/reload-config action/remove-layout-pane action/remove-parent action/rename-pane action/rename-tab action/replay-playback-1x action/replay-playback-2x action/replay-playback-5x action/replay-playback-reverse-1x action/replay-playback-reverse-2x action/replay-playback-reverse-5x action/search-borg action/set-borders-title action/set-borders-title-bottom action/set-layout-borders action/set-pane-colors action/show-color-map action/split-down action/split-left action/split-right action/split-up action/toggle-margins action/trace assoc clipboard/get clipboard/set cmd/commands cmd/kill cmd/new cmd/path cmd/query color-maps/get color-maps/get-all color-maps/get-id color-maps/set cy/cpu-profile cy/detach cy/kill-server cy/paste cy/reload-config cy/trace exec/file group/children group/leaves group/mkdir group/new input/find input/text key/action key/bind key/bind-many key/bind-many-tag key/current key/get key/get-actions key/remap key/unbind layout/assoc layout/attach layout/attach-first layout/attach-id layout/attach-path layout/attached? layout/bar layout/borders layout/color-map layout/detach layout/find layout/find-last layout/get layout/has? layout/hsplit layout/map layout/margins layout/move layout/move-down layout/move-left layout/move-right layout/move-up layout/new layout/pane layout/pane? layout/path layout/remove-attached layout/replace layout/replace-attached layout/set layout/split layout/split-down layout/split-left layout/split-right layout/split-up layout/successors layout/tab layout/tabs layout/type? layout/vsplit msg/log msg/toast pane/attach pane/current pane/history-backward pane/history-forward pane/screen pane/send-keys param/get param/rset param/set param/set-many path/abs path/base path/glob path/join register/get register/insert register/set replay/beginning replay/big-word-backward replay/big-word-end-backward replay/big-word-end-forward replay/big-word-forward replay/command-backward replay/command-forward replay/command-select-backward replay/command-select-forward replay/copy replay/copy-clipboard replay/copy-default replay/cursor-down replay/cursor-left replay/cursor-right replay/cursor-up replay/end replay/end-of-line replay/end-of-screen-line replay/first-non-blank replay/first-non-blank-screen replay/half-page-down replay/half-page-up replay/jump-again replay/jump-backward replay/jump-forward replay/jump-reverse replay/jump-to-backward replay/jump-to-forward replay/last-non-blank replay/last-non-blank-screen replay/middle-of-line replay/middle-of-screen-line replay/open replay/open-file replay/quit replay/scroll-down replay/scroll-up replay/search-again replay/search-backward replay/search-forward replay/search-reverse replay/select replay/start-of-line replay/start-of-screen-line replay/swap-screen replay/time-play replay/time-playback-rate replay/time-step-back replay/time-step-forward replay/word-backward replay/word-end-backward replay/word-end-forward replay/word-forward search/cancel search/first search/focus-input search/last search/new search/next search/prev shell/attach shell/new style/render style/text time/format time/now tree/group? tree/name tree/pane? tree/parent tree/path tree/rm tree/root tree/set-name viewport/get-animations viewport/get-frames viewport/set-frame
action/add-node
function
(action/add-node)
Add a node to the layout.
action/browse-animations
function
(action/browse-animations)
Browse animations.
action/choose-frame
function
(action/choose-frame)
Choose a frame.
action/clear-layout
function
(action/clear-layout)
Clear out the layout.
action/command-palette
function
(action/command-palette)
Open the command palette.
action/cpu-profile
function
(action/cpu-profile)
Save a CPU profile to cy's socket directory.
action/ctrl-r
function
(action/ctrl-r)
Find a recent command and insert it into the current shell.
action/detach
function
(action/detach)
Detach from the cy server.
action/jump-command
function
(action/jump-command)
Jump to the output of a command.
action/jump-group-pane
function
(action/jump-group-pane)
Jump to a pane that is a descendant of the current group.
action/jump-history-command
function
(action/jump-history-command)
Find a command and open its .borg file.
action/jump-pane
function
(action/jump-pane)
Jump to a pane.
action/jump-pane-command
function
(action/jump-pane-command)
Jump to a pane based on a command.
action/jump-project
function
(action/jump-project)
Jump to a project.
action/jump-screen-lines
function
(action/jump-screen-lines)
Jump to a pane based on screen lines.
action/jump-shell
function
(action/jump-shell)
Jump to a shell.
action/kill-and-reattach
function
(action/kill-and-reattach)
Remove the current pane from the node tree and attach to a new one.
A new shell will be created if the current pane is the last one in the layout.
action/kill-layout-pane
function
(action/kill-layout-pane)
Remove the current pane from the layout and the node tree.
action/kill-pane
function
(action/kill-pane)
Kill the process of the current pane, but do not detach from it.
action/kill-server
function
(action/kill-server)
Kill the cy server.
action/margins-160
function
(action/margins-160)
Set size to 160 columns.
action/margins-80
function
(action/margins-80)
Set margins size to 80 columns.
action/margins-bigger
function
(action/margins-bigger)
Increase margins by 5 columns.
action/margins-smaller
function
(action/margins-smaller)
Decrease margins by 5 columns.
action/move-down
function
(action/move-down)
Move down to the next pane.
action/move-left
function
(action/move-left)
Move left to the next pane.
action/move-right
function
(action/move-right)
Move right to the next pane.
action/move-up
function
(action/move-up)
Move up to the next pane.
action/new-project
function
(action/new-project)
Create a new project.
action/new-shell
function
(action/new-shell)
Create a new shell.
action/new-tab
function
(action/new-tab)
Create a new tab.
action/next-pane
function
(action/next-pane)
Move to the next sibling pane.
action/next-tab
function
(action/next-tab)
Switch to the next tab.
action/open-log
function
(action/open-log)
Open a .borg file.
action/open-replay
function
(action/open-replay)
Enter replay mode for the current pane.
action/paste
function
(action/paste)
Insert the contents of the default register.
action/paste-clipboard
function
(action/paste-clipboard)
Insert the contents of the system clipboard.
action/prev-pane
function
(action/prev-pane)
Move to the previous sibling pane.
action/prev-tab
function
(action/prev-tab)
Switch to the previous tab.
action/random-frame
function
(action/random-frame)
Switch to a random frame.
action/recall-command
function
(action/recall-command)
Recall the output of a command to the current shell.
action/reload-config
function
(action/reload-config)
Reload the cy configuration.
action/remove-layout-pane
function
(action/remove-layout-pane)
Remove the current pane from the layout.
action/remove-parent
function
(action/remove-parent)
Remove the parent of the current node.
action/rename-pane
function
(action/rename-pane)
Rename the current pane.
action/rename-tab
function
(action/rename-tab)
Rename the current tab.
action/replay-playback-1x
function
(action/replay-playback-1x)
Set the playback rate to 1x real time.
action/replay-playback-2x
function
(action/replay-playback-2x)
Set the playback rate to 2x real time.
action/replay-playback-5x
function
(action/replay-playback-5x)
Set the playback rate to 5x real time.
action/replay-playback-reverse-1x
function
(action/replay-playback-reverse-1x)
Set the playback rate to -1x real time (backwards).
action/replay-playback-reverse-2x
function
(action/replay-playback-reverse-2x)
Set the playback rate to -2x real time (backwards).
action/replay-playback-reverse-5x
function
(action/replay-playback-reverse-5x)
Set the playback rate to -5x real time (backwards).
action/search-borg
function
(action/search-borg)
Search all recorded .borg files for a pattern.
action/set-borders-title
function
(action/set-borders-title)
Set the :title for a :borders node.
action/set-borders-title-bottom
function
(action/set-borders-title-bottom)
Set the :title-bottom for a :borders node.
action/set-layout-borders
function
(action/set-layout-borders)
Change the border style across the entire layout.
action/set-pane-colors
function
(action/set-pane-colors)
Set the color map for the current pane.
action/show-color-map
function
(action/show-color-map)
Send a toast with the ID of the current color map.
action/split-down
function
(action/split-down)
Split the current pane downwards.
action/split-left
function
(action/split-left)
Split the current pane to the left.
action/split-right
function
(action/split-right)
Split the current pane to the right.
action/split-up
function
(action/split-up)
Split the current pane upwards.
action/toggle-margins
function
(action/toggle-margins)
Toggle the screen's margins.
action/trace
function
(action/trace)
Save a trace to cy's socket directory.
assoc
function
(assoc s key value)
Set a property in a struct, returning a new struct.
clipboard/get
function
(clipboard/get)
Get the contents of the system clipboard.
clipboard/set
function
(clipboard/set text)
Set the contents of the system clipboard.
cmd/commands
function
(cmd/commands target)
Get the commands executed in a particular pane. Returns an array of Commands. target
is a NodeID.
cmd/kill
function
(cmd/kill target)
Kill the pane specified by target. target
is a NodeID.
cmd/new
function
(cmd/new parent &named path restart command args name)
Run command
with args
and working directory path
in a new pane as a child of the group specified by parent
. You may also provide the name
of the new pane. If command
is not specified, (cmd/new)
defaults to the current user's shell. parent
is a NodeID.
If restart
is true
, when the command exits, it will be rerun. However, if the command exits with a non-zero exit code more than three times in a second, it will not be run again.
Some examples:
# Create a new shell in the root group
(cmd/new :root)
# `args` is a list of strings
(cmd/new :root :command "less" :args @["README.md"])
cmd/path
function
(cmd/path target)
Get the working directory of the program running in the pane pane specified by target
. target
is a NodeID.
cmd/query
function
(cmd/query)
Query all of the commands stored in the commmand database.
color-maps/get
function
(color-maps/get id)
Get a color map by id.
color-maps/get-all
function
(color-maps/get-all)
Get all of the built-in color maps.
color-maps/get-id
function
(color-maps/get-id target)
Get the ID of the color map of the target node.
color-maps/set
function
(color-maps/set target id)
Set the :color-map parameter of the target node to the color map specified by id. Also sets the :color-map-id parameter.
target
is a NodeID.
cy/cpu-profile
function
(cy/cpu-profile)
Save a 15-second CPU profile captured with pprof to the socket directory. This is only useful for debugging.
cy/detach
function
(cy/detach)
Detach from the cy
server.
cy/kill-server
function
(cy/kill-server)
Kill the cy
server, disconnecting all clients.
cy/paste
function
(cy/paste arg0)
Paste the text in the copy buffer to the current pane.
cy/reload-config
function
(cy/reload-config)
Detect and (re)evaluate cy's configuration. This uses the same configuration detection scheme described in the Configuration chapter.
cy/trace
function
(cy/trace)
Save a 15-second trace captured with runtime/trace to the socket directory. This is only useful for debugging.
exec/file
function
(exec/file path)
Execute the Janet file found at path
. Throws any errors that occur during execution.
group/children
function
(group/children group)
Get the NodeIDs for all of group
's child nodes.
group/leaves
function
(group/leaves group)
Get the NodeIDs for all of the leaf nodes reachable from group
. In other words, this is a list of all of the NodeIDs for all panes that are descendants of group
.
group/mkdir
function
(group/mkdir group path)
Get the group at the end of path
from the perspective of group
, creating any groups that do not exist. Returns the NodeID of the final group.
For example:
(group/mkdir :root "/foo/bar/baz")
# Returns the NodeID of "baz"
This function throws an error if any node in the path already exists and is not a group.
group/new
function
(group/new parent &named name)
Create a new group with parent
and (optionally) name
.
parent
is a NodeID.
input/find
function
(input/find inputs &named prompt full reverse animated headers)
(input/find)
is a general-purpose fuzzy finder that is similar to fzf
. When invoked, it prompts the user to choose from one of the items provided in inputs
. (input/find)
does not return until the user makes a choice; if they choose nothing (such as by hitting ctrl+c), it returns nil
.
inputs
is an array with elements that can take different forms depending on the desired behavior. See more on the page about fuzzy finding.
This function supports a range of named parameters that adjust its functionality:
:animated
(boolean): Enable and disable background animation.:case-sensitive
(boolean): Whether the matching algorithm should respect differences in case. The default isfalse
.:full
(boolean): If true, occupy the entire screen.:headers
([]string): Provide a title for each column. This mostly used for filtering tabular data.:prompt
(string): The text that will be shown beneath the search window.:reverse
(boolean): Display from the top of the screen (rather than the bottom.):width
(int): Set the width of the match window (if not in full screen mode.):height
(int): Set the maximum height of the match window. This applies bth in full screen and floating mode.
input/text
function
(input/text prompt &named preset placeholder full reverse animated)
(input/text)
prompts the user with a freeform text input. If the input is non-empty when the user presses enter, (input/text)
returns the value of the text input; otherwise it returns nil
.
The only required parameter, prompt
, is a string that determines the prompt text that is shown below the text input.
This function supports a range of named parameters that adjust its functionality:
:preset
(string): Pre-fill the value of the text input.:placeholder
(string): This string will be shown when the text input is empty.:full
(boolean): If true, occupy the entire screen.:reverse
(boolean): Display from the top of the screen (rather than the bottom.):animated
(boolean): Enable and disable background animation.
key/action
macro
(key/action name docstring & body)
Register an action. Equivalent to the Janet built-in (defn)
, but requires a docstring.
An action is just a Janet function that is registered to the cy server with a short human-readable string description. It provides a convenient method for making some functionality you use often more discoverable.
In a similar way to other modern applications, cy has a command palette (invoked by default with ctrl+a ctrl+p [?], see action/command-palette) in which all registered actions will appear.
key/bind
function
(key/bind target sequence callback)
Bind the key sequence sequence
to callback
for node target
, which is a NodeID, :time
(for time mode), or :copy
(for copy mode). target
can refer to any group or pane.
sequence
is a key sequence, which consists of a tuple with string elements that are either key literals ("h"
), preset key specifiers ("ctrl+a"
), or regex patterns ([:re "^[a-z]$"]
).
Read more about binding keys in the dedicated chapter.
key/bind-many
macro
(key/bind-many scope & body)
Bind many bindings at once in the same scope.
For example:
(key/bind-many :root
[prefix "j"] action/new-shell
[prefix "n"] action/new-project)
key/bind-many-tag
macro
(key/bind-many-tag scope tag & body)
Bind many bindings at once in the same scope, adding the provided tag.
key/current
function
(key/current)
Get all of the bindings accessible to the current client as an array of Bindings. It contains all of the bindings defined by the node to which the client is attached and its ancestors. In other words, this is equivalent to the list of bindings against which the client's key presses are compared.
key/get
function
(key/get target)
Get all of target
's bindings. target
is a NodeID, :time
, or :copy
. Returns an array of Bindings. Note that this does not return bindings defined in an ancestor node, only those defined on the node itself.
key/get-actions
function
(key/get-actions)
Get all registered actions.
key/remap
function
(key/remap target from to)
Remap all bindings that begin with sequence from
to sequence to
for node target
, which is a NodeID, :time
, or :copy
. Empty sequences ([]
) are not currently supported for from
and to
.
For example, to remap all of the default bindings that begin with ctrl+a to ctrl+v:
(key/remap :root ["ctrl+a"] ["ctrl+v"])
key/unbind
function
(key/unbind target sequence)
Clear all bindings that begin with sequence
for node target
, which is a NodeID, :time
, or :copy
. Note that the empty sequence []
will unbind all keys in the scope.
sequence
is a key sequence, which consists of a tuple with string elements that are either key literals ("h"
), preset key specifiers ("ctrl+a"
), or regex patterns ([:re "^[a-z]$"]
).
The following code snippet will unbind all of cy
's default keybindings that begin with ctrl+a:
(key/unbind :root ["ctrl+a"])
layout/assoc
function
(layout/assoc layout path node)
Set the node at the given path in layout to the provided node. Returns a copy of the original layout with the node changed.
layout/attach
function
(layout/attach layout path)
Attach to the node at path in layout.
layout/attach-first
function
(layout/attach-first layout)
Attach to the first pane found in the layout.
layout/attach-id
function
(layout/attach-id node)
Get the NodeID of the attached node for the given node.
layout/attach-path
function
(layout/attach-path node)
Get the path to the attached node for the given node.
layout/attached?
function
(layout/attached? node)
Report whether node or one of its descendants is attached.
layout/bar
function
(layout/bar text node &named bottom)
Convenience function for creating a new :bar node.
layout/borders
function
(layout/borders node &named title title-bottom border border-fg border-bg)
Convenience function for creating a new :borders node.
layout/color-map
function
(layout/color-map map node)
Convenience function for creating a new :color-map node.
layout/detach
function
(layout/detach node)
Detach the attached node in the tree.
layout/find
function
(layout/find node predicate)
Get the path to the first node satisfying the predicate function or nil if none exists.
layout/find-last
function
(layout/find-last layout path predicate)
Get the path to the last node in the path where (predicate node) evaluates to true.
layout/get
function
(layout/get)
Get the layout of the current user.
layout/has?
function
(layout/has? node predicate)
Report whether this node or one of its descendants matches the predicate function.
layout/hsplit
function
(layout/hsplit a b &named cells percent border border-fg border-bg)
Convenience function for creating a new horizontal :split node.
layout/map
function
(layout/map mapping layout)
Pass all nodes in the tree into a mapping function.
layout/margins
function
(layout/margins node &named cols rows border border-fg border-bg)
Convenience function for creating a new :margins node.
layout/move
function
(layout/move layout is-axis axis-successors)
This function attaches to the pane nearest to the one the user is currently attached to along an axis. It returns a new copy of layout with the attachment point changed or returns the same layout if no motion could be completed.
is-axis is a unary function that, given a node, returns a boolean that indicates whether the node is arranged along the axis in question. For example, when moving vertically, a vertical split (two panes on top of each other) would return true.
successors is a unary function that, given a node where is-axis was true, returns the paths of all of the child nodes accessible from the node in the order of their appearance along the axis.
For example, when moving vertically upwards, for a vertical split node this function would return @[[:b] [:a]], because :b is the first node from the bottom, and when moving vertically downwards it would return @[[:a] [:b]] because :a is the first node from the top.
layout/move-down
function
(layout/move-down layout)
Change the layout by moving to the next node "below" the attached pane.
layout/move-left
function
(layout/move-left layout)
Change the layout by moving to the next node to the left of the attached pane.
layout/move-right
function
(layout/move-right layout)
Change the layout by moving to the next node to the right of the attached pane.
layout/move-up
function
(layout/move-up layout)
Change the layout by moving to the next node "above" the attached pane.
layout/new
macro
(layout/new body)
Macro for quickly creating layouts. layout/new replaces shorthand versions of node creation functions with their longform versions and also includes a few abbreviations that do not exist elsewhere in the API.
Supported short forms:
- active-tab: A :tab with :active=true inside of a :tabs node.
- attach: An attached :pane node.
- bar: A :bar node.
- borders: A :borders node.
- color-map: A :color-map node.
- hsplit: A :split node with :vertical=false.
- margins: A :margins node.
- pane: A detached :pane node.
- split: A :split node.
- tab: A :tab inside of a :tabs node.
- tabs: A :tabs node.
- vsplit: A :split node with :vertical=true.
See the layouts chapter for more information.
layout/pane
function
(layout/pane &named id attached remove-on-exit)
Convenience function for creating a new :pane node.
layout/pane?
function
(layout/pane? node)
Report whether node is of type :pane.
layout/path
function
(layout/path node path)
Resolve the path to a node. Returns nil if any portion of the path is invalid.
layout/remove-attached
function
(layout/remove-attached layout)
Remove the attached node from the layout, simplifying the nearest ancestor with children.
layout/replace
function
(layout/replace node path replacer)
Replace the node at the path by passing it through a replacer function.
layout/replace-attached
function
(layout/replace-attached node replacer)
Replace the attached pane in this tree with a new one using the provided replacer function. This function will be invoked with a single argument, the node that is currently attached, and it should return a new node.
layout/set
function
(layout/set layout)
Set the layout of the current user.
layout/split
function
(layout/split a b &named vertical cells percent border border-fg border-bg)
Convenience function for creating a new :split node.
layout/split-down
function
(layout/split-down layout node)
Split the currently attached pane into two vertically, replacing the bottom pane with the given node.
layout/split-left
function
(layout/split-left layout node)
Split the currently attached pane into two horizontally, replacing the left pane with the given node.
layout/split-right
function
(layout/split-right layout node)
Split the currently attached pane into two horizontally, replacing the right pane with the given node.
layout/split-up
function
(layout/split-up layout node)
Split the currently attached pane into two vertically, replacing the top pane with the given node.
layout/successors
function
(layout/successors node)
Get the paths to all of the direct children of this node.
For example:
# For a node of type :split
@[[:a] [:b]]
# For a node of type :pane (it has no children)
@[]
layout/tab
function
(layout/tab name node &named active)
Convenience function for creating a new tab (inside of a :tabs node).
layout/tabs
function
(layout/tabs tabs &named active-fg active-bg inactive-fg inactive-bg bg bottom)
Convenience function for creating a new :tabs node.
layout/type?
function
(layout/type? type node)
Report whether node is of the provided type.
layout/vsplit
function
(layout/vsplit a b &named cells percent border border-fg border-bg)
Convenience function for creating a new vertical :split node.
msg/log
function
(msg/log level message)
Log message
to the /logs
pane. level
must be one of :info
, :warn
, :error
.
msg/toast
function
(msg/toast level message)
Send a toast with message
to the client. level
must be one of :info
, :warn
, :error
.
pane/attach
function
(pane/attach pane)
Attach to pane
, which is a NodeID that must correspond to a pane. This is similar to tmux
's attach
command.
pane/current
function
(pane/current)
Get the NodeID of the current pane.
pane/history-backward
function
(pane/history-backward)
Move backward in the pane history. Works in a similar way to vim's ctrl+o.
pane/history-forward
function
(pane/history-forward)
Move forward in the pane history. Works in a similar way to vim's ctrl+i.
pane/screen
function
(pane/screen pane)
Get the visible screen lines of the pane referred to by NodeID. Returns an array of strings.
pane/send-keys
function
(pane/send-keys pane keys)
Send keys to the pane referred to by NodeID. keys
is an array of strings. Strings that are not key specifiers will be written as-is.
(def pane (cmd/new :root))
# Send the string "test" to the pane
(pane/send-keys pane @["test"])
# Send ctrl+c to the pane
(pane/send-keys pane @["ctrl+c"])
param/get
function
(param/get key &named target)
Get the value of the parameter with key
, which must be a keyword.
Parameter values are retrieved in the following order:
- The client's parameter table, which overrides all other parameters and can be set with
(param/set :client ...)
. - The parameter table for the node the client is attached to and every parent node's parameter table, recursively, until the root node is reached.
- The default value for default parameters.
If target
is provided, it must be either :client
or a NodeID. This can be used to get parameter values from the perspective of another node in the tree, since it does the same cascade that (param/get)
does normally.
param/rset
function
(param/rset key value)
Set the value of a parameter at :root
.
param/set
function
(param/set target key value)
Set the value of the parameter at target
for key
to value
. target
must be either :client
or a NodeID (such as :root
.) value
can be any Janet value, though (param/set)
does enforce the type of default parameters.
param/set-many
macro
(param/set-many target & body)
Set many params at once with the same target.
For example:
(param/set-many :root
:replay-play-bg "#ff0000"
:replay-time-bg "#00ff00")
path/abs
function
(path/abs path)
Return the full absolute path for path
. Calls Go's path/filepath.Abs
.
path/base
function
(path/base path)
Return the last element of path
. Calls Go's path/filepath.Base
.
path/glob
function
(path/glob pattern)
Return an array of all files matching pattern
. Calls Go's path/filepath.Glob
.
path/join
function
(path/join paths)
Join the elements of the string array paths
with the OS's file path separator. Calls Go's path/filepath.Join
.
register/get
function
(register/get register)
Get the value stored in the given register. The "+" register refers to the system clipboard.
register/insert
function
(register/insert register)
Insert the contents of the given register in the current pane.
register/set
function
(register/set register value)
Store a string in the given register, which can be any string. The "+" register refers to the system clipboard.
replay/beginning
function
(replay/beginning)
Go to the beginning of the time range (in time mode) or the first line of the screen (in copy mode).
replay/big-word-backward
function
(replay/big-word-backward)
Move to the beginning of the previous WORD. Equivalent to vim's B
.
replay/big-word-end-backward
function
(replay/big-word-end-backward)
Move to the end of the previous WORD. Equivalent to vim's gE
.
replay/big-word-end-forward
function
(replay/big-word-end-forward)
Move to the end of the next WORD. Equivalent to vim's E
.
replay/big-word-forward
function
(replay/big-word-forward)
Move to the beginning of the next WORD. Equivalent to vim's W
.
replay/command-backward
function
(replay/command-backward)
In time mode, jump to the moment in time just before the previous command was executed. In copy mode, move the cursor to the first character of the previous command that was executed.
replay/command-forward
function
(replay/command-forward)
In time mode, jump to the moment in time just before the next command was executed. In copy mode, move the cursor to the first character of the next command.
replay/command-select-backward
function
(replay/command-select-backward)
Move the cursor to the first character of the output of the previous command and select its output.
replay/command-select-forward
function
(replay/command-select-forward)
Move the cursor to the first character of the output of the next command and select its output.
replay/copy
function
(replay/copy arg0)
Yank the selection into the copy buffer.
replay/copy-clipboard
function
(replay/copy-clipboard)
Yank the selection into the system clipboard.
replay/copy-default
function
(replay/copy-default)
Yank the selection into the default register.
replay/cursor-down
function
(replay/cursor-down)
Move cursor down one cell.
replay/cursor-left
function
(replay/cursor-left)
Move cursor left one cell.
replay/cursor-right
function
(replay/cursor-right)
Move cursor right one cell.
replay/cursor-up
function
(replay/cursor-up)
Move cursor up one cell.
replay/end
function
(replay/end)
Go to the end of the time range (in time mode) or the last line of the screen (in copy mode).
replay/end-of-line
function
(replay/end-of-line)
Move to the last character of the physical line. Equivalent to vim's $
.
replay/end-of-screen-line
function
(replay/end-of-screen-line)
Move to the end of the screen line. Equivalent to vim's g$
.
replay/first-non-blank
function
(replay/first-non-blank)
Move to the first non-blank character of the physical line. Equivalent to vim's ^
.
replay/first-non-blank-screen
function
(replay/first-non-blank-screen)
Move to the first non-blank character of the screen line. Equivalent to vim's g^
.
replay/half-page-down
function
(replay/half-page-down)
Scroll the viewport half a page (half the viewport height) down.
replay/half-page-up
function
(replay/half-page-up)
Scroll the viewport half a page (half the viewport height) up.
replay/jump-again
function
(replay/jump-again)
Repeat the last character jump.
replay/jump-backward
function
(replay/jump-backward char)
Jump to the previous instance of char
on the current line.
replay/jump-forward
function
(replay/jump-forward char)
Jump to the next instance of char
on the current line.
replay/jump-reverse
function
(replay/jump-reverse)
Repeat the inverse of the last character jump.
replay/jump-to-backward
function
(replay/jump-to-backward char)
Jump to the cell before char
after the cursor on the current line.
replay/jump-to-forward
function
(replay/jump-to-forward char)
Jump to the cell before char
after the cursor on the current line.
replay/last-non-blank
function
(replay/last-non-blank)
Move to the last non-blank character of the physical line. Equivalent to vim's g_
.
replay/last-non-blank-screen
function
(replay/last-non-blank-screen)
Move to the last non-blank character of the screen line. Equivalent to vim's g<end>
.
replay/middle-of-line
function
(replay/middle-of-line)
Move to the middle of the physical line. Equivalent to vim's gM
.
replay/middle-of-screen-line
function
(replay/middle-of-screen-line)
Move to the middle of the screen line. Equivalent to vim's gm
.
replay/open
function
(replay/open id &named copy focus alt-screen)
Enter replay mode for pane id
(which is a NodeID).
This function supports a range of named parameters that adjust its functionality:
:alt-screen
(boolean): Iftrue
, attempt to swap to the terminal's alt screen.:focus
(vec2): A coordinate in the reference frame of the terminal. These cannot be derived from scratch; typically this comes from a Command.
replay/open-file
function
(replay/open-file group path &named focus alt-screen highlights)
Open the .borg
file found at path
in a new replay window in group
.
This function supports a range of named parameters that adjust its functionality:
:focus
and:alt-screen
from replay/open:highlights
(selection): Just like:focus
, but is a struct with:from
and:to
fields. For the time being, this is not practical to derive by hand. See examples from the standard library.
For example:
(replay/open-file :root "some_borg.borg")
replay/quit
function
(replay/quit)
Quit replay mode.
replay/scroll-down
function
(replay/scroll-down)
Scroll the viewport one line down.
replay/scroll-up
function
(replay/scroll-up)
Scroll the viewport one line up.
replay/search-again
function
(replay/search-again)
Go to the next match in the direction of the last search.
replay/search-backward
function
(replay/search-backward)
Search for a string backwards in time (in time mode) or in the scrollback buffer (in copy mode).
replay/search-forward
function
(replay/search-forward)
Search for a string forwards in time (in time mode) or in the scrollback buffer (in copy mode).
replay/search-reverse
function
(replay/search-reverse)
Go to the previous match in the direction of the last search.
replay/select
function
(replay/select)
Enter visual select mode.
replay/start-of-line
function
(replay/start-of-line)
Move to the first character of the physical line. Equivalent to vim's 0
.
replay/start-of-screen-line
function
(replay/start-of-screen-line)
Move to the first character of the screen line. Equivalent to vim's g0
.
replay/swap-screen
function
(replay/swap-screen)
Swap between the alt screen and the main screen. This allows you to return to the pane's scrollback without quitting a program that is using the alternate screen, such as vim or htop.
replay/time-play
function
(replay/time-play)
Toggle playback.
replay/time-playback-rate
function
(replay/time-playback-rate rate)
Set the playback rate to rate
. Positive numbers indicate a multiplier of real time moving forwards, negative numbers, backwards. For example, a rate of 2
means that time will advance at twice the normal speed; -2
means that time will go backwards at -2x.
rate
is clamped to the range [10, 10].
replay/time-step-back
function
(replay/time-step-back)
Step one event backward in time.
replay/time-step-forward
function
(replay/time-step-forward)
Step one event forward in time.
replay/word-backward
function
(replay/word-backward)
Move to the beginning of the previous word. Equivalent to vim's b
.
replay/word-end-backward
function
(replay/word-end-backward)
Move to the end of the previous word. Equivalent to vim's ge
.
replay/word-end-forward
function
(replay/word-end-forward)
Move to the end of the next word. Equivalent to vim's e
.
replay/word-forward
function
(replay/word-forward)
Move to the beginning of the next word. Equivalent to vim's w
.
search/cancel
function
(search/cancel)
Cancel the current operation or the input of a query string.
search/first
function
(search/first)
Move to the first .borg
file in the search results.
search/focus-input
function
(search/focus-input)
Focus search mode's input bar so you can enter a new query string.
search/last
function
(search/last)
Move to the last .borg
file in the search results.
search/new
function
(search/new parent query &named files workers)
Create a new instance of search mode as a child of parent
with the given string query
. parent
is a NodeID. Calling this function will begin executing the search immediately, regardless of whether you attach to the new node.
This function supports a range of named parameters that adjust its functionality:
:files
(list of strings): All of the.borg
files to search in. By default this is populated with all of the.borg
files present in the user's:data-directory
.:workers
(integer): The number of workers (threads) to use to perform the search. Defaults to:num-search-workers
.
search/next
function
(search/next)
Move to the next .borg
file in the search results.
search/prev
function
(search/prev)
Move to the previous .borg
file in the search results.
shell/attach
function
(shell/attach &opt path)
Create a new shell initialized in the working directory path
and attach to it.
shell/new
function
(shell/new &opt path)
Create a new shell initialized in the working directory path
. If path
is not provided, this uses the path of the current pane.
style/render
function
(style/render style text)
Apply styling effects to some text. This function generates a string containing ANSI escape sequences that will style the provided text
according to style
.
All cy
API functions that render text to the screen, such as layout/set and input/find accept input styled with style/render.
style
is a struct with any of the following properties:
:fg
: The foreground color of the text.:bg
: The background color of the text.:width
: The number of horizontal cells the text should occupy. Padding is added if this value exceeds the length oftext
.:height
: The number of vertical cells the text should occupy. Padding is added if this value exceeds the height oftext
.:align-horizontal
: One of:left
,:center
, or:right
. If:width
is greater than the length of the text, the text will be aligned according to this property.:align-vertical
: One of:top
,:center
, or:bottom
. If:height
is greater than the height of the text, the text will be aligned according to this property.:bold
: A boolean indicating whether the text should be bolded.:italic
: A boolean indicating whether the text should be italic.:underline
: A boolean indicating whether the text should be underlined.:strikethrough
: A boolean indicating whether the text should be struck through.:reverse
: A boolean indicating whether the foreground and background colorshould be reversed.:blink
: A boolean indicating whether the text should blink.:faint
: A boolean indicating whether the text should be faint.
For example:
(style/render
{:bg "4"
:bold true
:width 15
} "some text")
style/text
function
(style/text text &named fg bg width height align-horizontal align-vertical bold italic underline strikethrough reverse blink faint)
Style the provided text with the attributes provided. This function is a convenient wrapper around style/render; instead of providing a struct, you may pass any of the attributes style/render supports as named parameters.
For example:
(style/text "foobar" :bg "#00ff00")
(style/text "foobar" :italic true :bold true :width 15)
time/format
function
(time/format ts format)
Format a Time struct using the provided format string. This uses Go's Time.Format. cy
provides all of Go's built-in time format layouts as constants, such as time/format/rfc-822
.
For example:
(time/format (time/now) time/format/rfc-822)
time/now
function
(time/now)
Return a Time struct representing the current local time.
tree/group?
function
(tree/group? node)
Return true
if node
is a group, false
otherwise. node
is a NodeID.
tree/name
function
(tree/name node)
Get the name of node
, which is a NodeID. This is the name of the node itself, not its path.
tree/pane?
function
(tree/pane? node)
Return true
if node
is a pane, false
otherwise. node
is a NodeID.
tree/parent
function
(tree/parent node)
Get the NodeID for the parent of node
. If node
is :root
, return (tree/parent)
returns nil
.
tree/path
function
(tree/path node)
Get the path of node
, which is a NodeID.
tree/rm
function
(tree/rm node)
Remove the node
and all of its child nodes. This will halt execution of any descendant panes. node
is a NodeID.
tree/root
function
(tree/root)
Get the NodeID that corresponds to the root node.
tree/set-name
function
(tree/set-name node name)
Set the name of node
to name
. name
will be stripped of all whitespace and slashes. node
is a NodeID.
viewport/get-animations
function
(viewport/get-animations)
Get a list of all of the available animations.
viewport/get-frames
function
(viewport/get-frames)
Get a list of all of the available frames.
viewport/set-frame
function
(viewport/set-frame frame)
Set the frame to frame
, which is an identifier for the desired frame.
You can get all of the available frames with (viewport/get-frames)
and also browse them here.