Skip to content

Commit

Permalink
feat(hurl.nvim): add variable editing functionality in HurlManageVari…
Browse files Browse the repository at this point in the history
…able buffer
  • Loading branch information
jellydn committed May 2, 2024
1 parent 10aae06 commit 7e56e3f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,12 @@ To use this command, simply type `:HurlManageVariable` in the command line:
:HurlManageVariable
```

Please note that as of now, this command only supports viewing the variables. The ability to add new variables, modify existing ones, or delete variables directly from this buffer is not available yet. However, this feature is on the roadmap and will be added in future updates.
The default keymap for this buffer is:

- `q`: Close the buffer
- `e`: Edit the variable

[![Manage variables](https://i.gyazo.com/0492719eb7a14f42cebff6996bde8672.gif)](https://gyazo.com/0492719eb7a14f42cebff6996bde8672)

For now, if you want to modify the global variables, you can do so by using the `HurlSetVariable` command or by editing your `vars.env` file directly.

Expand Down
17 changes: 16 additions & 1 deletion lua/hurl/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,22 @@ function M.setup()
end

local popup = require('hurl.popup')
popup.show_text('Hurl.nvim - Global variables', lines)
local text_popup = popup.show_text(
'Hurl.nvim - Global variables',
lines,
'Press `q` to close. Press `e` to edit the variable.'
)

-- Add e key binding to edit the variable
text_popup:map('n', 'e', function()
local line = vim.api.nvim_get_current_line()
local var_name = line:match('^(.-) =')
if var_name then
local new_value = vim.fn.input('Enter new value for ' .. var_name .. ': ')
_HURL_GLOBAL_CONFIG.global_vars[var_name] = new_value
vim.api.nvim_set_current_line(var_name .. ' = ' .. new_value)
end
end)
end, {
nargs = '*',
range = true,
Expand Down
11 changes: 9 additions & 2 deletions lua/hurl/popup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,12 @@ M.clear = function()
vim.api.nvim_buf_set_lines(popups.bottom.bufnr, 0, -1, false, { 'Processing...' })
end

M.show_text = function(title, lines)
--- Show text in a popup
---@param title string
---@param lines table
---@param bottom? string
---@return any
M.show_text = function(title, lines, bottom)
-- Create a new popup
local text_popup = Popup({
enter = true,
Expand All @@ -128,7 +133,7 @@ M.show_text = function(title, lines)
text = {
top = title,
top_align = 'center',
bottom = 'Press `q` to close',
bottom = bottom or 'Press `q` to close',
bottom_align = 'left',
},
},
Expand Down Expand Up @@ -156,6 +161,8 @@ M.show_text = function(title, lines)
end)

text_popup:mount()

return text_popup
end

return M

0 comments on commit 7e56e3f

Please sign in to comment.