fix input display
This commit is contained in:
parent
dc6f2fd5b6
commit
59f5066327
3 changed files with 24 additions and 13 deletions
|
|
@ -57,10 +57,13 @@ local function parse_command(args)
|
||||||
if test_arg then
|
if test_arg then
|
||||||
local test_index = tonumber(test_arg)
|
local test_index = tonumber(test_arg)
|
||||||
if not test_index then
|
if not test_index then
|
||||||
return { type = 'error', message = 'Test index must be a number' }
|
return {
|
||||||
|
type = 'error',
|
||||||
|
message = ("Test index '%s' is not a number"):format(test_index),
|
||||||
|
}
|
||||||
end
|
end
|
||||||
if test_index < 1 or test_index ~= math.floor(test_index) then
|
if test_index < 1 or test_index ~= math.floor(test_index) then
|
||||||
return { type = 'error', message = 'Test index must be >= 1' }
|
return { type = 'error', message = ("'%s' is not a valid test index"):format(test_index) }
|
||||||
end
|
end
|
||||||
return { type = 'action', action = 'run', test_index = test_index }
|
return { type = 'action', action = 'run', test_index = test_index }
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ local function start_tests(platform, contest_id, problems)
|
||||||
local test_cases = cache.get_test_cases(platform, contest_id, state.get_problem_id())
|
local test_cases = cache.get_test_cases(platform, contest_id, state.get_problem_id())
|
||||||
local input_lines = {}
|
local input_lines = {}
|
||||||
for _, tc in ipairs(test_cases) do
|
for _, tc in ipairs(test_cases) do
|
||||||
for _, line in ipairs(vim.split(tc.input, '\n', { plain = true, trimempty = false })) do
|
for _, line in ipairs(vim.split(tc.input, '\n')) do
|
||||||
table.insert(input_lines, line)
|
table.insert(input_lines, line)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -85,9 +85,9 @@ function M.toggle_interactive(interactor_cmd)
|
||||||
if
|
if
|
||||||
not contest_data
|
not contest_data
|
||||||
or not contest_data.index_map
|
or not contest_data.index_map
|
||||||
or not contest_data.problems[contest_data.index_map[problem_id]].interactive
|
or contest_data.problems[contest_data.index_map[problem_id]].interactive
|
||||||
then
|
then
|
||||||
logger.log('This problem is not interactive. Use :CP {run,panel}.', vim.log.levels.ERROR)
|
logger.log('This problem is interactive. Use :CP {run,panel}.', vim.log.levels.ERROR)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -275,9 +275,18 @@ function M.ensure_io_view()
|
||||||
utils.update_buffer_content(input_buf, {})
|
utils.update_buffer_content(input_buf, {})
|
||||||
utils.update_buffer_content(output_buf, {})
|
utils.update_buffer_content(output_buf, {})
|
||||||
|
|
||||||
vim.api.nvim_set_current_win(solution_win)
|
local test_cases = cache.get_test_cases(platform, contest_id, problem_id)
|
||||||
|
if test_cases and #test_cases > 0 then
|
||||||
|
local input_lines = {}
|
||||||
|
for _, tc in ipairs(test_cases) do
|
||||||
|
for _, line in ipairs(vim.split(tc.input, '\n')) do
|
||||||
|
table.insert(input_lines, line)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
utils.update_buffer_content(input_buf, input_lines, nil, nil)
|
||||||
|
end
|
||||||
|
|
||||||
populate_input()
|
vim.api.nvim_set_current_win(solution_win)
|
||||||
end
|
end
|
||||||
|
|
||||||
function M.run_io_view(test_index)
|
function M.run_io_view(test_index)
|
||||||
|
|
@ -295,9 +304,9 @@ function M.run_io_view(test_index)
|
||||||
if
|
if
|
||||||
not contest_data
|
not contest_data
|
||||||
or not contest_data.index_map
|
or not contest_data.index_map
|
||||||
or not contest_data.problems[contest_data.index_map[problem_id]].interactive
|
or contest_data.problems[contest_data.index_map[problem_id]].interactive
|
||||||
then
|
then
|
||||||
logger.log('This problem is not interactive. Use :CP {run,panel}.', vim.log.levels.ERROR)
|
logger.log('This problem is interactive. Use :CP {run,panel}.', vim.log.levels.ERROR)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -320,7 +329,7 @@ function M.run_io_view(test_index)
|
||||||
test_index,
|
test_index,
|
||||||
#test_state.test_cases
|
#test_state.test_cases
|
||||||
),
|
),
|
||||||
vim.log.levels.ERROR
|
vim.log.levels.WARN
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
@ -368,7 +377,7 @@ function M.run_io_view(test_index)
|
||||||
local input_lines = {}
|
local input_lines = {}
|
||||||
for _, idx in ipairs(test_indices) do
|
for _, idx in ipairs(test_indices) do
|
||||||
local tc = test_state.test_cases[idx]
|
local tc = test_state.test_cases[idx]
|
||||||
for _, line in ipairs(vim.split(tc.input, '\n', { plain = true, trimempty = false })) do
|
for _, line in ipairs(vim.split(tc.input, '\n')) do
|
||||||
table.insert(input_lines, line)
|
table.insert(input_lines, line)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -439,7 +448,6 @@ function M.toggle_panel(panel_opts)
|
||||||
end
|
end
|
||||||
state.set_active_panel(nil)
|
state.set_active_panel(nil)
|
||||||
M.ensure_io_view()
|
M.ensure_io_view()
|
||||||
populate_input()
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -452,7 +460,7 @@ function M.toggle_panel(panel_opts)
|
||||||
|
|
||||||
if not platform or not contest_id then
|
if not platform or not contest_id then
|
||||||
logger.log(
|
logger.log(
|
||||||
'No platform/contest/problem configured. Use :CP <platform> <contest> [...] first.',
|
'No platform/contest configured. Use :CP <platform> <contest> [...] first.',
|
||||||
vim.log.levels.ERROR
|
vim.log.levels.ERROR
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue