feat(table): refactor table with input in the middle
This commit is contained in:
parent
44f8a3cb74
commit
ff75b975ab
1 changed files with 41 additions and 7 deletions
|
|
@ -4,6 +4,25 @@
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
|
local exit_code_names = {
|
||||||
|
[128] = 'SIGHUP',
|
||||||
|
[129] = 'SIGINT',
|
||||||
|
[130] = 'SIGQUIT',
|
||||||
|
[131] = 'SIGILL',
|
||||||
|
[132] = 'SIGTRAP',
|
||||||
|
[133] = 'SIGABRT',
|
||||||
|
[134] = 'SIGBUS',
|
||||||
|
[135] = 'SIGFPE',
|
||||||
|
[136] = 'SIGKILL',
|
||||||
|
[137] = 'SIGUSR1',
|
||||||
|
[138] = 'SIGSEGV',
|
||||||
|
[139] = 'SIGUSR2',
|
||||||
|
[140] = 'SIGPIPE',
|
||||||
|
[141] = 'SIGALRM',
|
||||||
|
[142] = 'SIGTERM',
|
||||||
|
[143] = 'SIGCHLD',
|
||||||
|
}
|
||||||
|
|
||||||
---Convert test status to CP terminology with colors
|
---Convert test status to CP terminology with colors
|
||||||
---@param test_case TestCase
|
---@param test_case TestCase
|
||||||
---@return StatusInfo
|
---@return StatusInfo
|
||||||
|
|
@ -34,9 +53,9 @@ function M.render_test_list(test_state)
|
||||||
local lines = {}
|
local lines = {}
|
||||||
local highlights = {}
|
local highlights = {}
|
||||||
|
|
||||||
local header = ' # │ Status │ Time │ Exit │ Input'
|
local header = ' # │ Status │ Time │ Exit Code'
|
||||||
local separator =
|
local separator =
|
||||||
'────┼────────┼──────┼──────┼─────────────────'
|
'────┼────────┼──────┼───────────'
|
||||||
table.insert(lines, header)
|
table.insert(lines, header)
|
||||||
table.insert(lines, separator)
|
table.insert(lines, separator)
|
||||||
|
|
||||||
|
|
@ -48,16 +67,22 @@ function M.render_test_list(test_state)
|
||||||
local num_col = string.format('%s%-2d', prefix, i)
|
local num_col = string.format('%s%-2d', prefix, i)
|
||||||
local status_col = string.format(' %-6s', status_info.text)
|
local status_col = string.format(' %-6s', status_info.text)
|
||||||
local time_col = test_case.time_ms and string.format('%4.0fms', test_case.time_ms) or ' — '
|
local time_col = test_case.time_ms and string.format('%4.0fms', test_case.time_ms) or ' — '
|
||||||
local exit_col = test_case.code and string.format(' %-3d', test_case.code) or ' — '
|
local exit_col = ' — '
|
||||||
local input_col = test_case.input and test_case.input:gsub('\n', ' ') or ''
|
if test_case.code then
|
||||||
|
local signal_name = exit_code_names[test_case.code]
|
||||||
|
if signal_name then
|
||||||
|
exit_col = string.format(' %d (%s)', test_case.code, signal_name)
|
||||||
|
else
|
||||||
|
exit_col = string.format(' %d', test_case.code)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local line = string.format(
|
local line = string.format(
|
||||||
'%s │%s │ %s │%s │ %s',
|
'%s │%s │ %s │%s',
|
||||||
num_col,
|
num_col,
|
||||||
status_col,
|
status_col,
|
||||||
time_col,
|
time_col,
|
||||||
exit_col,
|
exit_col
|
||||||
input_col
|
|
||||||
)
|
)
|
||||||
table.insert(lines, line)
|
table.insert(lines, line)
|
||||||
|
|
||||||
|
|
@ -71,6 +96,15 @@ function M.render_test_list(test_state)
|
||||||
highlight_group = status_info.highlight_group,
|
highlight_group = status_info.highlight_group,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if is_current and test_case.input and test_case.input ~= '' then
|
||||||
|
for _, input_line in ipairs(vim.split(test_case.input, '\n', { plain = true, trimempty = false })) do
|
||||||
|
table.insert(lines, input_line)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local separator = '─────────────────────────────────────────────────────────────'
|
||||||
|
table.insert(lines, separator)
|
||||||
end
|
end
|
||||||
|
|
||||||
return lines, highlights
|
return lines, highlights
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue