refactor(git): rework status_view header
This commit is contained in:
+32
-17
@@ -103,8 +103,9 @@ local function display_name(section)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---@param bufnr integer
|
---@param bufnr integer
|
||||||
---@param status ow.Git.Status
|
---@param r ow.Git.Repo
|
||||||
local function render(bufnr, status)
|
local function render(bufnr, r)
|
||||||
|
local status = r.status
|
||||||
local branch = status.branch
|
local branch = status.branch
|
||||||
local lines = {}
|
local lines = {}
|
||||||
local marks = {}
|
local marks = {}
|
||||||
@@ -114,34 +115,48 @@ local function render(bufnr, status)
|
|||||||
table.insert(marks, { row = row, col = 0, end_col = len, hl = "Label" })
|
table.insert(marks, { row = row, col = 0, end_col = len, hl = "Label" })
|
||||||
end
|
end
|
||||||
|
|
||||||
table.insert(lines, "Head: " .. (branch.head or "?"))
|
local repo_line = vim.fn.fnamemodify(r.worktree, ":t")
|
||||||
label(#lines - 1, 4)
|
table.insert(lines, repo_line)
|
||||||
|
table.insert(marks, {
|
||||||
|
row = #lines - 1,
|
||||||
|
col = 0,
|
||||||
|
end_col = #repo_line,
|
||||||
|
hl = "Directory",
|
||||||
|
})
|
||||||
|
|
||||||
|
table.insert(lines, "Branch: " .. (branch.head or "?"))
|
||||||
|
label(#lines - 1, 6)
|
||||||
|
|
||||||
if branch.upstream then
|
if branch.upstream then
|
||||||
local push = "Push: " .. branch.upstream
|
local up = "Upstream: " .. branch.upstream
|
||||||
local extras = {}
|
local extras = {}
|
||||||
if branch.ahead > 0 then
|
if branch.ahead > 0 then
|
||||||
local col = #push + 1
|
local col = #up + 1
|
||||||
push = push .. " +" .. branch.ahead
|
up = up .. " +" .. branch.ahead
|
||||||
table.insert(extras, { col = col, end_col = #push, hl = "GitUnpushed" })
|
table.insert(extras, {
|
||||||
|
col = col,
|
||||||
|
end_col = #up,
|
||||||
|
hl = "GitUnpushed",
|
||||||
|
})
|
||||||
end
|
end
|
||||||
if branch.behind > 0 then
|
if branch.behind > 0 then
|
||||||
local col = #push + 1
|
local col = #up + 1
|
||||||
push = push .. " -" .. branch.behind
|
up = up .. " -" .. branch.behind
|
||||||
table.insert(extras, { col = col, end_col = #push, hl = "GitUnpulled" })
|
table.insert(extras, {
|
||||||
|
col = col,
|
||||||
|
end_col = #up,
|
||||||
|
hl = "GitUnpulled",
|
||||||
|
})
|
||||||
end
|
end
|
||||||
table.insert(lines, push)
|
table.insert(lines, up)
|
||||||
local row = #lines - 1
|
local row = #lines - 1
|
||||||
label(row, 4)
|
label(row, 8)
|
||||||
for _, e in ipairs(extras) do
|
for _, e in ipairs(extras) do
|
||||||
e.row = row
|
e.row = row
|
||||||
table.insert(marks, e)
|
table.insert(marks, e)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
table.insert(lines, "Help: g?")
|
|
||||||
label(#lines - 1, 4)
|
|
||||||
|
|
||||||
table.insert(lines, "")
|
table.insert(lines, "")
|
||||||
|
|
||||||
for _, section in ipairs(SECTIONS) do
|
for _, section in ipairs(SECTIONS) do
|
||||||
@@ -191,7 +206,7 @@ local function refresh(bufnr)
|
|||||||
if not s or not vim.api.nvim_buf_is_valid(bufnr) then
|
if not s or not vim.api.nvim_buf_is_valid(bufnr) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
render(bufnr, s.repo.status)
|
render(bufnr, s.repo)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param bufnr integer
|
---@param bufnr integer
|
||||||
|
|||||||
Reference in New Issue
Block a user