Skip to content

Commit

Permalink
feat: make paste window yank register configurable closes #15 (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikesmithgh authored Sep 23, 2023
1 parent 5a5edb2 commit 31f75ea
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ Arguments that can be passed to the `kitty_scrollback_nvim` Kitten defined in [k
| paste_window.winblend | `integer?` | The winblend setting of the window, see :help winblend |
| paste_window.winopts_overrides | `fun(paste_winopts: KsbWinOpts): table<string,any>?` | Paste float window overrides, see nvim_open_win() for configuration |
| paste_window.footer_winopts_overrides | `fun(footer_winopts: KsbWinOpts, paste_winopts: KsbWinOpts): table<string,any>?` | Paste footer window overrides, see nvim_open_win() for configuration |
| paste_window.yank_register | `string?` | register used during yanks to paste window, see `:h registers` |
| paste_window.yank_register_enabled | `boolean?` | If true, the `yank_register` copies content to the paste window. If false, disable yank to paste window |
| kitty_get_text | `KsbKittyGetText?` | options passed to get-text when reading scrollback buffer, see `kitty @ get-text --help` |
| kitty_get_text.ansi | `boolean` | If true, the text will include the ANSI formatting escape codes for colors, bold, italic, etc. |
| kitty_get_text.clear_selection | `boolean` | If true, clear the selection in the matched window, if any. |
Expand Down
8 changes: 7 additions & 1 deletion 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 September 20
*kitty-scrollback.nvim.txt* For NVIM v0.10+ Last change: 2023 September 23

==============================================================================
Table of Contents *kitty-scrollback.nvim-table-of-contents*
Expand Down Expand Up @@ -274,6 +274,12 @@ KITTY-SCROLLBACK.NVIM CONFIGURATION FILE ~
paste_window.footer_winopts_overrides fun(footer_winopts: KsbWinOpts, paste_winopts: KsbWinOpts): table<string,any>? Paste footer window overrides, see nvim_open_win() for
configuration

paste_window.yank_register string? register used during yanks to paste window, see
:h registers

paste_window.yank_register_enabled boolean? If true, the yank_register copies content to the paste
window. If false, disable yank to paste window

kitty_get_text KsbKittyGetText? options passed to get-text when reading scrollback buffer,
see kitty @ get-text --help

Expand Down
4 changes: 3 additions & 1 deletion doc/kitty-scrollback.nvim_spec.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,14 @@ KsbFooterWinOptsOverrideFunction
KsbPasteWindowOpts

Fields: ~
{highlight_as_normal_win} (fun():boolean|nil) If function returns true, use Normal highlight group. If false, use NormalFloat
{highlight_as_normal_win} (nil|fun():boolean) If function returns true, use Normal highlight group. If false, use NormalFloat
{filetype} (string|nil) The filetype of the paste window
{hide_footer} (boolean|nil) If true, hide the footer when the paste window is initially opened
{winblend} (integer|nil) The winblend setting of the window, see :help winblend
{winopts_overrides} (KsbWinOptsOverrideFunction|nil) Paste float window overrides, see nvim_open_win() for configuration
{footer_winopts_overrides} (KsbFooterWinOptsOverrideFunction|nil) Paste footer window overrides, see nvim_open_win() for configuration
{yank_register} (string|nil) register used during yanks to paste window, see :h registers
{yank_register_enabled} (boolean|nil) If true, the `yank_register` copies content to the paste window. If false, disable yank to paste window


KsbOpts *kitty-scrollback.launch.KsbOpts*
Expand Down
6 changes: 5 additions & 1 deletion lua/kitty-scrollback/autocommands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ local ksb_win = require('kitty-scrollback.windows')
local M = {}

local p
---@type KsbOpts
local opts ---@diagnostic disable-line: unused-local

M.setup = function(private, options)
Expand Down Expand Up @@ -163,7 +164,10 @@ M.set_yank_post_autocmd = function()
end

-- send contents to paste window
if yankevent.regname == '' then
if
opts.paste_window.yank_register_enabled
and yankevent.regname == opts.paste_window.yank_register
then
if e.buf ~= p.bufid then
return
end
Expand Down
11 changes: 11 additions & 0 deletions lua/kitty-scrollback/configs/paste_win_register.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
local M = {}

M.config = function(kitty_data)
return {
paste_window = {
yank_register = '*',
},
}
end

return M
11 changes: 11 additions & 0 deletions lua/kitty-scrollback/configs/paste_win_register_disabled.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
local M = {}

M.config = function(kitty_data)
return {
paste_window = {
yank_register_enabled = false,
},
}
end

return M
6 changes: 5 additions & 1 deletion lua/kitty-scrollback/launch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,14 @@ local opts = {}
---@alias KsbFooterWinOptsOverrideFunction fun(footer_winopts:KsbWinOpts, paste_winopts:KsbWinOpts):KsbWinOpts

---@class KsbPasteWindowOpts
---@field highlight_as_normal_win fun():boolean|nil If function returns true, use Normal highlight group. If false, use NormalFloat
---@field highlight_as_normal_win nil|fun():boolean If function returns true, use Normal highlight group. If false, use NormalFloat
---@field filetype string|nil The filetype of the paste window
---@field hide_footer boolean|nil If true, hide the footer when the paste window is initially opened
---@field winblend integer|nil The winblend setting of the window, see :help winblend
---@field winopts_overrides KsbWinOptsOverrideFunction|nil Paste float window overrides, see nvim_open_win() for configuration
---@field footer_winopts_overrides KsbFooterWinOptsOverrideFunction|nil Paste footer window overrides, see nvim_open_win() for configuration
---@field yank_register string|nil register used during yanks to paste window, see :h registers
---@field yank_register_enabled boolean|nil If true, the `yank_register` copies content to the paste window. If false, disable yank to paste window

---@class KsbOpts
---@field callbacks KsbCallbacks|nil fire and forget callback functions
Expand Down Expand Up @@ -115,6 +117,8 @@ local default_opts = {
winblend = 0,
winopts_overrides = nil,
footer_winopts_overrides = nil,
yank_register = '',
yank_register_enabled = true,
},
kitty_get_text = {
ansi = true,
Expand Down

0 comments on commit 31f75ea

Please sign in to comment.