feat: git log

This commit is contained in:
Folke Lemaitre 2022-11-22 21:12:50 +01:00
parent 54d5ff18f5
commit 3218c2d9ec
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
7 changed files with 83 additions and 6 deletions

View file

@ -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,

View file

@ -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

View file

@ -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

View file

@ -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