Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4461a65b90 | |||
| 8121227ba4 |
+39
-20
@@ -103,8 +103,9 @@ local function display_name(section)
|
||||
end
|
||||
|
||||
---@param bufnr integer
|
||||
---@param status ow.Git.Status
|
||||
local function render(bufnr, status)
|
||||
---@param r ow.Git.Repo
|
||||
local function render(bufnr, r)
|
||||
local status = r.status
|
||||
local branch = status.branch
|
||||
local lines = {}
|
||||
local marks = {}
|
||||
@@ -114,34 +115,48 @@ local function render(bufnr, status)
|
||||
table.insert(marks, { row = row, col = 0, end_col = len, hl = "Label" })
|
||||
end
|
||||
|
||||
table.insert(lines, "Head: " .. (branch.head or "?"))
|
||||
label(#lines - 1, 4)
|
||||
local repo_line = vim.fn.fnamemodify(r.worktree, ":t")
|
||||
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
|
||||
local push = "Push: " .. branch.upstream
|
||||
local up = "Upstream: " .. branch.upstream
|
||||
local extras = {}
|
||||
if branch.ahead > 0 then
|
||||
local col = #push + 1
|
||||
push = push .. " +" .. branch.ahead
|
||||
table.insert(extras, { col = col, end_col = #push, hl = "GitUnpushed" })
|
||||
local col = #up + 1
|
||||
up = up .. " +" .. branch.ahead
|
||||
table.insert(extras, {
|
||||
col = col,
|
||||
end_col = #up,
|
||||
hl = "GitUnpushed",
|
||||
})
|
||||
end
|
||||
if branch.behind > 0 then
|
||||
local col = #push + 1
|
||||
push = push .. " -" .. branch.behind
|
||||
table.insert(extras, { col = col, end_col = #push, hl = "GitUnpulled" })
|
||||
local col = #up + 1
|
||||
up = up .. " -" .. branch.behind
|
||||
table.insert(extras, {
|
||||
col = col,
|
||||
end_col = #up,
|
||||
hl = "GitUnpulled",
|
||||
})
|
||||
end
|
||||
table.insert(lines, push)
|
||||
table.insert(lines, up)
|
||||
local row = #lines - 1
|
||||
label(row, 4)
|
||||
label(row, 8)
|
||||
for _, e in ipairs(extras) do
|
||||
e.row = row
|
||||
table.insert(marks, e)
|
||||
end
|
||||
end
|
||||
|
||||
table.insert(lines, "Help: g?")
|
||||
label(#lines - 1, 4)
|
||||
|
||||
table.insert(lines, "")
|
||||
|
||||
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
|
||||
return
|
||||
end
|
||||
render(bufnr, s.repo.status)
|
||||
render(bufnr, s.repo)
|
||||
end
|
||||
|
||||
---@param bufnr integer
|
||||
@@ -662,7 +677,10 @@ local function set_keymaps(bufnr, placement)
|
||||
end
|
||||
end
|
||||
|
||||
---@param opts? { placement: ow.Git.StatusView.Placement? }
|
||||
---@class ow.Git.StatusView.OpenOpts
|
||||
---@field placement ow.Git.StatusView.Placement?
|
||||
|
||||
---@param opts? ow.Git.StatusView.OpenOpts
|
||||
function M.open(opts)
|
||||
opts = opts or {}
|
||||
local placement = opts.placement or "sidebar"
|
||||
@@ -765,13 +783,14 @@ function M.read_uri(buf)
|
||||
r:refresh()
|
||||
end
|
||||
|
||||
function M.toggle()
|
||||
---@param opts? ow.Git.StatusView.OpenOpts
|
||||
function M.toggle(opts)
|
||||
local existing = find_view()
|
||||
if existing then
|
||||
vim.api.nvim_win_close(existing, false)
|
||||
return
|
||||
end
|
||||
M.open({ placement = "sidebar" })
|
||||
M.open(opts)
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user