diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8bed9161..bcdba6f5 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -36,7 +36,7 @@ jobs: - 'stable' # v0.10.0 - 'nightly' kitty_version: - - 'stable' # 0.34.1 + - 'stable' # 0.36.+ - 'nightly' # update __branch-protection-rules.json and run __update_branch_protection_rules.sh when modified # test all version of nvim released as of v0.9.0 @@ -52,6 +52,10 @@ jobs: kitty_version: '0.32.2' - nvim_version: 'stable' kitty_version: '0.33.1' + - nvim_version: 'stable' + kitty_version: '0.34.1' + - nvim_version: 'stable' + kitty_version: '0.35.2' fail-fast: false runs-on: ubuntu-22.04 steps: diff --git a/CHANGELOG.md b/CHANGELOG.md index d0c06372..37b283fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [5.0.1](https://github.com/mikesmithgh/kitty-scrollback.nvim/compare/v5.0.0...v5.0.1) (2024-08-20) + + +### Bug Fixes + +* defer setting 'columns' to hardwrap at 300 columns ([#267](https://github.com/mikesmithgh/kitty-scrollback.nvim/issues/267)) ([2f267c3](https://github.com/mikesmithgh/kitty-scrollback.nvim/commit/2f267c315bea50cd67ea3fd23f78e586fb2915c5)) + # [5.0.0](https://github.com/mikesmithgh/kitty-scrollback.nvim/compare/v4.3.6...v5.0.0) (2024-06-07) diff --git a/lua/kitty-scrollback/backport/backport-sha.json b/lua/kitty-scrollback/backport/backport-sha.json index a2603890..f50d47a2 100644 --- a/lua/kitty-scrollback/backport/backport-sha.json +++ b/lua/kitty-scrollback/backport/backport-sha.json @@ -1,4 +1,4 @@ { "runtime/lua/vim/_system.lua": "691140fdecfa0c3dd28bd68505a47941c26fdf7efb9bfcd72d338e0cb59fe466", - "runtime/lua/vim/version.lua": "a5308820de020cb21e23109a5c03a338547660f9b677509f5129b337079bd453" + "runtime/lua/vim/version.lua": "6d5b925c8af9ad769c6a19e89319a8ad12def13a4184135f490a3b0cb0add4ef" } diff --git a/lua/kitty-scrollback/backport/init.lua b/lua/kitty-scrollback/backport/init.lua index 535a7868..d207f222 100644 --- a/lua/kitty-scrollback/backport/init.lua +++ b/lua/kitty-scrollback/backport/init.lua @@ -8,7 +8,7 @@ local M = {} local function backport_version() if type(vim.version().__tostring) ~= 'function' then -- NOTE: copied __tostring from - -- https://github.com/neovim/neovim/blob/8ba552bd59b0ed9f316ad1473126b603f35c912a/runtime/lua/vim/version.lua#L125 + -- https://github.com/neovim/neovim/blob/0d3f2c4904d552635da07a6e2b4e75520b514940/runtime/lua/vim/version.lua#L125 local Version = {} function Version:__tostring() @@ -27,7 +27,7 @@ local function backport_version() end -- NOTE: copied setmetatable from - -- https://github.com/neovim/neovim/blob/8ba552bd59b0ed9f316ad1473126b603f35c912a/runtime/lua/vim/version.lua#L451 + -- https://github.com/neovim/neovim/blob/0d3f2c4904d552635da07a6e2b4e75520b514940/runtime/lua/vim/version.lua#L455 setmetatable(vim.version, { --- Returns the current Nvim version. ---@return vim.Version diff --git a/lua/kitty-scrollback/kitty_commands.lua b/lua/kitty-scrollback/kitty_commands.lua index 6b0e029c..ade8afc2 100644 --- a/lua/kitty-scrollback/kitty_commands.lua +++ b/lua/kitty-scrollback/kitty_commands.lua @@ -52,6 +52,17 @@ local function get_scrollback_cmd(get_text_args) return scrollback_cmd, full_cmd end +local function defer_resize_term(min_cols) + local orig_columns = vim.o.columns + if vim.o.columns < min_cols then + vim.defer_fn(function() + vim.o.columns = min_cols + vim.api.nvim_set_option_value('columns', min_cols, { scope = 'global' }) + end, 0) + end + return orig_columns +end + ---@param get_text_opts KsbKittyGetTextArguments ---@param on_exit_cb function M.get_text_term = function(get_text_opts, on_exit_cb) @@ -60,9 +71,14 @@ M.get_text_term = function(get_text_opts, on_exit_cb) local stderr local tail_max = 10 + -- increase the number of columns temporary so that the width is used during the + -- terminal command kitty @ get-text. this avoids hard wrapping lines to the + -- current window size. Note: a larger min_cols appears to impact performance + -- defer is used as a timing workaround because this is expected to be called right before termopen + p.orig_columns = defer_resize_term(300) + -- set the shell used for termopen to sh to avoid imcompatabiliies with other shells (e.g., nushell, fish, etc) vim.o.shell = 'sh' - local success, error = pcall(vim.fn.termopen, full_cmd, { stdout_buffered = true, stderr_buffered = true, @@ -73,6 +89,11 @@ M.get_text_term = function(get_text_opts, on_exit_cb) stderr = data end, on_exit = function(id, exit_code, event) + -- NOTE(#58): nvim v0.9 support + -- vim.o.columns is resized automatically in nvim v0.9.1 when we trigger kitty so send a SIGWINCH signal + -- vim.o.columns is explicitly set to resize appropriatley on v0.9.0 + -- see https://github.com/neovim/neovim/pull/23503 + vim.o.columns = p.orig_columns if exit_code == 0 then -- no need to check allow_remote_control or dev/tty because earlier commands would have reported the error if #stdout >= 2 then diff --git a/lua/kitty-scrollback/launch.lua b/lua/kitty-scrollback/launch.lua index 81484ad0..a5236f2f 100644 --- a/lua/kitty-scrollback/launch.lua +++ b/lua/kitty-scrollback/launch.lua @@ -389,22 +389,8 @@ M.launch = function() ksb_autocmds.load_autocmds() - -- increase the number of columns temporary so that the width is used during the - -- terminal command kitty @ get-text. this avoids hard wrapping lines to the - -- current window size. Note: a larger min_cols appears to impact performance - local min_cols = 300 - p.orig_columns = vim.o.columns - if vim.o.columns < min_cols then - vim.o.columns = min_cols - end vim.schedule(function() ksb_kitty_cmds.get_text_term(get_text_opts(), function() - -- NOTE(#58): nvim v0.9 support - -- vim.o.columns is resized automatically in nvim v0.9.1 when we trigger kitty so send a SIGWINCH signal - -- vim.o.columns is explicitly set to resize appropriatley on v0.9.0 - -- see https://github.com/neovim/neovim/pull/23503 - vim.o.columns = p.orig_columns - ksb_kitty_cmds.signal_winchanged_to_kitty_child_process() if opts.kitty_get_text.extent == 'screen' or opts.kitty_get_text.extent == 'all' then set_cursor_position(p.kitty_data) diff --git a/scripts/internal/__branch-protection-rules.json b/scripts/internal/__branch-protection-rules.json index cd42475a..1fc6c6e4 100644 --- a/scripts/internal/__branch-protection-rules.json +++ b/scripts/internal/__branch-protection-rules.json @@ -11,7 +11,9 @@ "plenary (v0.9.0, stable)", "plenary (v0.9.5, stable)", "plenary (stable, 0.32.2)", - "plenary (stable, 0.33.1)" + "plenary (stable, 0.33.1)", + "plenary (stable, 0.34.1)", + "plenary (stable, 0.35.2)" ] }, "enforce_admins": false, diff --git a/tests/bashrc b/tests/bashrc index 08826e49..91575843 100644 --- a/tests/bashrc +++ b/tests/bashrc @@ -1,22 +1,22 @@ # thanks https://github.com/kalgynirae/dotfiles/blob/1203030bd44448088c4c1a42155a254171a31c4b/bashrc#L59 # Test the terminal's text/color capabilities colortest() { - local color escapes intensity style - echo "NORMAL bold dim itali under rever strik BRIGHT bold dim itali under rever strik" - for color in $(seq 0 7); do - for intensity in 3 9; do # normal, bright - escapes="${intensity}${color}" - printf '\e[%sm\\e[%sm\e[0m ' "$escapes" "$escapes" # normal - for style in 1 2 3 4 7 9; do # bold, dim, italic, underline, reverse, strikethrough - escapes="${intensity}${color};${style}" - printf '\e[%sm\\e[%sm\e[0m ' "$escapes" "$style" - done - echo -n " " - done - echo - done - echo -n "TRUECOLOR " - awk 'BEGIN{ + local color escapes intensity style + echo "NORMAL bold dim itali under rever strik BRIGHT bold dim itali under rever strik" + for color in $(seq 0 7); do + for intensity in 3 9; do # normal, bright + escapes="${intensity}${color}" + printf '\e[%sm\\e[%sm\e[0m ' "$escapes" "$escapes" # normal + for style in 1 2 3 4 7 9; do # bold, dim, italic, underline, reverse, strikethrough + escapes="${intensity}${color};${style}" + printf '\e[%sm\\e[%sm\e[0m ' "$escapes" "$style" + done + echo -n " " + done + echo + done + echo -n "TRUECOLOR " + awk 'BEGIN{ columns = 78; step = columns / 6; for (hue = 0; hue -> AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA -AA0123456789 -> ' - - -AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA -0123456789 -$ -]]), - cursor_y = 12, - cursor_x = 3, - }, - 'kitty-scrollback.nvim did not have expected removed wrap marker results' - ) - h.assert_screen_equals( - h.feed_kitty({ - h.send_without_newline(h.esc()), - }), - { - stdout = [[ -$ printf ' -> -> AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA0123456789 -> ' - - -AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA0123456789 -$ -]], - cursor_y = 12, - cursor_x = 3, - }, - 'kitty-scrollback.nvim did not have expected wrap marker results' - ) - end) - it('should temporarily block user input on start', function() h.kitty_remote_kitten_kitty_scrollback_nvim() h.assert_screen_not_match( @@ -481,4 +431,76 @@ Press ENTER or type command to continue.*]], } ) end) + + it([[should remove \r wrap markers and display line up to 300 columns]], function() + h.assert_screen_equals( + h.feed_kitty({ + h.send_as_string([[printf ' + +]] .. string.rep('A', 300) .. [[ +0123456789 +']]), + h.open_kitty_scrollback_nvim(), + }), + { + stdout = h.with_status_win([[ +$ printf ' +> +> AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA +AA0123456789 +> ' + + +AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA +0123456789 +$ +]]), + cursor_y = 12, + cursor_x = 3, + }, + 'kitty-scrollback.nvim did not have expected removed wrap marker results' + ) + h.assert_screen_equals( + h.feed_kitty({ + h.send_without_newline(h.esc()), + }), + { + stdout = [[ +$ printf ' +> +> AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA0123456789 +> ' + + +AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA0123456789 +$ +]], + cursor_y = 12, + cursor_x = 3, + }, + 'kitty-scrollback.nvim did not have expected wrap marker results' + ) + end) + + it('should hard wrap at 300 columns', function() + h.assert_screen_equals( + h.feed_kitty({ + h.with_pause_seconds_before( + [[for ((i = 0; i < 90; i++)); do echo -n "123456789|"; done; echo;]] + ), + h.open_kitty_scrollback_nvim(), + }), + { + stdout = h.with_status_win([[ +$ for ((i = 0; i < 90; i++)); do echo -n "123456789|"; done; echo; +123456789|123456789|123456789|123456789|123456789|123456789|123456789|123456789|123456789|123456789|1234567 +123456789|123456789|123456789|123456789|123456789|123456789|123456789|123456789|123456789|123456789|1234567 +123456789|123456789|123456789|123456789|123456789|123456789|123456789|123456789|123456789|123456789|1234567 +$ +]]), + cursor_y = 11, -- cursor position is not ideal but good enough for hardwrap workaround for now + cursor_x = 3, + } + ) + end) end)