feat(ui): auto-hide source buffer on close

This commit is contained in:
Barrett Ruth 2025-10-24 14:47:12 -04:00
parent 4b1b75fd6e
commit a842886933
4 changed files with 29 additions and 16 deletions

View file

@ -590,14 +590,18 @@ Input: |VerdictFormatData| table with test results
Output: |VerdictFormatResult| table with formatted line and optional highlights Output: |VerdictFormatResult| table with formatted line and optional highlights
*VerdictFormatData* *VerdictFormatData*
{index} (integer) Test case number {index} (integer) Test case number
{status} (table) { text: string, highlight_group: string } {status} (table) { text: string, highlight_group: string }
{time_ms} (number) Execution time in milliseconds {time_ms} (number) Execution time in milliseconds
{time_limit_ms} (number) Time limit in milliseconds {time_limit_ms} (number) Time limit in milliseconds
{memory_mb} (number) Peak memory usage in megabytes {memory_mb} (number) Peak memory usage in megabytes
{memory_limit_mb} (number) Memory limit in megabytes {memory_limit_mb} (number) Memory limit in megabytes
{exit_code} (integer) Process exit code {exit_code} (integer) Process exit code
{signal} (string|nil) Signal name for crashes (e.g. "SIGSEGV") {signal} (string|nil) Signal name for crashes (e.g. "SIGSEGV")
{time_actual_width} (integer|nil) Dynamic width for time value alignment
{time_limit_width} (integer|nil) Dynamic width for time limit alignment
{mem_actual_width} (integer|nil) Dynamic width for memory value alignment
{mem_limit_width} (integer|nil) Dynamic width for memory limit alignment
*VerdictFormatResult* *VerdictFormatResult*
{line} (string) The formatted verdict line {line} (string) The formatted verdict line

View file

@ -58,7 +58,6 @@ function M.default_verdict_formatter(data)
local exit_str = data.signal and string.format('%d (%s)', data.exit_code, data.signal) local exit_str = data.signal and string.format('%d (%s)', data.exit_code, data.signal)
or tostring(data.exit_code) or tostring(data.exit_code)
-- Use dynamic widths if provided, otherwise use reasonable defaults
local time_actual_w = data.time_actual_width or 6 local time_actual_w = data.time_actual_width or 6
local time_limit_w = data.time_limit_width or 4 local time_limit_w = data.time_limit_width or 4
local mem_actual_w = data.mem_actual_width or 3 local mem_actual_w = data.mem_actual_width or 3

View file

@ -156,20 +156,15 @@ function M.toggle_edit(test_index)
local test_buffers = {} local test_buffers = {}
local num_tests = #test_cases local num_tests = #test_cases
-- Step 1: Create N columns (vsplit creates full-height columns)
for i = 1, num_tests - 1 do for i = 1, num_tests - 1 do
vim.cmd('vsplit') vim.cmd('vsplit')
end end
-- Step 2: Go to leftmost window
vim.cmd('1wincmd w') vim.cmd('1wincmd w')
-- Step 3: For each column, split horizontally into input (top) and expected (bottom)
for col = 1, num_tests do for col = 1, num_tests do
-- Split current window horizontally
vim.cmd('split') vim.cmd('split')
-- After split, cursor is in bottom window. Go up to input window.
vim.cmd('wincmd k') vim.cmd('wincmd k')
local input_win = vim.api.nvim_get_current_win() local input_win = vim.api.nvim_get_current_win()
local input_buf = utils.create_buffer_with_options() local input_buf = utils.create_buffer_with_options()
@ -180,7 +175,6 @@ function M.toggle_edit(test_index)
vim.bo[input_buf].buflisted = false vim.bo[input_buf].buflisted = false
helpers.clearcol(input_buf) helpers.clearcol(input_buf)
-- Go down to expected window
vim.cmd('wincmd j') vim.cmd('wincmd j')
local expected_win = vim.api.nvim_get_current_win() local expected_win = vim.api.nvim_get_current_win()
local expected_buf = utils.create_buffer_with_options() local expected_buf = utils.create_buffer_with_options()
@ -198,7 +192,6 @@ function M.toggle_edit(test_index)
expected_win = expected_win, expected_win = expected_win,
} }
-- Move to next column (go up to top, then right)
vim.cmd('wincmd k') vim.cmd('wincmd k')
vim.cmd('wincmd l') vim.cmd('wincmd l')
end end

View file

@ -247,6 +247,23 @@ function M.ensure_io_view()
current_test_index = 1, current_test_index = 1,
}) })
local source_buf = vim.api.nvim_win_get_buf(solution_win)
vim.api.nvim_create_autocmd('BufDelete', {
buffer = source_buf,
callback = function()
local io = state.get_io_view_state()
if io then
if io.output_buf and vim.api.nvim_buf_is_valid(io.output_buf) then
vim.api.nvim_buf_delete(io.output_buf, { force = true })
end
if io.input_buf and vim.api.nvim_buf_is_valid(io.input_buf) then
vim.api.nvim_buf_delete(io.input_buf, { force = true })
end
state.set_io_view_state(nil)
end
end,
})
if cfg.hooks and cfg.hooks.setup_io_output then if cfg.hooks and cfg.hooks.setup_io_output then
pcall(cfg.hooks.setup_io_output, output_buf, state) pcall(cfg.hooks.setup_io_output, output_buf, state)
end end