Skip to content

Commit

Permalink
feat: clear previous response if buffer still open
Browse files Browse the repository at this point in the history
  • Loading branch information
jellydn committed Dec 13, 2023
1 parent 2e27b93 commit 6be36b6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lua/hurl/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,13 @@ local function execute_hurl_cmd(opts, callback)
is_running = true
vim.notify('hurl: running request', vim.log.levels.INFO)

local is_verbose_mode = vim.tbl_contains(opts, '--verbose')
if not _HURL_GLOBAL_CONFIG.auto_close and not is_verbose_mode and response.body then
local container = require('hurl.' .. _HURL_GLOBAL_CONFIG.mode)
utils.log_info('hurl: clear previous response if this is not auto close')
container.clear()
end

-- Check vars.env exist on the current file buffer
-- Then inject the command with --variables-file vars.env
local env_files = find_env_files_in_folders()
Expand Down
10 changes: 10 additions & 0 deletions lua/hurl/popup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,14 @@ M.show = function(data, type)
end
end

M.clear = function()
-- Check if popup is open
if not popups.bottom.winid then
return
end
-- Clear the buffer and adding `Processing...` message
vim.api.nvim_buf_set_lines(popups.top.bufnr, 0, -1, false, { 'Processing...' })
vim.api.nvim_buf_set_lines(popups.bottom.bufnr, 0, -1, false, { 'Processing...' })
end

return M
10 changes: 10 additions & 0 deletions lua/hurl/split.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,14 @@ M.show = function(data, type)
end
end

M.clear = function()
-- Check if split is open
if not split.winid then
return
end

-- Clear the buffer and adding `Processing...` message
vim.api.nvim_buf_set_lines(split.bufnr, 0, -1, false, { 'Processing...' })
end

return M

0 comments on commit 6be36b6

Please sign in to comment.