Skip to content

Commit

Permalink
chore: replace add-cursor with add-wrap-markers (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikesmithgh authored Jan 9, 2024
1 parent 4696f08 commit a852f2d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
11 changes: 5 additions & 6 deletions lua/kitty-scrollback/health.lua
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,16 @@ local function check_sed()
return
end

local esc = vim.fn.eval([["\e"]])
local cmd = {
'sed',
'-E',
'-e',
's/$/' .. esc .. '[0m/g',
[[s/\r//g]],
'-e',
's/' .. esc .. '\\[\\?25.' .. esc .. '\\[.*;.*H' .. esc .. '\\[.*//g',
[[s/$/\x1b[0m/g]],
}
local ok, sed_proc = pcall(vim.system, cmd, {
stdin = 'expected' .. esc .. '[?25h' .. esc .. '[1;1H' .. esc .. '[notexpected',
stdin = 'expected\r',
})
local result = {}
if ok then
Expand All @@ -124,7 +123,7 @@ local function check_sed()
result.stdout = ''
result.stderr = sed_proc
end
ok = ok and result.code == 0 and result.stdout == 'expected'
ok = ok and result.code == 0 and result.stdout == 'expected\x1b[0m'
if ok then
vim.health.ok(
'`'
Expand All @@ -150,7 +149,7 @@ local function check_sed()
.. result.code
.. '* and stdout `'
.. result.stdout
.. '` (should be `expected`)\n'
.. '` (should be `expected\x1b[0m`)\n'
.. result_err
.. '`\n'
.. ' `sed: '
Expand Down
15 changes: 3 additions & 12 deletions lua/kitty-scrollback/kitty_commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -127,24 +127,15 @@ M.get_text_term = function(kitty_data, get_text_opts, on_exit_cb)
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
.. [[-e 's/$/%s[0m/g' ]], -- append all lines with reset to avoid unintended colors
esc,
esc,
esc,
esc
)
local sed_cmd = [[sed -E ]]
.. [[-e 's/\r//g' ]] -- added to remove /r added by --add-wrap-markers, (--add-wrap-markers is used to add empty lines at end of screen)
.. [[-e 's/$/\x1b[0m/g']] -- append all lines with reset to avoid unintended colors
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
.. ' | '
.. 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
.. ' && '
Expand Down
6 changes: 4 additions & 2 deletions lua/kitty-scrollback/launch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -401,9 +401,11 @@ M.launch = function()
extent = '--extent=' .. extent_opt
end

local add_cursor = '--add-cursor' -- always add cursor
-- always add wrap markers, wrap markers are important to add blank lines with /r to
-- fill the screen when setting the cursor position
local add_wrap_markers = '--add-wrap-markers'

local get_text_opts = ansi .. ' ' .. clear_selection .. ' ' .. add_cursor .. ' ' .. extent
local get_text_opts = ansi .. ' ' .. clear_selection .. ' ' .. add_wrap_markers .. ' ' .. extent

-- 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
Expand Down

0 comments on commit a852f2d

Please sign in to comment.