feat: customization
This commit is contained in:
parent
6f9452c7e1
commit
249e84eb5a
5 changed files with 192 additions and 73 deletions
|
|
@ -10,6 +10,10 @@ function M.clearcol(bufnr)
|
|||
end
|
||||
end
|
||||
|
||||
---Pad text on the right (left-align text within width)
|
||||
---@param text string
|
||||
---@param width integer
|
||||
---@return string
|
||||
function M.pad_right(text, width)
|
||||
local pad = width - #text
|
||||
if pad <= 0 then
|
||||
|
|
@ -18,6 +22,10 @@ function M.pad_right(text, width)
|
|||
return text .. string.rep(' ', pad)
|
||||
end
|
||||
|
||||
---Pad text on the left (right-align text within width)
|
||||
---@param text string
|
||||
---@param width integer
|
||||
---@return string
|
||||
function M.pad_left(text, width)
|
||||
local pad = width - #text
|
||||
if pad <= 0 then
|
||||
|
|
@ -26,6 +34,10 @@ function M.pad_left(text, width)
|
|||
return string.rep(' ', pad) .. text
|
||||
end
|
||||
|
||||
---Center text within width
|
||||
---@param text string
|
||||
---@param width integer
|
||||
---@return string
|
||||
function M.center(text, width)
|
||||
local pad = width - #text
|
||||
if pad <= 0 then
|
||||
|
|
@ -35,4 +47,44 @@ function M.center(text, width)
|
|||
return string.rep(' ', left) .. text .. string.rep(' ', pad - left)
|
||||
end
|
||||
|
||||
---Default verdict formatter for I/O view
|
||||
---@param data VerdictFormatData
|
||||
---@return VerdictFormatResult
|
||||
function M.default_verdict_formatter(data)
|
||||
local time_data = string.format('%.2f', data.time_ms) .. '/' .. data.time_limit_ms
|
||||
local mem_data = string.format('%.0f', data.memory_mb)
|
||||
.. '/'
|
||||
.. string.format('%.0f', data.memory_limit_mb)
|
||||
local exit_str = data.signal and string.format('%d (%s)', data.exit_code, data.signal)
|
||||
or tostring(data.exit_code)
|
||||
|
||||
local test_num_part = 'Test ' .. data.index .. ':'
|
||||
local status_part = M.pad_right(data.status.text, 3)
|
||||
local time_part = time_data .. ' ms'
|
||||
local mem_part = mem_data .. ' MB'
|
||||
local exit_part = 'exit: ' .. exit_str
|
||||
|
||||
local line = test_num_part
|
||||
.. ' '
|
||||
.. status_part
|
||||
.. ' | '
|
||||
.. time_part
|
||||
.. ' | '
|
||||
.. mem_part
|
||||
.. ' | '
|
||||
.. exit_part
|
||||
|
||||
local highlights = {}
|
||||
local status_pos = line:find(data.status.text, 1, true)
|
||||
if status_pos then
|
||||
table.insert(highlights, {
|
||||
col_start = status_pos - 1,
|
||||
col_end = status_pos - 1 + #data.status.text,
|
||||
group = data.status.highlight_group,
|
||||
})
|
||||
end
|
||||
|
||||
return { line = line, highlights = highlights }
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue