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

chore: read kitty executable from path #94

Merged
merged 12 commits into from
Dec 7, 2023
13 changes: 10 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,20 @@ jobs:
run: |
sudo apt update
sudo apt install -y xfce4 libxcb-xkb1
# homebrew is not used but is required to reproduce an issue for a test case
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

- name: Test kitty-scrollback.nvim
- name: Start Xvfb
run: |
Xvfb :1 -screen 0 1024x768x16 &
export PATH=$HOME/.local/kitty.app/bin:$PATH

- name: Test kitty-scrollback.nvim
run: |
# TODO: improve the env var exports, github actions are making it hard so I gave up for now
export PATH=$HOME/.local/kitty.app/bin:/home/linuxbrew/.linuxbrew/bin:$PATH
export DISPLAY=:1
echo "export PATH=$HOME/.local/kitty.app/bin:$PATH" >> "$HOME/.bashrc"
export PS1="\[\e[34m\]$ \[\e[m\]"
echo 'export PATH=$HOME/.local/kitty.app/bin:/home/linuxbrew/.linuxbrew/bin:$PATH' >> "$HOME/.bashrc"
echo 'export DISPLAY=:1' >> "$HOME/.bashrc"
echo 'export PS1="\[\e[34m\]$ \[\e[m\]"' >> "$HOME/.bashrc"
make test
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ Navigate your Kitty scrollback buffer to quickly search, copy, and execute comma
[![neovim: v0.9+](https://img.shields.io/static/v1?style=flat-square&label=neovim&message=v0.9%2b&logo=neovim&labelColor=282828&logoColor=8faa80&color=414b32)](https://neovim.io/)
[![kitty v0.29+](https://img.shields.io/badge/v0.29%2B-352217?style=flat-square&logo=data%3Aimage%2Fjpeg%3Bbase64%2C%2F9j%2F4AAQSkZJRgABAQAAAQABAAD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xaOkw93QayNVThtyyVjn5%2BbxcGG%2BoyxTHG8z%2BHv6XTU02Phrzmetu4M9fo66jHNo5ZKxynv5PAex6S10Y4nDine88rT2eOAAAAAAAAAAAAAAAAAAAAAAAAAAA0wYb6jLFMcbzP4MGG%2BoyxTHG8z%2BHv6XTU02Lhpzmetu4Gl01NNj4a85nrbu5fSOv9VE4sM%2B%2F4z8v%2FT0jr%2FVb4sM%2B%2FwCNvl%2F68br1A6zzAAF64ct43pjvaO8VmU%2BzZ%2F2cn9ZBmNfZs%2F7OT%2Bsns2f9nJ%2FWQZDT2bP%2Bzk%2FrKLYctI3vjvWO81mAUAAAAAAAAAAAAAAAAAAAB6vobJirjvWZiMkzvz8YX9IekIxxOLBaJvPW0eDxwDr1AAI68%2BgA%2BmwXx2xVnFMTXblsu%2BWAfVIfLAPqVM18dMVpyzEV257vmQCevIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAH%2F9k%3D&label=kitty&labelColor=282828)](https://sw.kovidgoyal.net/kitty/)
[![semantic-release: angular](https://img.shields.io/static/v1?style=flat-square&label=semantic-release&message=angular&logo=semantic-release&labelColor=282828&logoColor=d8869b&color=8f3f71)](https://github.com/semantic-release/semantic-release)
[![test status](https://img.shields.io/github/actions/workflow/status/mikesmithgh/kitty-scrollback.nvim/test.yml?style=flat-square&logo=github&logoColor=c7c7c7&label=tests&labelColor=282828&event=push)](https://github.com/mikesmithgh/kitty-scrollback.nvim/actions/workflows/test.yml)
[![test status](https://img.shields.io/github/actions/workflow/status/mikesmithgh/kitty-scrollback.nvim/test.yml?style=flat-square&logo=github&logoColor=c7c7c7&label=tests&labelColor=282828&event=push)](https://github.com/mikesmithgh/kitty-scrollback.nvim/actions/workflows/test.yml?query=event%3Apush)
[![nightly test status](https://img.shields.io/github/actions/workflow/status/mikesmithgh/kitty-scrollback.nvim/test.yml?style=flat-square&logo=github&logoColor=c7c7c7&label=nightly%20tests&labelColor=282828&event=schedule)](https://github.com/mikesmithgh/kitty-scrollback.nvim/actions/workflows/test.yml?query=event%3Aschedule)

<a href="https://github.com/mikesmithgh/kitty-scrollback.nvim/wiki/kitty_scrollback_nvim">
<picture>
Expand Down
1 change: 1 addition & 0 deletions doc/kitty-scrollback.nvim_spec.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ KsbKittyData *kitty-scrollback.launch.KsbKittyData*
{kitty_opts} (KsbKittyOpts) relevant kitty configuration values
{kitty_config_dir} (string) kitty configuration directory path
{kitty_version} (table) kitty version
{kitty_path} (string) kitty executable path


KsbPrivate *kitty-scrollback.launch.KsbPrivate*
Expand Down
2 changes: 1 addition & 1 deletion lua/kitty-scrollback/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ M.checkhealth = function()
if vim.fn.has('nvim-0.9') > 0 then
vim
.system({
'kitty',
p.kitty_data.kitty_path,
'@',
'kitten',
kitty_scrollback_kitten,
Expand Down
7 changes: 4 additions & 3 deletions lua/kitty-scrollback/health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ end
local function check_kitty_remote_control()
vim.health.start('kitty-scrollback: Kitty remote control')
local cmd = {
'kitty',
p.kitty_data.kitty_path,
'@',
'ls',
}
Expand Down Expand Up @@ -206,8 +206,9 @@ local function check_kitty_debug_config()
local kitty_debug_config_kitten =
vim.api.nvim_get_runtime_file('python/kitty_debug_config.py', false)[1]
local debug_config_log = vim.fn.stdpath('data') .. '/kitty-scrollback.nvim/debug_config.log'
local result =
vim.system({ 'kitty', '@', 'kitten', kitty_debug_config_kitten, debug_config_log }):wait()
local result = vim
.system({ p.kitty_data.kitty_path, '@', 'kitten', kitty_debug_config_kitten, debug_config_log })
:wait()
if result.code == 0 then
if vim.fn.filereadable(debug_config_log) then
vim.health.ok(table.concat(vim.fn.readfile(debug_config_log), '\n '))
Expand Down
2 changes: 1 addition & 1 deletion lua/kitty-scrollback/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ M.setup = function(configs)
})

---@brief [[
---:KittyScrollbackGenerateKittens Run `:checkhealth kitty-scrollback` in the context of Kitty
---:KittyScrollbackCheckHealth Run `:checkhealth kitty-scrollback` in the context of Kitty
---
--- See: ~
--- |kitty.api.checkhealth|
Expand Down
26 changes: 15 additions & 11 deletions lua/kitty-scrollback/kitty_commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,12 @@ end

M.get_text_term = function(kitty_data, get_text_opts, on_exit_cb)
local esc = vim.fn.eval([["\e"]])
local kitty_get_text_cmd =
string.format([[kitty @ get-text --match="id:%s" %s]], kitty_data.window_id, get_text_opts)
local kitty_get_text_cmd = string.format(
[[%s @ get-text --match="id:%s" %s]],
p.kitty_data.kitty_path,
kitty_data.window_id,
get_text_opts
)
local sed_cmd = string.format(
[[sed -E ]]
.. [[-e 's/%s\[\?25.%s\[.*;.*H%s\[.*//g' ]] -- remove control sequence added by --add-cursor flag
Expand All @@ -132,7 +136,7 @@ M.get_text_term = function(kitty_data, get_text_opts, on_exit_cb)
esc,
esc
)
local flush_stdout_cmd = [[kitty +runpy 'sys.stdout.flush()']]
local flush_stdout_cmd = p.kitty_data.kitty_path .. [[ +runpy 'sys.stdout.flush()']]
-- start to set title but do not complete see https://github.com/kovidgoyal/kitty/issues/719#issuecomment-952039731
local start_set_title_cmd = string.format([[printf '%s]2;']], esc)
local full_cmd = kitty_get_text_cmd
Expand Down Expand Up @@ -245,7 +249,7 @@ M.send_paste_buffer_text_to_kitty_and_quit = function(execute_command)
end

system_handle_error({
'kitty',
p.kitty_data.kitty_path,
'@',
'send-text',
'--match=id:' .. p.kitty_data.window_id,
Expand All @@ -256,7 +260,7 @@ end

M.list_kitty_windows = function()
return system_handle_error({
'kitty',
p.kitty_data.kitty_path,
'@',
'ls',
})
Expand All @@ -267,7 +271,7 @@ M.close_kitty_loading_window = function(ignore_error)
local winid = p.kitty_loading_winid
p.kitty_loading_winid = nil
return system_handle_error({
'kitty',
p.kitty_data.kitty_path,
'@',
'close-window',
'--match=id:' .. winid,
Expand All @@ -278,7 +282,7 @@ end

M.signal_winchanged_to_kitty_child_process = function()
system_handle_error({
'kitty',
p.kitty_data.kitty_path,
'@',
'signal-child',
'SIGWINCH',
Expand All @@ -290,7 +294,7 @@ M.signal_term_to_kitty_child_process = function(force)
vim.cmd.quitall({ bang = true })
else
system_handle_error({
'kitty',
p.kitty_data.kitty_path,
'@',
'signal-child',
'SIGTERM',
Expand All @@ -303,7 +307,7 @@ M.open_kitty_loading_window = function(env)
M.close_kitty_loading_window(true)
end
local kitty_cmd = vim.list_extend({
'kitty',
p.kitty_data.kitty_path,
'@',
'launch',
'--type',
Expand Down Expand Up @@ -332,7 +336,7 @@ end
M.get_kitty_colors = function(kitty_data, ignore_error, no_window_id)
local match = no_window_id and nil or '--match=id:' .. kitty_data.window_id
local ok, result = system_handle_error({
'kitty',
p.kitty_data.kitty_path,
'@',
'get-colors',
match,
Expand All @@ -351,7 +355,7 @@ end

M.send_text_to_clipboard = function(text)
return system_handle_error({
'kitty',
p.kitty_data.kitty_path,
'+kitten',
'clipboard',
'/dev/stdin',
Expand Down
1 change: 1 addition & 0 deletions lua/kitty-scrollback/launch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ local M = {}
---@field kitty_opts KsbKittyOpts relevant kitty configuration values
---@field kitty_config_dir string kitty configuration directory path
---@field kitty_version table kitty version
---@field kitty_path string kitty executable path

---@class KsbPrivate
---@field orig_columns number
Expand Down
60 changes: 38 additions & 22 deletions python/kitty_scrollback_nvim.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import json
import os
import inspect
import shutil

ksb_dir = os.path.dirname(
os.path.dirname(os.path.abspath(inspect.getfile(lambda: None))))
Expand All @@ -30,10 +31,11 @@ def get_kitty_shell_integration(kitty_opts, w):


# based on kitty source window.py
def pipe_data(w, target_window_id, config):
def pipe_data(w, target_window_id, config, kitty_path):
kitty_opts = get_options()
kitty_shell_integration = get_kitty_shell_integration(kitty_opts, w)
return {
'kitty_path': kitty_path,
'kitty_scrollback_config': config,
'scrolled_by': w.screen.scrolled_by,
'cursor_x': w.screen.cursor.x + 1,
Expand Down Expand Up @@ -110,6 +112,26 @@ def parse_cwd(args):
return ()


def nvim_err_cmd(err_file):
return (
'launch',
'--copy-env',
'--type',
'overlay',
'--title',
'kitty-scrollback.nvim :: error',
'nvim',
) + parse_nvim_args() + (
'-c',
'set laststatus=0',
'-c',
'set fillchars=eob:\\ ',
'-c',
'set filetype=checkhealth',
err_file,
)


@result_handler(type_of_input=None, no_ui=True, has_ready_notification=False)
def handle_result(args: List[str],
result: str,
Expand All @@ -118,28 +140,22 @@ def handle_result(args: List[str],
del args[0]
w = boss.window_id_map.get(target_window_id)
if w is not None:
kitty_path = shutil.which('kitty')
if not kitty_path:
boss.call_remote_control(
w,
nvim_err_cmd(f'{ksb_dir}/scripts/kitty_not_found.txt'))
return

config = parse_config(args)
if config == 'crying cat --config-file':
err_cmd = (
'launch',
'--copy-env',
'--type',
'overlay',
'--title',
'kitty-scrollback.nvim',
'nvim',
) + parse_nvim_args() + (
'-c',
'set laststatus=0',
'-c',
'set fillchars=eob:\\ ',
'-c',
'set filetype=checkhealth',
f'{ksb_dir}/scripts/breaking_change_config_file.txt',
)

err_winid = boss.call_remote_control(w, err_cmd)

err_winid = boss.call_remote_control(
w,
nvim_err_cmd(
f'{ksb_dir}/scripts/breaking_change_config_file.txt'))

# window logo is overridden by new neovim colorscheme
set_logo_cmd = ('set-window-logo',
'--no-response',
'--alpha',
Expand All @@ -149,12 +165,12 @@ def handle_result(args: List[str],
f'{ksb_dir}/media/sad_kitty_thumbs_up.png')

err_win = boss.window_id_map.get(err_winid)
err_winid = boss.call_remote_control(err_win, set_logo_cmd)
boss.call_remote_control(err_win, set_logo_cmd)
return

cwd = parse_cwd(args)
env = parse_env(args)
kitty_data_str = pipe_data(w, target_window_id, config)
kitty_data_str = pipe_data(w, target_window_id, config, kitty_path)
kitty_data = json.dumps(kitty_data_str)

if w.title.startswith('kitty-scrollback.nvim'):
Expand Down
18 changes: 18 additions & 0 deletions scripts/kitty_not_found.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
404 kitty not found ~

ERROR Sorry 😿

Failed to find kitty executable. Please check your environment variable `PATH`.


`|`\___/`|`
=) `^`Y`^` (=
\ *^* / If you have any issues or questions using *kitty-scrollback.nvim* then
` )=*=( ` please create an issue at
/ \ https://github.com/mikesmithgh/kitty-scrollback.nvim/issues
| |
/| | | |\
\| | `|`_`|`/\
/_// ___/
\_)

15 changes: 15 additions & 0 deletions tests/kitty-scrollback/kitty_scrollback_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@ describe('kitty-scrollback.nvim', function()
$ echo meow 󰄛 󰣐 
meow
$
]],
'kitty-scrollback.nvim content did not match the terminal screen'
)
end)

-- during brew search a, the PATH env changes. if we are not pointing to the correct kitty executable, it will error out
it('should use correct kitty path during brew command', function()
h.assert_screen_equals(
h.feed_kitty({
[[brew search a]],
[[\n]], -- enter
[[__open_ksb]],
}),
[[
$ brew search a 󰄛 󰣐 
]],
'kitty-scrollback.nvim content did not match the terminal screen'
)
Expand Down