Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(keys): include custom keys in help menu #1105

Merged
merged 1 commit into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 21 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -371,22 +371,27 @@ return {
browser = nil, ---@type string?
throttle = 20, -- how frequently should the ui process render events
custom_keys = {
-- you can define custom key maps here.
-- To disable one of the defaults, set it to false

-- open lazygit log
["<localleader>l"] = function(plugin)
require("lazy.util").float_term({ "lazygit", "log" }, {
cwd = plugin.dir,
})
end,

-- open a terminal for the plugin dir
["<localleader>t"] = function(plugin)
require("lazy.util").float_term(nil, {
cwd = plugin.dir,
})
end,
-- You can define custom key maps here. If present, the description will
-- be shown in the help menu.
-- To disable one of the defaults, set it to false.

["<localleader>l"] = {
function(plugin)
require("lazy.util").float_term({ "lazygit", "log" }, {
cwd = plugin.dir,
})
end,
desc = "Open lazygit log",
},

["<localleader>t"] = {
function(plugin)
require("lazy.util").float_term(nil, {
cwd = plugin.dir,
})
end,
desc = "Open terminal in plugin dir",
},
},
},
diff = {
Expand Down
37 changes: 21 additions & 16 deletions doc/lazy.nvim.txt
Original file line number Diff line number Diff line change
Expand Up @@ -473,22 +473,27 @@ CONFIGURATION *lazy.nvim-lazy.nvim-configuration*
browser = nil, ---@type string?
throttle = 20, -- how frequently should the ui process render events
custom_keys = {
-- you can define custom key maps here.
-- To disable one of the defaults, set it to false

-- open lazygit log
["<localleader>l"] = function(plugin)
require("lazy.util").float_term({ "lazygit", "log" }, {
cwd = plugin.dir,
})
end,

-- open a terminal for the plugin dir
["<localleader>t"] = function(plugin)
require("lazy.util").float_term(nil, {
cwd = plugin.dir,
})
end,
-- You can define custom key maps here. If present, the description will
-- be shown in the help menu.
-- To disable one of the defaults, set it to false.

["<localleader>l"] = {
function(plugin)
require("lazy.util").float_term({ "lazygit", "log" }, {
cwd = plugin.dir,
})
end,
desc = "Open lazygit log",
},

["<localleader>t"] = {
function(plugin)
require("lazy.util").float_term(nil, {
cwd = plugin.dir,
})
end,
desc = "Open terminal in plugin dir",
},
},
},
diff = {
Expand Down
33 changes: 19 additions & 14 deletions lua/lazy/core/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,22 +81,27 @@ M.defaults = {
browser = nil, ---@type string?
throttle = 20, -- how frequently should the ui process render events
custom_keys = {
-- you can define custom key maps here.
-- To disable one of the defaults, set it to false
-- You can define custom key maps here. If present, the description will
-- be shown in the help menu.
-- To disable one of the defaults, set it to false.

-- open lazygit log
["<localleader>l"] = function(plugin)
require("lazy.util").float_term({ "lazygit", "log" }, {
cwd = plugin.dir,
})
end,
["<localleader>l"] = {
function(plugin)
require("lazy.util").float_term({ "lazygit", "log" }, {
cwd = plugin.dir,
})
end,
desc = "Open lazygit log",
},

-- open a terminal for the plugin dir
["<localleader>t"] = function(plugin)
require("lazy.util").float_term(nil, {
cwd = plugin.dir,
})
end,
["<localleader>t"] = {
function(plugin)
require("lazy.util").float_term(nil, {
cwd = plugin.dir,
})
end,
desc = "Open terminal in plugin dir",
},
},
},
diff = {
Expand Down
7 changes: 4 additions & 3 deletions lua/lazy/view/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,10 @@ function M.create()
end
end)

for key, handler in pairs(Config.options.ui.custom_keys) do
if handler then
self:on_key(key, function()
for lhs, rhs in pairs(Config.options.ui.custom_keys) do
if rhs then
local handler = type(rhs) == "table" and rhs[1] or rhs
self:on_key(lhs, function()
local plugin = self.render:get_plugin()
if plugin then
handler(plugin)
Expand Down
8 changes: 8 additions & 0 deletions lua/lazy/view/render.lua
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,14 @@ function M:help()
self:append(" " .. (mode.desc_plugin or mode.desc)):nl()
end
end
for lhs, rhs in pairs(Config.options.ui.custom_keys) do
if type(rhs) == "table" and rhs.desc then
self:append("- ", "LazySpecial", { indent = 2 })
self:append("Custom key ", "Title")
self:append(lhs, "LazyProp")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not surrounding the keys with angle brackets here because it looked kind of odd with mappings like <localleader>t, but I'm open to other ways to format these.

self:append(" " .. rhs.desc):nl()
end
end
end

function M:progressbar()
Expand Down