Skip to content

Commit

Permalink
Merge pull request #77 from mistweaverco/feat/add-close
Browse files Browse the repository at this point in the history
feat(ui): add `close()` function
  • Loading branch information
gorillamoe authored Jul 27, 2024
2 parents e9fbca1 + edb6185 commit 89b9cdb
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
6 changes: 6 additions & 0 deletions docs/docs/public_methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
`require('kulala').copy()` copies the current request
(as cURL command) to the clipboard.

### close

`require('kulala').close()` closes the kulala window and also the current buffer.

> (it will not close the current buffer, if it is not a `.http` or `.rest` file)
### toggle_view

`require('kulala').toggle_view()` toggles between
Expand Down
2 changes: 1 addition & 1 deletion lua/kulala/globals/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local FS = require("kulala.utils.fs")

local M = {}

M.VERSION = "2.6.0"
M.VERSION = "2.7.0"
M.UI_ID = "kulala://ui"
M.HEADERS_FILE = FS.get_plugin_tmp_dir() .. "/headers.txt"
M.BODY_FILE = FS.get_plugin_tmp_dir() .. "/body.txt"
Expand Down
4 changes: 4 additions & 0 deletions lua/kulala/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ M.toggle_view = function()
UI:toggle_headers()
end

M.close = function()
UI:close()
end

M.set_selected_env = function(env)
if env == nil then
local has_telescope, telescope = pcall(require, "telescope")
Expand Down
16 changes: 15 additions & 1 deletion lua/kulala/ui/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ local open_buffer = function()
vim.api.nvim_set_current_win(prev_win)
end

local close_buffer = function()
vim.cmd("bdelete " .. GLOBALS.UI_ID)
end

local get_buffer = function()
-- Iterate through all buffers
for _, buf in ipairs(vim.api.nvim_list_bufs()) do
Expand Down Expand Up @@ -122,6 +126,16 @@ M.open = function()
end)
end

M.close = function()
if buffer_exists() then
close_buffer()
end
local ext = vim.fn.expand("%:e")
if ext == "http" or ext == "rest" then
vim.cmd("bdelete")
end
end

M.show_body = function()
if FS.file_exists(GLOBALS.BODY_FILE) then
if not buffer_exists() then
Expand Down Expand Up @@ -149,7 +163,7 @@ M.show_headers = function()
end

M.toggle_headers = function()
cfg = CONFIG.get()
local cfg = CONFIG.get()
if cfg.default_view == "headers" then
cfg.default_view = "body"
else
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "kulala.nvim",
"version": "2.6.0"
"version": "2.7.0"
}

0 comments on commit 89b9cdb

Please sign in to comment.