Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjones2014 committed Apr 19, 2023
1 parent 7de1381 commit e0f37ee
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 15 deletions.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -469,3 +469,29 @@ listen_on unix:/tmp/mykitty
Thanks @knubie for inspiration for the Kitty implementation from [vim-kitty-navigator](https://github.com/knubie/vim-kitty-navigator).

Thanks to @chancez for the relative resize [Python kitten](https://github.com/chancez/dotfiles/blob/badc69d3895a6a942285126b8c372a55d77533e1/kitty/.config/kitty/relative_resize.py).

### Multiplexer Lua API

You can directly access the multiplexer API for scripting purposes as well.
To get a handle to the current multiplexer backend, you can do:

```lua
local mux = require('smart-splits.mux').get()
```

This returns the currently enabled multiplexer backend, or `nil` if none is currently in use.
The API offers the following methods:

```lua
local mux = require('smart-splits.mux').get()
-- mux matches the following type annotations
---@class SmartSplitsMultiplexer
---@field current_pane_id fun():number|nil
---@field current_pane_at_edge fun(direction:'left'|'right'|'up'|'down'):boolean
---@field is_in_session fun():boolean
---@field current_pane_is_zoomed fun():boolean
---@field next_pane fun(direction:'left'|'right'|'up'|'down'):boolean
---@field resize_pane fun(direction:'left'|'right'|'up'|'down', amount:number):boolean
---@field split_pane fun(direction:'left'|'right'|'up'|'down',size:number|nil):boolean
---@field type 'tmux'|'wezterm'|'kitty'
```
23 changes: 19 additions & 4 deletions lua/smart-splits/mux/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ end
---@param direction SmartSplitsDirection direction to move
---@param will_wrap boolean whether to wrap around edge
---@param at_edge SmartSplitsAtEdgeBehavior behavior at edge
---@return boolean whether we moved with multiplexer or not
---@return boolean success
function M.move_pane(direction, will_wrap, at_edge)
at_edge = at_edge or config.at_edge
local multiplexer = M.get()
Expand All @@ -90,7 +90,7 @@ end
---Try resizing with multiplexer
---@param direction SmartSplitsDirection direction to resize
---@param amount number amount to resize
---@return boolean whether we resized with multiplexer or not
---@return boolean success
function M.resize_pane(direction, amount)
local multiplexer = M.get()
if not multiplexer or not multiplexer.is_in_session() then
Expand All @@ -103,10 +103,25 @@ function M.resize_pane(direction, amount)
local ok = multiplexer.resize_pane(direction, amount)
if not ok then
vim.notify('[smart-splits.nvim] Failed to resize multiplexer pane', vim.log.levels.ERROR)
return false
end

return true
return ok
end

---Try creating a new mux split pane. Not supported in Kitty multiplexer.
---@param direction SmartSplitsDirection
---@param size number|nil
---@return boolean success
function M.split_pane(direction, size)
local mux = M.get()
if not mux or not mux.is_in_session() then
return false
end
local ok = mux.split_pane(direction, size)
if not ok then
vim.notify('[smart-splits.nvim] Failed to create a new mux pane', vim.log.levels.ERROR)
end
return ok
end

return M
14 changes: 6 additions & 8 deletions lua/smart-splits/mux/kitty.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,7 @@ function M.next_pane(direction)
end

direction = dir_keys_kitty[direction] ---@diagnostic disable-line
local ok, _ = pcall(function()
kitty_exec({ 'kitten', 'neighboring_window.py', direction })
end)

local ok, _ = pcall(kitty_exec, { 'kitten', 'neighboring_window.py', direction })
return ok
end

Expand All @@ -93,15 +90,16 @@ function M.resize_pane(direction, amount)
return false
end

local ok, _ = pcall(function()
kitty_exec({ 'kitten', 'relative_resize.py', direction, amount })
end)
local ok, _ = pcall(kitty_exec, { 'kitten', 'relative_resize.py', direction, amount })

return ok
end

function M.split_pane(_, _)
vim.notify('[smart-splits.nvim] Sorry, Kitty does not support creation of arbitrary split panes.')
vim.notify(
'[smart-splits.nvim] Sorry, Kitty does not support creation of arbitrary split panes.',
vim.log.levels.WARN
)
return false
end

Expand Down
15 changes: 12 additions & 3 deletions lua/smart-splits/mux/tmux.lua
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,7 @@ function M.next_pane(direction)
end

direction = dir_keys_tmux[direction] ---@diagnostic disable-line
local ok, s = pcall(tmux_exec, { 'select-pane', string.format('-%s', direction) })
p(s)
local ok, _ = pcall(tmux_exec, { 'select-pane', string.format('-%s', direction) })
return ok
end

Expand All @@ -177,7 +176,17 @@ function M.resize_pane(direction, amount)
end

function M.split_pane(direction, size)
local args = {}
local vert_or_horiz = (direction == Direction.left or direction == Direction.right) and '-h' or '-v'
local args = { 'split-pane', vert_or_horiz }
if direction == Direction.up or direction == Direction.left then
table.insert(args, '-b')
end
if size then
table.insert(args, '-l')
table.insert(args, size)
end
local ok, _ = pcall(tmux_exec, args)
return ok
end

return M

0 comments on commit e0f37ee

Please sign in to comment.