Skip to content

Commit

Permalink
chore: remove global config in favor of first index
Browse files Browse the repository at this point in the history
  • Loading branch information
mikesmithgh committed Jan 21, 2024
1 parent acb7b7d commit 884394a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ Navigate your [Kitty](https://sw.kovidgoyal.net/kitty/) scrollback buffer to qui
- The command `KittyScrollbackGenerateKittens` no longer accepts the bang `!` modifier
- The api `generate_kittens` signature removed the `all` parameter
- Removed the undocumented reserved `default` configuration name
- Removed the reserved `global` configuration name


</details>
Expand Down
23 changes: 11 additions & 12 deletions lua/kitty-scrollback/launch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,13 @@ local function load_requires()
ksb_backport = require('kitty-scrollback.backport')
end

local function config_to_opts(config)
if type(config) == 'function' then
config = config(p.kitty_data)
end
return type(config) == 'table' and config or {}
end

---Setup and configure kitty-scrollback.nvim
---@param kitty_data_str string
M.setup = function(kitty_data_str)
Expand All @@ -299,14 +306,13 @@ M.setup = function(kitty_data_str)
p.kitty_data = vim.fn.json_decode(kitty_data_str)
load_requires() -- must be after p.kitty_data initialized

-- if a config named 'global' is found, that will be applied to all configurations regardless of prefix
-- if a config at the first index found, that will be applied to all configurations regardless of prefix
-- if a config name is prefixed 'ksb_builtin_', the user's config will be merged with configs/builtin.lua
-- if a config does not meet the above criteria, check if a user had defined a configuration with the given config name and use that

local config_name = p.kitty_data.kitty_scrollback_config or ''
local config_source = require('kitty-scrollback')
local global_fn = config_source.configs['global']
local global_opts = global_fn and global_fn(p.kitty_data) or {}
local global_opts = config_to_opts(config_source.configs[1])
local user_config = config_source.configs[config_name]
if config_name ~= '' and not user_config and not config_name:match('^ksb_builtin_.*') then
vim.defer_fn(function()
Expand All @@ -315,17 +321,10 @@ M.setup = function(kitty_data_str)
config_name = 'ksb_builtin_get_text_all'
user_config = config_source.configs[config_name]
end
if type(user_config) == 'function' then
user_config = user_config(p.kitty_data)
end
local user_opts = type(user_config) == 'table' and user_config or {}
local user_opts = config_to_opts(user_config)
local builtin_opts = {}
if config_name:match('^ksb_builtin_.*') then
local builtin_config = require('kitty-scrollback.configs.builtin')[config_name]
if type(builtin_config) == 'function' then
builtin_config = builtin_config(p.kitty_data)
end
builtin_opts = type(builtin_config) == 'table' and builtin_config or {}
builtin_opts = config_to_opts(require('kitty-scrollback.configs.builtin')[config_name])
end
opts = vim.tbl_deep_extend('force', default_opts, global_opts, builtin_opts, user_opts)

Expand Down

0 comments on commit 884394a

Please sign in to comment.