diff --git a/README.md b/README.md index ad512e3..25cace6 100644 --- a/README.md +++ b/README.md @@ -327,6 +327,14 @@ return { task = "✔ ", }, throttle = 20, -- how frequently should the ui process render events + diff = { + -- diff command can be one of: + -- * browser: opens the github compare view. Note that this is always mapped to as well, + -- so you can have a different command for diff + -- * 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 diff --git a/lua/lazy/core/config.lua b/lua/lazy/core/config.lua index bd89f95..c061ea9 100644 --- a/lua/lazy/core/config.lua +++ b/lua/lazy/core/config.lua @@ -50,6 +50,14 @@ M.defaults = { task = "✔ ", }, throttle = 20, -- how frequently should the ui process render events + diff = { + -- diff command can be one of: + -- * browser: opens the github compare view. Note that this is always mapped to as well, + -- so you can have a different command for diff + -- * 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 diff --git a/lua/lazy/manage/process.lua b/lua/lazy/manage/process.lua index 8b11674..7ac6514 100644 --- a/lua/lazy/manage/process.lua +++ b/lua/lazy/manage/process.lua @@ -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 diff --git a/lua/lazy/view/config.lua b/lua/lazy/view/config.lua index 65bcffa..84bd294 100644 --- a/lua/lazy/view/config.lua +++ b/lua/lazy/view/config.lua @@ -26,6 +26,7 @@ end M.keys = { hover = "K", + diff = "d", close = "q", details = "", profile_sort = "", diff --git a/lua/lazy/view/diff.lua b/lua/lazy/view/diff.lua new file mode 100644 index 0000000..adff761 --- /dev/null +++ b/lua/lazy/view/diff.lua @@ -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 diff --git a/lua/lazy/view/render.lua b/lua/lazy/view/render.lua index d95c66e..ba242b1 100644 --- a/lua/lazy/view/render.lua +++ b/lua/lazy/view/render.lua @@ -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")