mirror of
https://github.com/harivansh-afk/forge.nvim.git
synced 2026-04-15 09:01:15 +00:00
feat: color schemes
This commit is contained in:
parent
20b3651c6c
commit
afb5d93853
1 changed files with 57 additions and 72 deletions
|
|
@ -157,6 +157,16 @@ local hl_defaults = {
|
||||||
ForgeComposeFile = 'Directory',
|
ForgeComposeFile = 'Directory',
|
||||||
ForgeComposeAdded = 'Added',
|
ForgeComposeAdded = 'Added',
|
||||||
ForgeComposeRemoved = 'Removed',
|
ForgeComposeRemoved = 'Removed',
|
||||||
|
ForgeNumber = 'Number',
|
||||||
|
ForgeOpen = 'DiagnosticInfo',
|
||||||
|
ForgeMerged = 'Constant',
|
||||||
|
ForgeClosed = 'Comment',
|
||||||
|
ForgePass = 'DiagnosticOk',
|
||||||
|
ForgeFail = 'DiagnosticError',
|
||||||
|
ForgePending = 'DiagnosticWarn',
|
||||||
|
ForgeSkip = 'Comment',
|
||||||
|
ForgeBranch = 'Special',
|
||||||
|
ForgeDim = 'Comment',
|
||||||
}
|
}
|
||||||
|
|
||||||
for group, link in pairs(hl_defaults) do
|
for group, link in pairs(hl_defaults) do
|
||||||
|
|
@ -490,21 +500,6 @@ local function relative_time(iso)
|
||||||
return ('%dy'):format(math.floor(diff / 31536000))
|
return ('%dy'):format(math.floor(diff / 31536000))
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param iso string?
|
|
||||||
---@return string
|
|
||||||
local function compact_date(iso)
|
|
||||||
local ts = parse_iso(iso)
|
|
||||||
if not ts then
|
|
||||||
return ''
|
|
||||||
end
|
|
||||||
local current_year = os.date('%Y')
|
|
||||||
local entry_year = os.date('%Y', ts)
|
|
||||||
if entry_year == current_year then
|
|
||||||
return os.date('%d/%m %H:%M', ts)
|
|
||||||
end
|
|
||||||
return os.date('%d/%m/%y %H:%M', ts)
|
|
||||||
end
|
|
||||||
|
|
||||||
local event_map = {
|
local event_map = {
|
||||||
merge_request_event = 'mr',
|
merge_request_event = 'mr',
|
||||||
external_pull_request_event = 'ext',
|
external_pull_request_event = 'ext',
|
||||||
|
|
@ -535,6 +530,11 @@ local function extract_author(entry, field)
|
||||||
return tostring(v or '')
|
return tostring(v or '')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function hl(group, text)
|
||||||
|
local utils = require('fzf-lua.utils')
|
||||||
|
return utils.ansi_from_hl(group, text)
|
||||||
|
end
|
||||||
|
|
||||||
---@param entry table
|
---@param entry table
|
||||||
---@param fields table
|
---@param fields table
|
||||||
---@param show_state boolean
|
---@param show_state boolean
|
||||||
|
|
@ -550,23 +550,22 @@ function M.format_pr(entry, fields, show_state)
|
||||||
local prefix = ''
|
local prefix = ''
|
||||||
if show_state then
|
if show_state then
|
||||||
local state = (entry[fields.state] or ''):lower()
|
local state = (entry[fields.state] or ''):lower()
|
||||||
local icon, color
|
local icon, group
|
||||||
if state == 'open' or state == 'opened' then
|
if state == 'open' or state == 'opened' then
|
||||||
icon, color = icons.open, '\27[34m'
|
icon, group = icons.open, 'ForgeOpen'
|
||||||
elseif state == 'merged' then
|
elseif state == 'merged' then
|
||||||
icon, color = icons.merged, '\27[35m'
|
icon, group = icons.merged, 'ForgeMerged'
|
||||||
else
|
else
|
||||||
icon, color = icons.closed, '\27[31m'
|
icon, group = icons.closed, 'ForgeClosed'
|
||||||
end
|
end
|
||||||
prefix = color .. icon .. '\27[0m '
|
prefix = hl(group, icon) .. ' '
|
||||||
end
|
end
|
||||||
return ('%s\27[34m#%-5s\27[0m %s \27[2m%-' .. widths.author .. 's %3s\27[0m'):format(
|
return prefix
|
||||||
prefix,
|
.. hl('ForgeNumber', ('#%-5s'):format(num))
|
||||||
num,
|
.. ' '
|
||||||
pad_or_truncate(title, widths.title),
|
.. pad_or_truncate(title, widths.title)
|
||||||
pad_or_truncate(author, widths.author),
|
.. ' '
|
||||||
age
|
.. hl('ForgeDim', pad_or_truncate(author, widths.author) .. (' %3s'):format(age))
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param entry table
|
---@param entry table
|
||||||
|
|
@ -584,21 +583,20 @@ function M.format_issue(entry, fields, show_state)
|
||||||
local prefix = ''
|
local prefix = ''
|
||||||
if show_state then
|
if show_state then
|
||||||
local state = (entry[fields.state] or ''):lower()
|
local state = (entry[fields.state] or ''):lower()
|
||||||
local icon, color
|
local icon, group
|
||||||
if state == 'open' or state == 'opened' then
|
if state == 'open' or state == 'opened' then
|
||||||
icon, color = icons.open, '\27[34m'
|
icon, group = icons.open, 'ForgeOpen'
|
||||||
else
|
else
|
||||||
icon, color = icons.closed, '\27[2m'
|
icon, group = icons.closed, 'ForgeClosed'
|
||||||
end
|
end
|
||||||
prefix = color .. icon .. '\27[0m '
|
prefix = hl(group, icon) .. ' '
|
||||||
end
|
end
|
||||||
return ('%s\27[34m#%-5s\27[0m %s \27[2m%-' .. widths.author .. 's %3s\27[0m'):format(
|
return prefix
|
||||||
prefix,
|
.. hl('ForgeNumber', ('#%-5s'):format(num))
|
||||||
num,
|
.. ' '
|
||||||
pad_or_truncate(title, widths.title),
|
.. pad_or_truncate(title, widths.title)
|
||||||
pad_or_truncate(author, widths.author),
|
.. ' '
|
||||||
age
|
.. hl('ForgeDim', pad_or_truncate(author, widths.author) .. (' %3s'):format(age))
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param check table
|
---@param check table
|
||||||
|
|
@ -609,17 +607,17 @@ function M.format_check(check)
|
||||||
local widths = display.widths
|
local widths = display.widths
|
||||||
local bucket = (check.bucket or 'pending'):lower()
|
local bucket = (check.bucket or 'pending'):lower()
|
||||||
local name = check.name or ''
|
local name = check.name or ''
|
||||||
local icon, color
|
local icon, group
|
||||||
if bucket == 'pass' then
|
if bucket == 'pass' then
|
||||||
icon, color = icons.pass, '\27[32m'
|
icon, group = icons.pass, 'ForgePass'
|
||||||
elseif bucket == 'fail' then
|
elseif bucket == 'fail' then
|
||||||
icon, color = icons.fail, '\27[31m'
|
icon, group = icons.fail, 'ForgeFail'
|
||||||
elseif bucket == 'pending' then
|
elseif bucket == 'pending' then
|
||||||
icon, color = icons.pending, '\27[33m'
|
icon, group = icons.pending, 'ForgePending'
|
||||||
elseif bucket == 'skipping' or bucket == 'cancel' then
|
elseif bucket == 'skipping' or bucket == 'cancel' then
|
||||||
icon, color = icons.skip, '\27[2m'
|
icon, group = icons.skip, 'ForgeSkip'
|
||||||
else
|
else
|
||||||
icon, color = icons.unknown, '\27[2m'
|
icon, group = icons.unknown, 'ForgeSkip'
|
||||||
end
|
end
|
||||||
local elapsed = ''
|
local elapsed = ''
|
||||||
if check.startedAt and check.completedAt and check.completedAt ~= '' then
|
if check.startedAt and check.completedAt and check.completedAt ~= '' then
|
||||||
|
|
@ -634,12 +632,7 @@ function M.format_check(check)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return ('%s%s\27[0m %s \27[2m%s\27[0m'):format(
|
return hl(group, icon) .. ' ' .. pad_or_truncate(name, widths.name) .. ' ' .. hl('ForgeDim', elapsed)
|
||||||
color,
|
|
||||||
icon,
|
|
||||||
pad_or_truncate(name, widths.name),
|
|
||||||
elapsed
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param run forge.CIRun
|
---@param run forge.CIRun
|
||||||
|
|
@ -648,39 +641,31 @@ function M.format_run(run)
|
||||||
local display = M.config().display
|
local display = M.config().display
|
||||||
local icons = display.icons
|
local icons = display.icons
|
||||||
local widths = display.widths
|
local widths = display.widths
|
||||||
local icon, color
|
local icon, group
|
||||||
local s = run.status:lower()
|
local s = run.status:lower()
|
||||||
if s == 'success' then
|
if s == 'success' then
|
||||||
icon, color = icons.pass, '\27[32m'
|
icon, group = icons.pass, 'ForgePass'
|
||||||
elseif s == 'failure' or s == 'failed' then
|
elseif s == 'failure' or s == 'failed' then
|
||||||
icon, color = icons.fail, '\27[31m'
|
icon, group = icons.fail, 'ForgeFail'
|
||||||
elseif s == 'in_progress' or s == 'running' or s == 'pending' or s == 'queued' then
|
elseif s == 'in_progress' or s == 'running' or s == 'pending' or s == 'queued' then
|
||||||
icon, color = icons.pending, '\27[33m'
|
icon, group = icons.pending, 'ForgePending'
|
||||||
elseif s == 'cancelled' or s == 'canceled' or s == 'skipped' then
|
elseif s == 'cancelled' or s == 'canceled' or s == 'skipped' then
|
||||||
icon, color = icons.skip, '\27[2m'
|
icon, group = icons.skip, 'ForgeSkip'
|
||||||
else
|
else
|
||||||
icon, color = icons.unknown, '\27[2m'
|
icon, group = icons.unknown, 'ForgeSkip'
|
||||||
end
|
end
|
||||||
local event = abbreviate_event(run.event)
|
local event = abbreviate_event(run.event)
|
||||||
local date = compact_date(run.created_at)
|
local age = relative_time(run.created_at)
|
||||||
if run.branch ~= '' then
|
if run.branch ~= '' then
|
||||||
local name_w = widths.name - widths.branch + 10
|
local name_w = widths.name - widths.branch + 10
|
||||||
return ('%s%s\27[0m %s \27[36m%s\27[0m \27[2m%-6s %s\27[0m'):format(
|
return hl(group, icon) .. ' '
|
||||||
color,
|
.. pad_or_truncate(run.name, name_w) .. ' '
|
||||||
icon,
|
.. hl('ForgeBranch', pad_or_truncate(run.branch, widths.branch)) .. ' '
|
||||||
pad_or_truncate(run.name, name_w),
|
.. hl('ForgeDim', ('%-6s'):format(event) .. ' ' .. age)
|
||||||
pad_or_truncate(run.branch, widths.branch),
|
|
||||||
event,
|
|
||||||
date
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
return ('%s%s\27[0m %s \27[2m%-6s %s\27[0m'):format(
|
return hl(group, icon) .. ' '
|
||||||
color,
|
.. pad_or_truncate(run.name, widths.name) .. ' '
|
||||||
icon,
|
.. hl('ForgeDim', ('%-6s'):format(event) .. ' ' .. age)
|
||||||
pad_or_truncate(run.name, widths.name),
|
|
||||||
event,
|
|
||||||
date
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param checks table[]
|
---@param checks table[]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue