Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kitty terminal support #26

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ vim.keymap.set({'n', 't'}, '<A-p>', '<CMD>NavigatorPrevious<CR>')

- [Tmux](https://github.com/numToStr/Navigator.nvim/wiki/Tmux-Integration)
- [WezTerm](https://github.com/numToStr/Navigator.nvim/wiki/WezTerm-Integration)
- [Kitty](https://github.com/numToStr/Navigator.nvim/wiki/Kitty-Integration)

#### Configuration (optional)

Expand Down
53 changes: 53 additions & 0 deletions lua/Navigator/mux/kitty.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---@mod navigator.kitty Kitty navigator
---@brief [[
---This module provides navigation and interaction for kitty, and uses |navigator.vi|
---as a base class. This is used automatically when kitty is detected on host system
---but can also be used to manually override the mux.
---
---Read also: https://github.com/numToStr/Navigator.nvim/wiki/kitty-Integration
---@brief ]]

---@private
---@class Kitty: Vi
---@field private direction table<Direction, string>
---@field private execute fun(arg: string): unknown
local Kitty = require('Navigator.mux.vi'):new()

---Creates a new Kitty navigator instance
---@return Kitty
---@usage [[
---local ok, kitty = pcall(function()
--- return require('Navigator.mux.kitty'):new()
---end)
---
---require('Navigator').setup({
--- mux = ok and kitty or 'auto'
---})
---@usage ]]
function Kitty:new()
-- Kitty sets TERM, but not TERM_PROGRAM
assert(os.getenv('TERM') == 'xterm-kitty', '[Navigator] Kitty is not running!')

local U = require('Navigator.utils')

---@type Kitty
local state = {
execute = function(arg)
return U.execute(string.format('kitty @ %s', arg))
end,
direction = { h = 'left', j = 'bottom', k = 'top', l = 'right', },
}
self.__index = self
return setmetatable(state, self)
end

---Switch pane in kitty
---@param direction Direction See |navigator.api.Direction|
---@return Kitty
function Kitty:navigate(direction)
self.execute(string.format('kitten navigator.py %s', self.direction[direction]))
return self
end

return Kitty

6 changes: 6 additions & 0 deletions lua/Navigator/navigate.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ local function load_mux()
if ok_wezterm then
return wezterm
end
local ok_kitty, kitty = pcall(function()
return require('Navigator.mux.kitty'):new()
end)
if ok_kitty then
return kitty
end
return require('Navigator.mux.vi'):new()
end

Expand Down