From 684dd833ef6a0ee0c2992b510cbe7119d44ae419 Mon Sep 17 00:00:00 2001 From: Mike <10135646+mikesmithgh@users.noreply.github.com> Date: Sat, 14 Oct 2023 22:57:18 -0400 Subject: [PATCH] fix: use set title to remove process exited msg (#33) --- .github/workflows/vimdocs.yml | 2 +- doc/kitty-scrollback.nvim.txt | 4 +- lua/kitty-scrollback/autocommands.lua | 10 ----- lua/kitty-scrollback/kitty_commands.lua | 18 ++++++-- lua/kitty-scrollback/launch.lua | 60 +++++++++++-------------- lua/kitty-scrollback/util.lua | 5 +++ python/kitty_scrollback_nvim.py | 2 +- 7 files changed, 49 insertions(+), 52 deletions(-) diff --git a/.github/workflows/vimdocs.yml b/.github/workflows/vimdocs.yml index 2ca5e4a0..a4f816de 100644 --- a/.github/workflows/vimdocs.yml +++ b/.github/workflows/vimdocs.yml @@ -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 diff --git a/doc/kitty-scrollback.nvim.txt b/doc/kitty-scrollback.nvim.txt index d37180b2..d1835332 100644 --- a/doc/kitty-scrollback.nvim.txt +++ b/doc/kitty-scrollback.nvim.txt @@ -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* @@ -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. diff --git a/lua/kitty-scrollback/autocommands.lua b/lua/kitty-scrollback/autocommands.lua index ca3b431f..e4710237 100644 --- a/lua/kitty-scrollback/autocommands.lua +++ b/lua/kitty-scrollback/autocommands.lua @@ -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, }) diff --git a/lua/kitty-scrollback/kitty_commands.lua b/lua/kitty-scrollback/kitty_commands.lua index ef6f4483..8a0cee46 100644 --- a/lua/kitty-scrollback/kitty_commands.lua +++ b/lua/kitty-scrollback/kitty_commands.lua @@ -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 diff --git a/lua/kitty-scrollback/launch.lua b/lua/kitty-scrollback/launch.lua index aca92753..7feca1ea 100644 --- a/lua/kitty-scrollback/launch.lua +++ b/lua/kitty-scrollback/launch.lua @@ -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 diff --git a/lua/kitty-scrollback/util.lua b/lua/kitty-scrollback/util.lua index ba894019..62882e43 100644 --- a/lua/kitty-scrollback/util.lua +++ b/lua/kitty-scrollback/util.lua @@ -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 diff --git a/python/kitty_scrollback_nvim.py b/python/kitty_scrollback_nvim.py index 0f24aa68..81d4d17e 100755 --- a/python/kitty_scrollback_nvim.py +++ b/python/kitty_scrollback_nvim.py @@ -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,