-
Notifications
You must be signed in to change notification settings - Fork 236
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This allows less locations to edit when adding a new popup
- Loading branch information
1 parent
6353bf0
commit 1b4c1a2
Showing
6 changed files
with
114 additions
and
65 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
local M = {} | ||
function M.echo(value) | ||
local notification = require("neogit.lib.notification") | ||
notification.create("Echo: " .. value) | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
local popup = require("neogit.lib.popup") | ||
local actions = require("neogit.popups.echo.actions") | ||
|
||
local M = {} | ||
|
||
function M.create(...) | ||
local args = { ... } | ||
local p = popup.builder():name("NeogitEchoPopup") | ||
for k, v in ipairs(args) do | ||
p:action(tostring(k), tostring(v), function() | ||
actions.echo(v) | ||
end) | ||
end | ||
|
||
local p = p:build() | ||
|
||
p:show() | ||
|
||
return p | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
local M = {} | ||
|
||
---@param name string | ||
--@param get_args nil|fun(): any | ||
--- Creates a curried function which will open the popup with the given name when called | ||
--- Extra arguments are supplied to popup.`create()` | ||
function M.open(name, get_args) | ||
return function() | ||
local ok, value = pcall(require, "neogit.popups." .. name) | ||
if ok then | ||
assert(value) | ||
local args = {} | ||
|
||
if get_args == "function" then | ||
args = { get_args() } | ||
end | ||
|
||
value.create(table.unpack(args)) | ||
else | ||
local notification = require("neogit.lib.notification") | ||
notification.create(string.format("No such popup: %q", name), vim.log.levels.ERROR) | ||
end | ||
end | ||
end | ||
|
||
function M.test() | ||
M.open("echo", function() | ||
return "a", "b" | ||
end)() | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters