Compare commits

...

2 Commits

+39 -20
View File
@@ -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
@@ -662,7 +677,10 @@ local function set_keymaps(bufnr, placement)
end end
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) function M.open(opts)
opts = opts or {} opts = opts or {}
local placement = opts.placement or "sidebar" local placement = opts.placement or "sidebar"
@@ -765,13 +783,14 @@ function M.read_uri(buf)
r:refresh() r:refresh()
end end
function M.toggle() ---@param opts? ow.Git.StatusView.OpenOpts
function M.toggle(opts)
local existing = find_view() local existing = find_view()
if existing then if existing then
vim.api.nvim_win_close(existing, false) vim.api.nvim_win_close(existing, false)
return return
end end
M.open({ placement = "sidebar" }) M.open(opts)
end end
return M return M