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

fix: use set title to remove process exited msg #33

Merged
merged 2 commits into from
Oct 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/vimdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
- '**'
paths:
- README.md
- .github/workflows/panvimdoc.yml
- .github/workflows/vimdocs.yml
- doc/**
- lua/kitty-scrollback/launch.lua
- lua/kitty-scrollback/api.lua
Expand Down
4 changes: 2 additions & 2 deletions doc/kitty-scrollback.nvim.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*kitty-scrollback.nvim.txt* For NVIM v0.10+ Last change: 2023 October 01
*kitty-scrollback.nvim.txt* For NVIM v0.10+ Last change: 2023 October 15

==============================================================================
Table of Contents *kitty-scrollback.nvim-table-of-contents*
Expand All @@ -21,7 +21,7 @@ Table of Contents *kitty-scrollback.nvim-table-of-contents*
==============================================================================
1. kitty-scrollback.nvim *kitty-scrollback.nvim-kitty-scrollback.nvim*

Navigate your Kitty scrollback buffer to quickly search, copy, or execute
Navigate your Kitty scrollback buffer to quickly search, copy, and execute
commands in Neovim.


Expand Down
10 changes: 0 additions & 10 deletions lua/kitty-scrollback/autocommands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,6 @@ M.set_term_enter_autocmd = function(bufid)
callback = function(e)
if e.buf == bufid then
ksb_win.open_paste_window(true)

-- when performing last cmd or visited output, every time termenter is triggered it
-- is restoring the process exited message, this may be a bug in neovim
vim.fn.timer_start(20, function(t) ---@diagnostic disable-line: redundant-parameter
if ksb_util.remove_process_exited() then
vim.fn.timer_stop(t)
end
end, {
['repeat'] = 100,
})
end
end,
})
Expand Down
18 changes: 15 additions & 3 deletions lua/kitty-scrollback/kitty_commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,27 @@ M.get_text_term = function(kitty_data, get_text_opts, on_exit_cb)
local kitty_get_text_cmd =
string.format([[kitty @ get-text --match="id:%s" %s]], kitty_data.window_id, get_text_opts)
local sed_cmd = string.format(
[[sed -E -e 's/$/%s[0m/g' ]] -- append all lines with reset to avoid unintended colors
.. [[-e 's/%s\[\?25.%s\[.*;.*H%s\[.*//g']], -- remove control sequence added by --add-cursor flag
[[sed -E ]]
.. [[-e 's/%s\[\?25.%s\[.*;.*H%s\[.*//g' ]] -- remove control sequence added by --add-cursor flag
.. [[-e 's/$/%s[0m/g' ]], -- append all lines with reset to avoid unintended colors
esc,
esc,
esc,
esc
)
local flush_stdout_cmd = [[kitty +runpy 'sys.stdout.flush()']]
local full_cmd = kitty_get_text_cmd .. ' | ' .. sed_cmd .. ' && ' .. flush_stdout_cmd
-- 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
.. ' | '
.. sed_cmd
-- TODO: find scenario where I needed sed and possibly remove?
-- - reproduced on v1.0.0 but can't repro on this with: bat --no-pager ~/.bashrc; printf "before \x1b[1;1H after\n"
-- - may not need, but need to write tests first
.. ' && '
.. flush_stdout_cmd
.. ' && '
.. start_set_title_cmd
local stdout
local stderr
local tail_max = 10
Expand Down
60 changes: 25 additions & 35 deletions lua/kitty-scrollback/launch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -389,41 +389,31 @@ M.launch = function()
vim.schedule(function()
ksb_kitty_cmds.get_text_term(kitty_data, get_text_opts, function()
ksb_kitty_cmds.signal_winchanged_to_kitty_child_process()
vim.fn.timer_start(20, function(t) ---@diagnostic disable-line: redundant-parameter
local timer_info = vim.fn.timer_info(t)[1] or {}
local ready = ksb_util.remove_process_exited()
if ready or timer_info['repeat'] == 0 then
vim.fn.timer_stop(t)

if opts.kitty_get_text.extent == 'screen' or opts.kitty_get_text.extent == 'all' then
set_cursor_position(kitty_data)
end
ksb_win.show_status_window()

-- improve buffer name to avoid displaying complex command to user
local term_buf_name = vim.api.nvim_buf_get_name(p.bufid)
term_buf_name = term_buf_name:gsub('^(term://.-:).*', '%1kitty-scrollback.nvim')
vim.api.nvim_buf_set_name(p.bufid, term_buf_name)
vim.api.nvim_buf_delete(vim.fn.bufnr('#'), { force = true }) -- delete alt buffer after rename

if opts.restore_options then
restore_orig_options()
end
if
opts.callbacks
and opts.callbacks.after_ready
and type(opts.callbacks.after_ready) == 'function'
then
ksb_util.restore_and_redraw()
vim.schedule(function()
opts.callbacks.after_ready(kitty_data, opts)
end)
end
ksb_api.close_kitty_loading_window()
end
end, {
['repeat'] = 200,
})
if opts.kitty_get_text.extent == 'screen' or opts.kitty_get_text.extent == 'all' then
set_cursor_position(kitty_data)
end
ksb_win.show_status_window()

-- improve buffer name to avoid displaying complex command to user
local term_buf_name = vim.api.nvim_buf_get_name(p.bufid)
term_buf_name = term_buf_name:gsub('^(term://.-:).*', '%1kitty-scrollback.nvim')
vim.api.nvim_buf_set_name(p.bufid, term_buf_name)
vim.api.nvim_buf_delete(vim.fn.bufnr('#'), { force = true }) -- delete alt buffer after rename

if opts.restore_options then
restore_orig_options()
end
if
opts.callbacks
and opts.callbacks.after_ready
and type(opts.callbacks.after_ready) == 'function'
then
ksb_util.restore_and_redraw()
vim.schedule(function()
opts.callbacks.after_ready(kitty_data, opts)
end)
end
ksb_api.close_kitty_loading_window()
end)
end)
if
Expand Down
5 changes: 5 additions & 0 deletions lua/kitty-scrollback/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ M.screaming_snakecase = function(s)
:upper()
end

--- @deprecated
--- should no longer need this because we are using set title workaround
--- to remove the process exited message
--- see https://github.com/kovidgoyal/kitty/issues/719#issuecomment-952039731
M.remove_process_exited = function()
-- TODO: delete function after verifying no longer needed
local last_line_range = vim.api.nvim_buf_line_count(p.bufid) - vim.o.lines
if last_line_range < 1 then
last_line_range = 1
Expand Down
2 changes: 1 addition & 1 deletion python/kitty_scrollback_nvim.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def pipe_data(w, target_window_id, ksb_dir, config_files):
'scrolled_by': w.screen.scrolled_by,
'cursor_x': w.screen.cursor.x + 1,
'cursor_y': w.screen.cursor.y + 1,
'lines': w.screen.lines,
'lines': w.screen.lines + 1,
'columns': w.screen.columns,
'window_id': int(target_window_id),
'window_title': w.title,
Expand Down