feat(run): prettier panel arrow

This commit is contained in:
Barrett Ruth 2025-09-19 21:02:15 -04:00
parent 514761733b
commit 161a84ff12

View file

@ -54,7 +54,7 @@ local function format_exit_code(code)
end end
local function compute_cols(test_state) local function compute_cols(test_state)
local w = { num = 3, status = 8, time = 6, exit = 11, timeout = 8, memory = 8 } local w = { num = 4, status = 8, time = 6, timeout = 8, memory = 8, exit = 11 }
local timeout_str = '' local timeout_str = ''
local memory_str = '' local memory_str = ''
@ -72,19 +72,19 @@ local function compute_cols(test_state)
w.status = math.max(w.status, #(' ' .. M.get_status_info(tc).text .. ' ')) w.status = math.max(w.status, #(' ' .. M.get_status_info(tc).text .. ' '))
local time_str = tc.time_ms and string.format('%.2f', tc.time_ms) or '' local time_str = tc.time_ms and string.format('%.2f', tc.time_ms) or ''
w.time = math.max(w.time, #(' ' .. time_str .. ' ')) w.time = math.max(w.time, #(' ' .. time_str .. ' '))
w.exit = math.max(w.exit, #(' ' .. format_exit_code(tc.code) .. ' '))
w.timeout = math.max(w.timeout, #(' ' .. timeout_str .. ' ')) w.timeout = math.max(w.timeout, #(' ' .. timeout_str .. ' '))
w.memory = math.max(w.memory, #(' ' .. memory_str .. ' ')) w.memory = math.max(w.memory, #(' ' .. memory_str .. ' '))
w.exit = math.max(w.exit, #(' ' .. format_exit_code(tc.code) .. ' '))
end end
w.num = math.max(w.num, #' # ') w.num = math.max(w.num, #' # ')
w.status = math.max(w.status, #' Status ') w.status = math.max(w.status, #' Status ')
w.time = math.max(w.time, #' Runtime (ms) ') w.time = math.max(w.time, #' Runtime (ms) ')
w.exit = math.max(w.exit, #' Exit Code ')
w.timeout = math.max(w.timeout, #' Time (ms) ') w.timeout = math.max(w.timeout, #' Time (ms) ')
w.memory = math.max(w.memory, #' Mem (MB) ') w.memory = math.max(w.memory, #' Mem (MB) ')
w.exit = math.max(w.exit, #' Exit Code ')
local sum = w.num + w.status + w.time + w.exit + w.timeout + w.memory local sum = w.num + w.status + w.time + w.timeout + w.memory + w.exit
local inner = sum + 5 local inner = sum + 5
local total = inner + 2 local total = inner + 2
return { w = w, sum = sum, inner = inner, total = total } return { w = w, sum = sum, inner = inner, total = total }
@ -108,6 +108,20 @@ local function right_align(text, width)
return string.rep(' ', pad) .. content return string.rep(' ', pad) .. content
end end
local function format_num_column(prefix, idx, width)
local num_str = tostring(idx)
if #num_str == 1 then
local content = prefix .. num_str .. ' '
local pad = width - #content
if pad <= 0 then
return content
end
return string.rep(' ', pad) .. content
else
return center(prefix .. idx, width)
end
end
local function top_border(c) local function top_border(c)
local w = c.w local w = c.w
return '' return ''
@ -117,11 +131,11 @@ local function top_border(c)
.. '' .. ''
.. string.rep('', w.time) .. string.rep('', w.time)
.. '' .. ''
.. string.rep('', w.exit)
.. ''
.. string.rep('', w.timeout) .. string.rep('', w.timeout)
.. '' .. ''
.. string.rep('', w.memory) .. string.rep('', w.memory)
.. ''
.. string.rep('', w.exit)
.. '' .. ''
end end
@ -134,11 +148,11 @@ local function row_sep(c)
.. '' .. ''
.. string.rep('', w.time) .. string.rep('', w.time)
.. '' .. ''
.. string.rep('', w.exit)
.. ''
.. string.rep('', w.timeout) .. string.rep('', w.timeout)
.. '' .. ''
.. string.rep('', w.memory) .. string.rep('', w.memory)
.. ''
.. string.rep('', w.exit)
.. '' .. ''
end end
@ -151,11 +165,11 @@ local function bottom_border(c)
.. '' .. ''
.. string.rep('', w.time) .. string.rep('', w.time)
.. '' .. ''
.. string.rep('', w.exit)
.. ''
.. string.rep('', w.timeout) .. string.rep('', w.timeout)
.. '' .. ''
.. string.rep('', w.memory) .. string.rep('', w.memory)
.. ''
.. string.rep('', w.exit)
.. '' .. ''
end end
@ -168,11 +182,11 @@ local function flat_fence_above(c)
.. '' .. ''
.. string.rep('', w.time) .. string.rep('', w.time)
.. '' .. ''
.. string.rep('', w.exit)
.. ''
.. string.rep('', w.timeout) .. string.rep('', w.timeout)
.. '' .. ''
.. string.rep('', w.memory) .. string.rep('', w.memory)
.. ''
.. string.rep('', w.exit)
.. '' .. ''
end end
@ -185,11 +199,11 @@ local function flat_fence_below(c)
.. '' .. ''
.. string.rep('', w.time) .. string.rep('', w.time)
.. '' .. ''
.. string.rep('', w.exit)
.. ''
.. string.rep('', w.timeout) .. string.rep('', w.timeout)
.. '' .. ''
.. string.rep('', w.memory) .. string.rep('', w.memory)
.. ''
.. string.rep('', w.exit)
.. '' .. ''
end end
@ -206,12 +220,12 @@ local function header_line(c)
.. '' .. ''
.. center('Runtime (ms)', w.time) .. center('Runtime (ms)', w.time)
.. '' .. ''
.. center('Exit Code', w.exit)
.. ''
.. center('Time (ms)', w.timeout) .. center('Time (ms)', w.timeout)
.. '' .. ''
.. center('Mem (MB)', w.memory) .. center('Mem (MB)', w.memory)
.. '' .. ''
.. center('Exit Code', w.exit)
.. ''
end end
local function data_row(c, idx, tc, is_current, test_state) local function data_row(c, idx, tc, is_current, test_state)
@ -238,12 +252,12 @@ local function data_row(c, idx, tc, is_current, test_state)
.. '' .. ''
.. right_align(time, w.time) .. right_align(time, w.time)
.. '' .. ''
.. right_align(exit, w.exit)
.. ''
.. right_align(timeout, w.timeout) .. right_align(timeout, w.timeout)
.. '' .. ''
.. right_align(memory, w.memory) .. right_align(memory, w.memory)
.. '' .. ''
.. right_align(exit, w.exit)
.. ''
local hi local hi
if status.text ~= '' then if status.text ~= '' then
@ -286,6 +300,10 @@ function M.render_test_list(test_state)
if has_input then if has_input then
table.insert(lines, flat_fence_above(c)) table.insert(lines, flat_fence_above(c))
local input_header = 'Input:'
local header_pad = c.inner - #input_header
table.insert(lines, '' .. input_header .. string.rep(' ', header_pad) .. '')
for _, input_line in ipairs(vim.split(tc.input, '\n', { plain = true, trimempty = false })) do for _, input_line in ipairs(vim.split(tc.input, '\n', { plain = true, trimempty = false })) do
local s = input_line or '' local s = input_line or ''
if #s > c.inner then if #s > c.inner then