feat: lua opts for border

This commit is contained in:
mpaulson 2023-12-10 19:34:45 -07:00
parent f7d3c7360d
commit fa73cd0c33
2 changed files with 21 additions and 13 deletions

View File

@ -27,8 +27,6 @@ M.DEFAULT_LIST = DEFAULT_LIST
---@class HarpoonSettings ---@class HarpoonSettings
---@field save_on_toggle boolean defaults to true ---@field save_on_toggle boolean defaults to true
---@field sync_on_ui_close? boolean ---@field sync_on_ui_close? boolean
---@field ui_fallback_width number defaults 69, nice
---@field ui_width_ratio number defaults to 0.62569
---@field key (fun(): string) ---@field key (fun(): string)
---@class HarpoonPartialSettings ---@class HarpoonPartialSettings
@ -58,16 +56,12 @@ function M.get_default_config()
settings = { settings = {
save_on_toggle = false, save_on_toggle = false,
sync_on_ui_close = false, sync_on_ui_close = false,
ui_fallback_width = 69,
ui_width_ratio = 0.62569,
key = function() key = function()
return vim.loop.cwd() return vim.loop.cwd()
end, end,
}, },
default = { default = {
--- ui_nav_wrap allows the ability to enable(true) or disable(false) wrapping on prev and next list calls.
ui_nav_wrap = true,
--- select_with_nill allows for a list to call select even if the provided item is nil --- select_with_nill allows for a list to call select even if the provided item is nil
select_with_nil = false, select_with_nil = false,

View File

@ -3,7 +3,18 @@ local Logger = require("harpoon.logger")
local Listeners = require("harpoon.listeners") local Listeners = require("harpoon.listeners")
---@class HarpoonToggleOptions ---@class HarpoonToggleOptions
---TODO: Finish. ---@field border? any this value is directly passed to nvim_open_win
---@field ui_fallback_width? number
---@field ui_width_ratio? number
---@return HarpoonToggleOptions
local function toggle_config(config)
return vim.tbl_extend("force", {
ui_fallback_width = 69,
ui_width_ratio = 0.62569,
}, config)
end
---@class HarpoonUI ---@class HarpoonUI
---@field win_id number ---@field win_id number
@ -69,11 +80,12 @@ end
function HarpoonUI:_create_window(toggle_opts) function HarpoonUI:_create_window(toggle_opts)
local win = vim.api.nvim_list_uis() local win = vim.api.nvim_list_uis()
local width = self.settings.ui_fallback_width local width = toggle_opts.ui_fallback_width
if #win > 0 then if #win > 0 then
-- no ackshual reason for 0.62569, just looks complicated, and i want -- no ackshual reason for 0.62569, just looks complicated, and i want
-- to make my boss think i am smart -- to make my boss think i am smart
width = math.floor(win[1].width * self.settings.ui_width_ratio) width = math.floor(win[1].width * toggle_opts.ui_width_ratio)
end end
local height = 8 local height = 8
@ -86,11 +98,13 @@ function HarpoonUI:_create_window(toggle_opts)
width = width, width = width,
height = height, height = height,
style = "minimal", style = "minimal",
border = "single", border = toggle_opts.border or "single",
}) })
if win_id == 0 then if win_id == 0 then
Logger:log("ui#_create_window failed to create window, win_id returned 0") Logger:log("ui#_create_window failed to create window, win_id returned 0")
self.bufnr = bufnr
self:close_menu()
error("Failed to create window") error("Failed to create window")
end end
@ -111,8 +125,8 @@ end
---@param list? HarpoonList ---@param list? HarpoonList
---TODO: @param opts? HarpoonToggleOptions ---TODO: @param opts? HarpoonToggleOptions
function HarpoonUI:toggle_quick_menu(list) function HarpoonUI:toggle_quick_menu(list, opts)
opts = opts or {} opts = toggle_config(opts)
if list == nil or self.win_id ~= nil then if list == nil or self.win_id ~= nil then
Logger:log("ui#toggle_quick_menu#closing", list and list.name) Logger:log("ui#toggle_quick_menu#closing", list and list.name)
if self.settings.save_on_toggle then if self.settings.save_on_toggle then
@ -123,7 +137,7 @@ function HarpoonUI:toggle_quick_menu(list)
end end
Logger:log("ui#toggle_quick_menu#opening", list and list.name) Logger:log("ui#toggle_quick_menu#opening", list and list.name)
local win_id, bufnr = self:_create_window() local win_id, bufnr = self:_create_window(opts)
self.win_id = win_id self.win_id = win_id
self.bufnr = bufnr self.bufnr = bufnr