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

feat: clear selection in kitty after paste closes #76 #84

Merged
merged 3 commits into from
Dec 1, 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
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- `git clone [email protected]/mikesmithgh/kitty-scrollback.nvim.wiki.git`
- `cd kitty-scrollback.nvim.wiki`
- `./scripts/record_main_demo.lua`
- `./scripts/record_demo_videos.lua`
- `ls -1 assets/*.mov | xargs -I {} scripts/mov_to_gif.sh {}`
- Upload all `mov` files in the `assets` directory to Github by dragging them to a markdown file in the browser
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ Navigate your Kitty scrollback buffer to quickly search, copy, and execute comma

<a href="https://github.com/mikesmithgh/kitty-scrollback.nvim/wiki/kitty_scrollback_nvim">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/mikesmithgh/kitty-scrollback.nvim/assets/10135646/3513aada-c19c-4e4a-bd9e-91b9907a2c8d">
<source media="(prefers-color-scheme: light)" srcset="https://github.com/mikesmithgh/kitty-scrollback.nvim/assets/10135646/3513aada-c19c-4e4a-bd9e-91b9907a2c8d">
<img alt="kitty-scrollback.nvim demo" src="https://github.com/mikesmithgh/kitty-scrollback.nvim/assets/10135646/3513aada-c19c-4e4a-bd9e-91b9907a2c8d">
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/mikesmithgh/kitty-scrollback.nvim/wiki/assets/kitty_scrollback_screencapture_00_kitty_scrollback_nvim.gif">
<source media="(prefers-color-scheme: light)" srcset="https://github.com/mikesmithgh/kitty-scrollback.nvim/wiki/assets/kitty_scrollback_screencapture_00_kitty_scrollback_nvim.gif">
<img alt="kitty-scrollback.nvim demo" src="https://github.com/mikesmithgh/kitty-scrollback.nvim/wiki/assets/kitty_scrollback_screencapture_00_kitty_scrollback_nvim.gif">
</picture>
<div align="center"><sup>(click for video)<sup></div>
</a>
Expand Down
20 changes: 14 additions & 6 deletions lua/kitty-scrollback/kitty_commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -221,21 +221,29 @@ M.get_text_term = function(kitty_data, get_text_opts, on_exit_cb)
vim.o.shell = p.orig_options.shell
end

M.send_paste_buffer_text_to_kitty_and_quit = function(bracketed_paste_mode)
M.send_paste_buffer_text_to_kitty_and_quit = function(execute_command)
-- convert table to string separated by carriage returns
local cmd_str = table.concat(
vim.tbl_filter(function(l)
return #l > 0
return #l > 0 -- remove empty lines
end, vim.api.nvim_buf_get_lines(p.paste_bufid, 0, -1, false)),
'\r'
)
-- wrap in bracketed paste mode
local esc = vim.fn.eval([["\e"]])
cmd_str = esc .. '[200~' .. cmd_str .. '\r' .. esc .. '[201~' -- see https://cirw.in/blog/bracketed-paste
-- if not bracketed paste mode trigger add a carriage return to execute command
if not bracketed_paste_mode then
local enquiry = '\x05' -- see https://en.wikipedia.org/wiki/Enquiry_character
local start_bracketed_paste = esc .. '[200~' -- see https://cirw.in/blog/bracketed-paste
local stop_bracketed_paste = esc .. '[201~' -- see https://cirw.in/blog/bracketed-paste

-- the beginning enquiry is used to separate any existing commands in kitty that may end with escape
-- if escape is present, then bash autocompletion will be triggered because bracketed paste mode starts with an escape
-- the ending enquiry is used to remove deselect the text after pasting to the terminal
cmd_str = enquiry .. start_bracketed_paste .. cmd_str .. stop_bracketed_paste .. enquiry

if not execute_command then
-- add a carriage return to execute command
cmd_str = cmd_str .. '\r'
end

system_handle_error({
'kitty',
'@',
Expand Down
Loading