mirror of https://github.com/folke/lazy.nvim.git
feat(ui): added multiple options for diff command
This commit is contained in:
parent
8ad05feef1
commit
7d02da2ff0
|
@ -327,6 +327,14 @@ return {
|
|||
task = "✔ ",
|
||||
},
|
||||
throttle = 20, -- how frequently should the ui process render events
|
||||
diff = {
|
||||
-- diff command <d> can be one of:
|
||||
-- * browser: opens the github compare view. Note that this is always mapped to <K> as well,
|
||||
-- so you can have a different command for diff <d>
|
||||
-- * git: will run git diff and open a buffer with filetype git
|
||||
-- * terminal_git: will open a pseudo terminal with git diff
|
||||
-- * diffview.nvim: will open Diffview to show the diff
|
||||
cmd = "git",
|
||||
},
|
||||
checker = {
|
||||
-- automatically check for plugin updates
|
||||
|
|
|
@ -50,6 +50,14 @@ M.defaults = {
|
|||
task = "✔ ",
|
||||
},
|
||||
throttle = 20, -- how frequently should the ui process render events
|
||||
diff = {
|
||||
-- diff command <d> can be one of:
|
||||
-- * browser: opens the github compare view. Note that this is always mapped to <K> as well,
|
||||
-- so you can have a different command for diff <d>
|
||||
-- * git: will run git diff and open a buffer with filetype git
|
||||
-- * terminal_git: will open a pseudo terminal with git diff
|
||||
-- * diffview.nvim: will open Diffview to show the diff
|
||||
cmd = "git",
|
||||
},
|
||||
checker = {
|
||||
-- automatically check for plugin updates
|
||||
|
|
|
@ -109,7 +109,7 @@ function M.spawn(cmd, opts)
|
|||
end
|
||||
|
||||
---@param cmd string[]
|
||||
---@param opts? {cwd:string}
|
||||
---@param opts? {cwd:string, env:table}
|
||||
function M.exec(cmd, opts)
|
||||
opts = opts or {}
|
||||
---@type string[]
|
||||
|
@ -117,6 +117,7 @@ function M.exec(cmd, opts)
|
|||
local job = vim.fn.jobstart(cmd, {
|
||||
cwd = opts.cwd,
|
||||
pty = false,
|
||||
env = opts.env,
|
||||
stdout_buffered = true,
|
||||
on_stdout = function(_, _lines)
|
||||
lines = _lines
|
||||
|
|
|
@ -26,6 +26,7 @@ end
|
|||
|
||||
M.keys = {
|
||||
hover = "K",
|
||||
diff = "d",
|
||||
close = "q",
|
||||
details = "<cr>",
|
||||
profile_sort = "<C-s>",
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
local Util = require("lazy.util")
|
||||
|
||||
local M = {}
|
||||
|
||||
---@alias LazyDiff {commit:string} | {from:string, to:string}
|
||||
---@alias LazyDiffFun fun(plugin:LazyPlugin, diff:LazyDiff)
|
||||
|
||||
M.handlers = {
|
||||
|
||||
---@type LazyDiffFun
|
||||
browser = function(plugin, diff)
|
||||
if plugin.url then
|
||||
local url = plugin.url:gsub("%.git$", "")
|
||||
if diff.commit then
|
||||
Util.open(url .. "/commit/" .. diff.commit)
|
||||
else
|
||||
Util.open(url .. "/compare/" .. diff.from .. ".." .. diff.to)
|
||||
end
|
||||
else
|
||||
Util.error("No url for " .. plugin.name)
|
||||
end
|
||||
end,
|
||||
|
||||
---@type LazyDiffFun
|
||||
["diffview.nvim"] = function(plugin, diff)
|
||||
if diff.commit then
|
||||
vim.cmd.DiffviewOpen(("-C=%s"):format(plugin.dir) .. " " .. diff.commit)
|
||||
else
|
||||
vim.cmd.DiffviewOpen(("-C=%s"):format(plugin.dir) .. " " .. diff.from .. ".." .. diff.to)
|
||||
end
|
||||
end,
|
||||
|
||||
---@type LazyDiffFun
|
||||
git = function(plugin, diff)
|
||||
local cmd = { "git", "diff" }
|
||||
if diff.commit then
|
||||
cmd[#cmd + 1] = diff.commit
|
||||
else
|
||||
cmd[#cmd + 1] = diff.from
|
||||
cmd[#cmd + 1] = diff.to
|
||||
end
|
||||
Util.open_cmd(cmd, { cwd = plugin.dir, filetype = "git" })
|
||||
end,
|
||||
|
||||
---@type LazyDiffFun
|
||||
terminal_git = function(plugin, diff)
|
||||
local cmd = { "git", "diff" }
|
||||
if diff.commit then
|
||||
cmd[#cmd + 1] = diff.commit
|
||||
else
|
||||
cmd[#cmd + 1] = diff.from
|
||||
cmd[#cmd + 1] = diff.to
|
||||
end
|
||||
Util.open_cmd(cmd, { cwd = plugin.dir, terminal = true, env = { PAGER = "cat" } })
|
||||
end,
|
||||
}
|
||||
|
||||
return M
|
|
@ -25,7 +25,7 @@ function M.new(view)
|
|||
local self = setmetatable({}, { __index = setmetatable(M, { __index = Text }) })
|
||||
self.view = view
|
||||
self.padding = 2
|
||||
self.wrap = view.win_opts.width
|
||||
self.wrap = view.opts.win_opts.width
|
||||
return self
|
||||
end
|
||||
|
||||
|
@ -56,8 +56,9 @@ function M:update()
|
|||
end
|
||||
end
|
||||
|
||||
local mode = self:title()
|
||||
self:title()
|
||||
|
||||
local mode = self.view.state.mode
|
||||
if mode == "help" then
|
||||
self:help()
|
||||
elseif mode == "profile" then
|
||||
|
@ -139,7 +140,6 @@ function M:title()
|
|||
end
|
||||
self:nl():nl()
|
||||
end
|
||||
return self.view.state.mode
|
||||
end
|
||||
|
||||
function M:help()
|
||||
|
@ -395,12 +395,14 @@ function M:log(task)
|
|||
if msg:find("^%S+!:") then
|
||||
self:diagnostic({ message = "Breaking Changes", severity = vim.diagnostic.severity.WARN })
|
||||
end
|
||||
self:append(ref .. " ", "LazyCommit", { indent = 6 })
|
||||
self:append(ref:sub(1, 7) .. " ", "LazyCommit", { indent = 6 })
|
||||
self:append(vim.trim(msg)):highlight({
|
||||
["#%d+"] = "Number",
|
||||
["^%S+:"] = "Title",
|
||||
["^%S+(%(.*%)):"] = "Italic",
|
||||
["`.-`"] = "@text.literal.markdown_inline",
|
||||
["%*.-%*"] = "Italic",
|
||||
["%*%*.-%*%*"] = "Bold",
|
||||
})
|
||||
-- string.gsub
|
||||
self:append(" " .. time, "Comment")
|
||||
|
|
Loading…
Reference in New Issue