Skip to content

Commit

Permalink
feat!: redesign kitty-scrollback.nvim configuration (#118)
Browse files Browse the repository at this point in the history
closes #69

BREAKING CHANGE: kitty-scrollback.nvim loads your Neovim configuration by default. Previous versions of kitty-scrollback.nvim, did not load any configurations or plugins by default.

  - Previously, kitty-scrollback.nvim did not open Neovim with your Neovim configuration by default. This has changed to loading your Neovim 
  configuration by default, with the ability to opt out. If you prefer to continue not loading your Neovim configuration, then follow the
  steps at [No Configuration](#no-configuration).
  - If you previously used the flag `--no-nvim-args`, then delete it from your configuration because it no longer has any effect. The flag 
  `--nvim-args` remains unchanged and can still be used.
  - `ksb_example` configurations have been removed and can no longer be referenced by name. If you were previously referencing an example configuration
  by name, then you can manually copy it from [./tests/example.lua](./tests/example.lua) into your kitty-scrollback.nvim configuration. See 
  [Plugin Configuration](#plugin-configuration) for detailed instructions on configuration kitty-scrollback.nvim. 
  - The command `KittyScrollbackGenerateKittens` and api `generate_kittens` no longer have an option to generate `ksb_example` configurations.
    - The command `KittyScrollbackGenerateKittens` no longer accepts the bang `!` modifier
    - The api `generate_kittens` signature removed the `all` parameter
  - The reserved `global` configuration name has been removed and global options are now configured by the first element of the options table without a key.
  See [Global Configuration](#global-configuration) for more details.
  - The undocumented reserved `default` configuration name has been removed. kitty-scrollback.nvim defaults to `ksb_builtin_get_text_all` if no configuration is provided.
  • Loading branch information
mikesmithgh authored Jan 29, 2024
1 parent f5fb791 commit 97fea1b
Show file tree
Hide file tree
Showing 29 changed files with 1,532 additions and 1,001 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/vimdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: lemmyhelp
run: |
curl -Lq https://github.com/numToStr/lemmy-help/releases/latest/download/lemmy-help-x86_64-unknown-linux-gnu.tar.gz | tar xz
./lemmy-help -c -a -f lua/kitty-scrollback/launch.lua lua/kitty-scrollback/api.lua > doc/kitty-scrollback.nvim_spec.txt
./lemmy-help -c -a -f lua/kitty-scrollback/launch.lua lua/kitty-scrollback/configs/defaults.lua lua/kitty-scrollback/api.lua > doc/kitty-scrollback.nvim_spec.txt
- name: preformat README.md
run: |
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ make test-demo-config # run all demo configuration tests
- Upload all `mov` files in the `assets` directory to Github by dragging them to a markdown file in the browser
- Copy all the generated embedded video urls and paste in `uploaded_movs` array in the `make_video_markdown_files.sh` script
- `./scripts/make_video_markdown_files.sh`
- `./scripts/make_adv_config_markdown_file.lua &> Advanced-Configuration.md`
- `./scripts/make_adv_config_markdown_file.lua &> Advanced-Configuration-Examples.md`
## Troubleshooting
Expand Down
536 changes: 441 additions & 95 deletions README.md

Large diffs are not rendered by default.

632 changes: 514 additions & 118 deletions doc/kitty-scrollback.nvim.txt

Large diffs are not rendered by default.

64 changes: 30 additions & 34 deletions doc/kitty-scrollback.nvim_spec.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,33 +47,49 @@ KsbPrivate *kitty-scrollback.launch.KsbPrivate*
{pos} (table|nil)


KsbCallbacks *kitty-scrollback.launch.KsbCallbacks*
M.setup({kitty_data_str}) *kitty-scrollback.launch.setup*
Setup and configure kitty-scrollback.nvim

Parameters: ~
{kitty_data_str} (string)


M.launch() *kitty-scrollback.launch.launch*
Launch kitty-scrollack.nvim with configured scrollback buffer


M.setup_and_launch({kitty_data_str}) *kitty-scrollback.launch.setup_and_launch*
Setup and launch kitty-scrollback.nvim

Parameters: ~
{kitty_data_str} (string)


KsbCallbacks *default_opts.KsbCallbacks*

Fields: ~
{after_setup} (fun(kitty_data:KsbKittyData,opts:KsbOpts)|nil) callback executed after initializing kitty-scrollback.nvim
{after_launch} (fun(kitty_data:KsbKittyData,opts:KsbOpts)|nil) callback executed after launch started to process the scrollback buffer
{after_ready} (fun(kitty_data:KsbKittyData,opts:KsbOpts)|nil) callback executed after scrollback buffer is loaded and cursor is positioned


KsbKittyGetText *kitty-scrollback.launch.KsbKittyGetText*
KsbKittyGetText *default_opts.KsbKittyGetText*

Fields: ~
{ansi} (boolean) If true, the text will include the ANSI formatting escape codes for colors, bold, italic, etc.
{clear_selection} (boolean) If true, clear the selection in the matched window, if any.
{extent} (string|"screen"|"all"|"selection"|"first_cmd_output_on_screen"|"last_cmd_output"|"last_visited_cmd_output"|"last_non_empty_output") What text to get. The default of screen means all text currently on the screen. all means all the screen+scrollback and selection means the currently selected text. first_cmd_output_on_screen means the output of the first command that was run in the window on screen. last_cmd_output means the output of the last command that was run in the window. last_visited_cmd_output means the first command output below the last scrolled position via scroll_to_prompt. last_non_empty_output is the output from the last command run in the window that had some non empty output. The last four require shell_integration to be enabled. Choices: screen, all, first_cmd_output_on_screen, last_cmd_output, last_non_empty_output, last_visited_cmd_output, selection
{ansi} (boolean|nil) If true, the text will include the ANSI formatting escape codes for colors, bold, italic, etc.
{clear_selection} (boolean|nil) If true, clear the selection in the matched window, if any.
{extent} (string|nil|"screen"|"all"|"selection"|"first_cmd_output_on_screen"|"last_cmd_output"|"last_visited_cmd_output"|"last_non_empty_output") What text to get. The default of screen means all text currently on the screen. all means all the screen+scrollback and selection means the currently selected text. first_cmd_output_on_screen means the output of the first command that was run in the window on screen. last_cmd_output means the output of the last command that was run in the window. last_visited_cmd_output means the first command output below the last scrolled position via scroll_to_prompt. last_non_empty_output is the output from the last command run in the window that had some non empty output. The last four require shell_integration to be enabled. Choices: screen, all, first_cmd_output_on_screen, last_cmd_output, last_non_empty_output, last_visited_cmd_output, selection


*kitty-scrollback.launch.KsbStatusWindowIcons*
KsbStatusWindowIcons
KsbStatusWindowIcons *default_opts.KsbStatusWindowIcons*

Fields: ~
{kitty} (string) kitty status window icon, defaults to 󰄛
{heart} (string) heart status window icon, defaults to 󰣐
{nvim} (string) nvim status window icon, defaults to 


*kitty-scrollback.launch.KsbStatusWindowOpts*
KsbStatusWindowOpts
KsbStatusWindowOpts *default_opts.KsbStatusWindowOpts*

Fields: ~
{enabled} (boolean) If true, show status window in upper right corner of the screen
Expand All @@ -83,28 +99,26 @@ KsbStatusWindowOpts
{icons} (KsbStatusWindowIcons) Icons displayed in the status window, defaults to 󰄛 󰣐 


KsbWinOpts *kitty-scrollback.launch.KsbWinOpts*
KsbWinOpts *default_opts.KsbWinOpts*

Type: ~
table<string,any>


*kitty-scrollback.launch.KsbWinOptsOverrideFunction*
KsbWinOptsOverrideFunction
KsbWinOptsOverrideFunction *default_opts.KsbWinOptsOverrideFunction*

Type: ~
fun(paste_winopts:KsbWinOpts):KsbWinOpts


*kitty-scrollback.launch.KsbFooterWinOptsOverrideFunction*
*default_opts.KsbFooterWinOptsOverrideFunction*
KsbFooterWinOptsOverrideFunction

Type: ~
fun(footer_winopts:KsbWinOpts,paste_winopts:KsbWinOpts):KsbWinOpts


*kitty-scrollback.launch.KsbPasteWindowOpts*
KsbPasteWindowOpts
KsbPasteWindowOpts *default_opts.KsbPasteWindowOpts*

Fields: ~
{highlight_as_normal_win} (nil|fun():boolean) If function returns true, use Normal highlight group. If false, use NormalFloat
Expand All @@ -117,7 +131,7 @@ KsbPasteWindowOpts
{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*
KsbOpts *default_opts.KsbOpts*

Fields: ~
{callbacks} (KsbCallbacks|nil) fire and forget callback functions
Expand All @@ -131,24 +145,6 @@ KsbOpts *kitty-scrollback.launch.KsbOpts*
{visual_selection_highlight_mode} (string|"darken"|"kitty"|"nvim"|"reverse"|nil)


M.setup({kitty_data_str}) *kitty-scrollback.launch.setup*
Setup and configure kitty-scrollback.nvim

Parameters: ~
{kitty_data_str} (string)


M.launch() *kitty-scrollback.launch.launch*
Launch kitty-scrollack.nvim with configured scrollback buffer


M.setup_and_launch({kitty_data_str}) *kitty-scrollback.launch.setup_and_launch*
Setup and launch kitty-scrollback.nvim

Parameters: ~
{kitty_data_str} (string)


==============================================================================
*kitty-scrollback.api*

Expand Down
72 changes: 8 additions & 64 deletions lua/kitty-scrollback/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,8 @@ end
---@alias KsbGenKittenModes string | 'maps' | 'commands'

---Generate Kitten commands used as reference for configuring `kitty.conf`
---@param all boolean|nil
---@param generate_modes table<KsbGenKittenModes>|nil
M.generate_kittens = function(all, generate_modes)
M.generate_kittens = function(generate_modes)
generate_modes = (generate_modes and next(generate_modes)) and generate_modes or { 'maps' }
local target_gen_modes = {}
for _, gen_mode in pairs(generate_modes) do
Expand All @@ -93,10 +92,6 @@ M.generate_kittens = function(all, generate_modes)
vim.api.nvim_get_runtime_file('python/kitty_scrollback_nvim.py', false)[1],
':p'
)
local example_path = vim.fn.fnamemodify(
vim.api.nvim_get_runtime_file('lua/kitty-scrollback/configs/example.lua', false)[1],
':p'
)

local action_alias = 'kitty_scrollback_nvim'
local alias_config = {
Expand All @@ -116,73 +111,22 @@ M.generate_kittens = function(all, generate_modes)
.. ' --config ksb_builtin_last_visited_cmd_output',
}

local ksb_example = require('kitty-scrollback.configs.example').configs
local example_configs = vim.tbl_map(
function(name)
if name == '' or name:match('^#.*') then
return name
end
return 'map f1 ' .. action_alias .. ' --config ' .. name
end,
vim.list_extend({
'',
'# Example kitty-scrollback.nvim config overrides',
'# See ' .. example_path .. ' for config details',
}, vim.tbl_keys(ksb_example))
)

local nvim_args = vim.tbl_map(function(c)
if c == '' or c:match('^#.*') then
return c
end
return 'map f1 ' .. action_alias .. ' ' .. c
end, {
[[]],
[[# Example kitty-scrollback.nvim nvim overrides]],
[[--no-nvim-args --env NVIM_APPNAME=ksb-nvim]],
[[--nvim-args +'colorscheme darkblue']],
[[--nvim-args +'lua vim.defer_fn(function() vim.api.nvim_set_option_value("filetype", "markdown", { buf = 0 }); vim.cmd("silent! CellularAutomaton make_it_rain") end, 6000)']],
})

local kitten_map_configs = vim.list_extend(
vim.list_extend(vim.tbl_extend('force', builtin_map_configs, {}), example_configs),
nvim_args
)

local builtin_command_configs = vim.tbl_map(function(config)
return config:gsub(
'^.*map%s%S+.*kitty_scrollback_nvim',
'kitty @ kitten ' .. kitty_scrollback_kitten
)
end, builtin_map_configs)

local kitten_command_configs = vim.tbl_map(function(config)
return config:gsub(
'^.*map%s%S+.*kitty_scrollback_nvim',
'kitty @ kitten ' .. kitty_scrollback_kitten
)
end, kitten_map_configs)

local configs = {}

if all then
if target_gen_modes['maps'] then
vim.list_extend(configs, alias_config)
vim.list_extend(configs, kitten_map_configs)
table.insert(configs, '')
end
if target_gen_modes['commands'] then
vim.list_extend(configs, kitten_command_configs)
end
else
if target_gen_modes['maps'] then
vim.list_extend(configs, alias_config)
vim.list_extend(configs, builtin_map_configs)
table.insert(configs, '')
end
if target_gen_modes['commands'] then
vim.list_extend(configs, builtin_command_configs)
end
if target_gen_modes['maps'] then
vim.list_extend(configs, alias_config)
vim.list_extend(configs, builtin_map_configs)
table.insert(configs, '')
end
if target_gen_modes['commands'] then
vim.list_extend(configs, builtin_command_configs)
end

local bufid = vim.api.nvim_create_buf(true, true)
Expand Down
50 changes: 18 additions & 32 deletions lua/kitty-scrollback/configs/builtin.lua
Original file line number Diff line number Diff line change
@@ -1,35 +1,21 @@
local prefix = 'ksb_builtin_'

---@type table<string, KsbOpts|fun(KsbKittyData):KsbOpts>
return {
configs = {
[prefix .. 'get_text_all'] = function()
return {
kitty_get_text = {
extent = 'all',
ansi = true,
},
}
end,
[prefix .. 'last_cmd_output'] = function()
return {
kitty_get_text = {
extent = 'last_cmd_output',
ansi = true,
},
}
end,
[prefix .. 'last_visited_cmd_output'] = function()
return {
kitty_get_text = {
extent = 'last_visited_cmd_output',
ansi = true,
},
}
end,
[prefix .. 'checkhealth'] = function()
return {
checkhealth = true,
}
end,
ksb_builtin_get_text_all = {
kitty_get_text = {
extent = 'all',
},
},
ksb_builtin_last_cmd_output = {
kitty_get_text = {
extent = 'last_cmd_output',
},
},
ksb_builtin_last_visited_cmd_output = {
kitty_get_text = {
extent = 'last_visited_cmd_output',
},
},
ksb_builtin_checkhealth = {
checkhealth = true,
},
}
83 changes: 83 additions & 0 deletions lua/kitty-scrollback/configs/defaults.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
---@class KsbCallbacks
---@field after_setup fun(kitty_data:KsbKittyData, opts:KsbOpts)|nil callback executed after initializing kitty-scrollback.nvim
---@field after_launch fun(kitty_data:KsbKittyData, opts:KsbOpts)|nil callback executed after launch started to process the scrollback buffer
---@field after_ready fun(kitty_data:KsbKittyData, opts:KsbOpts)|nil callback executed after scrollback buffer is loaded and cursor is positioned

---@class KsbKittyGetText
---@field ansi boolean|nil If true, the text will include the ANSI formatting escape codes for colors, bold, italic, etc.
---@field clear_selection boolean|nil If true, clear the selection in the matched window, if any.
---@field extent string|nil | 'screen' | 'all' | 'selection' | 'first_cmd_output_on_screen' | 'last_cmd_output' | 'last_visited_cmd_output' | 'last_non_empty_output' What text to get. The default of screen means all text currently on the screen. all means all the screen+scrollback and selection means the currently selected text. first_cmd_output_on_screen means the output of the first command that was run in the window on screen. last_cmd_output means the output of the last command that was run in the window. last_visited_cmd_output means the first command output below the last scrolled position via scroll_to_prompt. last_non_empty_output is the output from the last command run in the window that had some non empty output. The last four require shell_integration to be enabled. Choices: screen, all, first_cmd_output_on_screen, last_cmd_output, last_non_empty_output, last_visited_cmd_output, selection

---@class KsbStatusWindowIcons
---@field kitty string kitty status window icon, defaults to 󰄛
---@field heart string heart status window icon, defaults to 󰣐
---@field nvim string nvim status window icon, defaults to

---@class KsbStatusWindowOpts
---@field enabled boolean If true, show status window in upper right corner of the screen
---@field style_simple boolean If true, use plaintext instead of nerd font icons
---@field autoclose boolean If true, close the status window after kitty-scrollback.nvim is ready
---@field show_timer boolean If true, show a timer in the status window while kitty-scrollback.nvim is loading
---@field icons KsbStatusWindowIcons Icons displayed in the status window, defaults to 󰄛 󰣐 

---@alias KsbWinOpts table<string, any>

---@alias KsbWinOptsOverrideFunction fun(paste_winopts:KsbWinOpts):KsbWinOpts
---@alias KsbFooterWinOptsOverrideFunction fun(footer_winopts:KsbWinOpts, paste_winopts:KsbWinOpts):KsbWinOpts

---@class KsbPasteWindowOpts
---@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 mappings in 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
---@field keymaps_enabled boolean|nil if true, enabled all default keymaps
---@field restore_options boolean|nil if true, restore options that were modified while processing the scrollback buffer
---@field highlight_overrides KsbHighlights|nil kitty-scrollback.nvim highlight overrides
---@field status_window KsbStatusWindowOpts|nil options for status window indicating that kitty-scrollback.nvim is ready
---@field paste_window KsbPasteWindowOpts|nil options for paste window that sends commands to Kitty
---@field kitty_get_text KsbKittyGetText|nil options passed to get-text when reading scrollback buffer, see `kitty @ get-text --help`
---@field checkhealth boolean|nil if true execute :checkhealth kitty-scrollback and skip setup
---@field visual_selection_highlight_mode string | 'darken' | 'kitty' | 'nvim' | 'reverse' | nil
local default_opts = {
callbacks = nil,
keymaps_enabled = true,
restore_options = false,
highlight_overrides = nil,
status_window = {
enabled = true,
style_simple = false,
autoclose = false,
show_timer = false,
icons = {
kitty = '󰄛',
heart = '󰣐', -- variants 󰣐 |  |  | ♥ |  | 󱢠 | 
nvim = '', -- variants  |  |  | 
},
},
paste_window = {
highlight_as_normal_win = nil,
filetype = nil,
hide_footer = false,
winblend = 0,
winopts_overrides = nil,
footer_winopts_overrides = nil,
yank_register = '',
yank_register_enabled = true,
},
kitty_get_text = {
ansi = true,
extent = 'all',
clear_selection = true,
},
checkhealth = false,
visual_selection_highlight_mode = 'darken',
}

return default_opts
Loading

0 comments on commit 97fea1b

Please sign in to comment.