Skip to content

Commit

Permalink
fix: prevent caught deadly signal message on exit (#155)
Browse files Browse the repository at this point in the history
closes #135
  • Loading branch information
mikesmithgh authored Jan 9, 2024
1 parent a852f2d commit 00a0b5f
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 31 deletions.
2 changes: 1 addition & 1 deletion doc/kitty-scrollback.nvim_spec.txt
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ M.setup() *kitty-scrollback.api.setup*


M.quit_all() *kitty-scrollback.api.quit_all*
Attempt to gracefully quit Neovim. How do you exit vim? Why would you exit vim?
Attempt to force quit Neovim. How do you exit vim? Why would you exit vim?


M.close_or_quit_all() *kitty-scrollback.api.close_or_quit_all*
Expand Down
6 changes: 2 additions & 4 deletions lua/kitty-scrollback/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ M.setup = function(private, options)
opts = options ---@diagnostic disable-line: unused-local
end

---Attempt to gracefully quit Neovim. How do you exit vim? Why would you exit vim?
---Attempt to force quit Neovim. How do you exit vim? Why would you exit vim?
M.quit_all = function()
-- quit causes nvim to exit early sometime interrupting underlying copy child process (.e.g, xclip)
-- send sigterm to gracefully terminate
vim.schedule(ksb_kitty_cmds.signal_term_to_kitty_child_process)
ksb_util.quitall()
end

---If the current buffer is the paste buffer, then close the window
Expand Down
14 changes: 11 additions & 3 deletions lua/kitty-scrollback/autocommands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,16 @@ M.set_yank_post_autocmd = function()

if yankevent.regname == '+' then
if vim.fn.has('clipboard') > 0 then
-- contents are copied to clipboard, return to kitty
ksb_api.quit_all()
-- Contents are copied to clipboard, return to kitty
-- Previously Kitty was used to quit nvim by sending a SIGTERM signal avoid exiting nvim early.
-- The xclip child process was not spawning quick enough in the TextYankPost autocommand, resulting
-- in content not being copied to the clipboard. This was observed running Ubuntu on UTM.
-- The side effect of this is that the message Vim: Caught deadly signal 'SIGTERM' would briefly
-- flash before exiting kitty-scrollback.nvim. To avoid the deadly signal message and provide time
-- for xclip to start, defer calling quitall by 100 ms
vim.defer_fn(function()
vim.cmd.quitall({ bang = true })
end, 100)
else
vim.schedule(function()
local prompt_msg =
Expand All @@ -147,7 +155,7 @@ M.set_yank_post_autocmd = function()
ksb_util.restore_and_redraw()
local response = vim.fn.confirm(prompt_msg, '&Quit\n&Continue')
if response ~= 2 then
ksb_api.quit_all()
ksb_util.quitall()
end
end)
end
Expand Down
17 changes: 2 additions & 15 deletions lua/kitty-scrollback/kitty_commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ local display_error = function(cmd, r)
ksb_util.restore_and_redraw()
local response = vim.fn.confirm(prompt_msg, '&Quit\n&Continue')
if response ~= 2 then
M.signal_term_to_kitty_child_process(true)
ksb_util.quitall()
end
end

Expand Down Expand Up @@ -246,7 +246,7 @@ M.send_lines_to_kitty_and_quit = function(lines, execute_command)
'--match=id:' .. p.kitty_data.window_id,
cmd_str,
})
M.signal_term_to_kitty_child_process()
ksb_util.quitall()
end

M.send_paste_buffer_text_to_kitty_and_quit = function(execute_command)
Expand Down Expand Up @@ -285,19 +285,6 @@ M.signal_winchanged_to_kitty_child_process = function()
})
end

M.signal_term_to_kitty_child_process = function(force)
if force then
vim.cmd.quitall({ bang = true })
else
system_handle_error({
p.kitty_data.kitty_path,
'@',
'signal-child',
'SIGTERM',
})
end
end

M.open_kitty_loading_window = function(env)
if p.kitty_loading_winid then
M.close_kitty_loading_window(true)
Expand Down
4 changes: 2 additions & 2 deletions lua/kitty-scrollback/launch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ M.setup = function(kitty_data_str)
.. table.concat(ksb_health.advice().nvim_version)
local response = vim.fn.confirm(prompt_msg, '&Quit\n&Continue')
if response ~= 2 then
ksb_kitty_cmds.signal_term_to_kitty_child_process(true)
ksb_util.quitall()
end
end
if not ksb_health.check_kitty_version(true) then
Expand All @@ -342,7 +342,7 @@ M.setup = function(kitty_data_str)
.. table.concat(ksb_health.advice().kitty_version)
local response = vim.fn.confirm(prompt_msg, '&Quit\n&Continue')
if response ~= 2 then
ksb_kitty_cmds.signal_term_to_kitty_child_process(true)
ksb_util.quitall()
end
end

Expand Down
4 changes: 4 additions & 0 deletions lua/kitty-scrollback/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,8 @@ M.clear_yank_autocommand_and_get_visual_selection = function()
return reginfo.regcontents
end

M.quitall = function()
vim.cmd.quitall({ bang = true })
end

return M
9 changes: 3 additions & 6 deletions tests/kitty-scrollback/kitty_scrollback_demo_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,6 @@ $

it('should_copy_visual_selection_to_clipboard', function()
local paste = function()
-- TODO(#135): github runner has issues accessing the clipboard
-- just hardcode it for now since this test is for primarily for demo purposes anyway
if h.is_github_action then
return 'README.md'
end
return vim.fn.getreg('+')
end
h.feed_kitty({
Expand All @@ -194,7 +189,9 @@ $
}, 0)
h.assert_screen_equals(
h.feed_kitty({
h.send_without_newline([[printf "\n kitty-scrollback.nvim copied \e[35m]]),
h.with_pause_seconds_before(
h.send_without_newline([[printf "\n kitty-scrollback.nvim copied \e[35m]])
),
h.with_pause_seconds_before(h.send_without_newline(h.send_as_string(paste())), 1),
h.with_pause_seconds_before([[\e[0m to clipboard\n\n"]], 1),
}),
Expand Down

0 comments on commit 00a0b5f

Please sign in to comment.