Skip to content

Commit

Permalink
feat(display_mode): split or float
Browse files Browse the repository at this point in the history
closes #300.
  • Loading branch information
gorillamoe committed Nov 1, 2024
1 parent 164dc11 commit 8b16a50
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
25 changes: 25 additions & 0 deletions docs/docs/getting-started/configuration-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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`
Expand Down
3 changes: 3 additions & 0 deletions lua/kulala/config/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
30 changes: 29 additions & 1 deletion lua/kulala/ui/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 8b16a50

Please sign in to comment.