From 8b16a5094075cbc788e5672ebbcf5a007cc0ab80 Mon Sep 17 00:00:00 2001 From: Marco Kellershoff Date: Fri, 1 Nov 2024 21:57:26 +0100 Subject: [PATCH] feat(display_mode): split or float closes #300. --- .../getting-started/configuration-options.md | 25 ++++++++++++++++ lua/kulala/config/init.lua | 3 ++ lua/kulala/ui/init.lua | 30 ++++++++++++++++++- 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/docs/docs/getting-started/configuration-options.md b/docs/docs/getting-started/configuration-options.md index 06447e4..48e32dc 100644 --- a/docs/docs/getting-started/configuration-options.md +++ b/docs/docs/getting-started/configuration-options.md @@ -16,6 +16,9 @@ the Kulala plugin with the available `opts`: -- you can specify it here curl_path = "curl", + -- Display mode, possible values: "split", "float" + display_mode = "split", + -- split direction -- possible values: "vertical", "horizontal" split_direction = "vertical", @@ -125,10 +128,32 @@ Example: }, } ``` + +### display_mode + +The display mode. + +Can be either `split` or `float`. + +Default: `split` + +Example: + +```lua +{ + "mistweaverco/kulala.nvim", + opts = { + display_mode = "float", + }, +} +``` + ### split_direction Split direction. +Only used when `display_mode` is set to `split`. + Possible values: - `vertical` diff --git a/lua/kulala/config/init.lua b/lua/kulala/config/init.lua index f8b8683..aa381c0 100644 --- a/lua/kulala/config/init.lua +++ b/lua/kulala/config/init.lua @@ -6,6 +6,9 @@ M.defaults = { -- if you have curl installed in a non-standard path, -- you can specify it here curl_path = "curl", + -- Display mode + -- possible values: "split", "float" + display_mode = "split", -- split direction -- possible values: "vertical", "horizontal" split_direction = "vertical", diff --git a/lua/kulala/ui/init.lua b/lua/kulala/ui/init.lua index b170416..42924b5 100644 --- a/lua/kulala/ui/init.lua +++ b/lua/kulala/ui/init.lua @@ -29,6 +29,26 @@ local get_win = function() return nil end +local open_float = function() + local bufnr = vim.api.nvim_create_buf(false, false) + vim.api.nvim_buf_set_name(bufnr, "kulala://ui") + + local width = vim.api.nvim_win_get_width(0) - 10 + local height = vim.api.nvim_win_get_height(0) - 10 + + local winnr = vim.api.nvim_open_win(bufnr, true, { + title = "Kulala", + title_pos = "center", + relative = "editor", + border = "single", + width = width, + height = height, + row = math.floor(((vim.o.lines - height) / 2) - 1), + col = math.floor((vim.o.columns - width) / 2), + style = "minimal", + }) +end + local get_buffer = function() -- Iterate through all buffers for _, buf in ipairs(vim.api.nvim_list_bufs()) do @@ -70,7 +90,7 @@ local replace_buffer = function() return new_bufnr end -local open_buffer = function() +local open_split = function() local prev_win = vim.api.nvim_get_current_win() local sd = CONFIG.get().split_direction == "vertical" and "vsplit" or "split" vim.cmd("keepalt " .. sd .. " " .. GLOBALS.UI_ID) @@ -80,6 +100,14 @@ local open_buffer = function() vim.api.nvim_set_current_win(prev_win) end +local open_buffer = function() + if CONFIG.get().display_mode == "split" then + open_split() + else + open_float() + end +end + local close_buffer = function() vim.cmd("bdelete! " .. GLOBALS.UI_ID) end