-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add nvim side for zellij, waiting for zellij side
[zellij #967](zellij-org/zellij#967)
- Loading branch information
1 parent
91d8650
commit 8dc67b8
Showing
3 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
---@mod navigator.zellij Zellij navigator | ||
---@brief [[ | ||
---This module provides navigation and interaction for Zellij, and uses |navigator.vi| | ||
---as a base class. This is used automatically when zellij is detected on host system | ||
---but can also be used to manually override the mux. | ||
--- | ||
---@brief ]] | ||
|
||
---@private | ||
---@class Zellij: Vi | ||
---@field private direction table<Direction, string> | ||
---@field private execute fun(arg: string): unknown | ||
local Zellij = require('Navigator.mux.vi'):new() | ||
|
||
---Creates a new Zellij navigator instance | ||
---@return Zellij | ||
---@usage [[ | ||
---local ok, zellij = pcall(function() | ||
--- return require('Navigator.mux.zellij'):new() | ||
---end) | ||
--- | ||
---require('Navigator').setup({ | ||
--- mux = ok and zellij or 'auto' | ||
---}) | ||
---@usage ]] | ||
function Zellij:new() | ||
assert(os.getenv('ZELLIJ'), '[Navigator] Zellij is not running!') | ||
local U = require('Navigator.utils') | ||
|
||
---@type Zellij | ||
local state = { | ||
execute = function(arg) | ||
local cmd = string.format('zellij action %s', arg) | ||
return U.execute(cmd) | ||
end, | ||
direction = { | ||
p = 'focus-previous-pane', | ||
h = 'move-focus left', | ||
k = 'move-focus up', | ||
l = 'move-focus right', | ||
j = 'move-focus down' | ||
}, | ||
} | ||
self.__index = self | ||
return setmetatable(state, self) | ||
end | ||
|
||
---Switch pane in zellij | ||
---@param direction Direction See |navigator.api.Direction| | ||
---@return Zellij | ||
function Zellij:navigate(direction) | ||
self.execute(string.format('%s', self.direction[direction])) | ||
return self | ||
end | ||
|
||
return Zellij |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters