diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..20acaa4 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +tt.lua diff --git a/lua/lazy/manager.lua b/lua/lazy/manager.lua index f4c8096..05f1cd5 100644 --- a/lua/lazy/manager.lua +++ b/lua/lazy/manager.lua @@ -53,6 +53,9 @@ function M.run(operation, opts, filter) runner:add(Task.new(plugin, "run")) end plugin.dirty = false + if operation == "update" then + runner:add(Task.new(plugin, "log")) + end end -- wait for post-install to finish runner:wait(on_done) @@ -85,6 +88,14 @@ function M.update(opts) end) end +---@param opts? ManagerOpts +function M.log(opts) + ---@param plugin LazyPlugin + M.run("log", opts, function(plugin) + return plugin.uri and plugin.installed + end) +end + ---@param opts? ManagerOpts function M.clean(opts) opts = opts or {} diff --git a/lua/lazy/task.lua b/lua/lazy/task.lua index f330228..8b9d4b1 100644 --- a/lua/lazy/task.lua +++ b/lua/lazy/task.lua @@ -8,7 +8,7 @@ local Util = require("lazy.util") ---@field running boolean local Task = {} ----@alias TaskType "update"|"install"|"run"|"clean" +---@alias TaskType "update"|"install"|"run"|"clean"|"log" ---@param plugin LazyPlugin ---@param type TaskType @@ -27,7 +27,6 @@ end function Task:_done() self.running = false - vim.cmd("do User LazyRender") end @@ -54,7 +53,7 @@ function Task:clean() end self.plugin.installed = false - self.running = false + self:_done() end function Task:install() @@ -161,16 +160,38 @@ function Task:start() self:run() elseif self.type == "clean" then self:clean() + elseif self.type == "log" then + self:log() end end) if not ok then self.error = err or "failed" - self:_done() end end +function Task:log() + if not Util.file_exists(self.plugin.dir .. "/.git") then + self:_done() + return + end + + local args = { + "log", + "--pretty=format:%h %s (%cr)", + "--abbrev-commit", + "--decorate", + "--date=short", + "--color=never", + "--since='7 days ago'", + } + self:spawn("git", { + args = args, + cwd = self.plugin.dir, + }) +end + function Task:update() if Util.file_exists(self.plugin.uri) then if vim.loop.fs_realpath(self.plugin.uri) ~= vim.loop.fs_realpath(self.plugin.dir) then @@ -180,7 +201,6 @@ function Task:update() }) vim.opt.runtimepath:append(self.plugin.uri) end - self:_done() else local args = { diff --git a/lua/lazy/view/commands.lua b/lua/lazy/view/commands.lua index 67b6ba9..43a2961 100644 --- a/lua/lazy/view/commands.lua +++ b/lua/lazy/view/commands.lua @@ -21,6 +21,9 @@ M.commands = { install = function() Manager.install({ clear = true, show = true }) end, + log = function() + Manager.log({ clear = true, show = true }) + end, show = function() View.show() end, diff --git a/lua/lazy/view/render.lua b/lua/lazy/view/render.lua index 4afda31..272c615 100644 --- a/lua/lazy/view/render.lua +++ b/lua/lazy/view/render.lua @@ -119,6 +119,25 @@ function M:plugin(plugin) self:nl() end end + elseif task.type == "log" then + local log = vim.trim(task.output) + if log ~= "" then + local lines = vim.split(log, "\n") + for l, line in ipairs(lines) do + if l == 1 then + self:nl() + end + local ref, msg, time = line:match("^(%w+) (.*) (%(.*%))$") + self:append(" " .. ref .. " ", "@variable.builtin") + local col = self:col() + self:append(msg) + -- string.gsub + self:append(" " .. time, "Comment") + if l ~= #lines then + self:nl() + end + end + end end end end diff --git a/lua/lazy/view/sections.lua b/lua/lazy/view/sections.lua index c60c23e..64e101e 100644 --- a/lua/lazy/view/sections.lua +++ b/lua/lazy/view/sections.lua @@ -51,6 +51,14 @@ return { end, title = "Running", }, + { + filter = function(plugin) + return has_task(plugin, function(task) + return task.type == "log" and vim.trim(task.output) ~= "" + end) + end, + title = "Log", + }, { filter = function(plugin) return plugin.installed and not plugin.uri diff --git a/lua/lazy/view/text.lua b/lua/lazy/view/text.lua index 259071c..e4df4cb 100644 --- a/lua/lazy/view/text.lua +++ b/lua/lazy/view/text.lua @@ -16,7 +16,7 @@ function Text.new() end ---@param str string ----@param hl string|table +---@param hl? string|table function Text:append(str, hl) if #self._lines == 0 then self:nl() @@ -84,4 +84,19 @@ function Text:trim() end end +function Text:row() + return #self._lines == 0 and 1 or #self._lines +end + +function Text:col() + if #self._lines == 0 then + return 0 + end + local width = 0 + for _, segment in ipairs(self._lines[#self._lines]) do + width = width + vim.fn.strlen(segment.str) + end + return width +end + return Text