Merge pull request #159 from barrett-ruth/fix/panel-rename
fix: rename run panel to panel
This commit is contained in:
commit
f0edb103ce
9 changed files with 53 additions and 54 deletions
|
|
@ -145,7 +145,7 @@ Here's an example configuration with lazy.nvim:
|
|||
open_url = true,
|
||||
debug = false,
|
||||
ui = {
|
||||
run_panel = {
|
||||
panel = {
|
||||
ansi = true,
|
||||
diff_mode = 'vim',
|
||||
max_output_lines = 50,
|
||||
|
|
@ -210,7 +210,7 @@ run CSES problems with Rust using the single schema:
|
|||
function(contest, contest_id, problem_id, config, language): string
|
||||
Should return full filename with extension.
|
||||
(default: concatenates contest_id and problem_id, lowercased)
|
||||
{ui} (|CpUI|) UI settings: run panel, diff backend, picker.
|
||||
{ui} (|CpUI|) UI settings: panel, diff backend, picker.
|
||||
{open_url} (boolean) Open the contest & problem url in the browser
|
||||
when the contest is first opened.
|
||||
|
||||
|
|
@ -238,11 +238,11 @@ run CSES problems with Rust using the single schema:
|
|||
|
||||
*CpUI*
|
||||
Fields: ~
|
||||
{run_panel} (|RunPanelConfig|) Test panel behavior configuration.
|
||||
{panel} (|PanelConfig|) Test panel behavior configuration.
|
||||
{diff} (|DiffConfig|) Diff backend configuration.
|
||||
{picker} (string|nil) 'telescope', 'fzf-lua', or nil.
|
||||
|
||||
*cp.RunPanelConfig*
|
||||
*cp.PanelConfig*
|
||||
Fields: ~
|
||||
{ansi} (boolean, default: true) Enable ANSI color parsing
|
||||
and highlighting.
|
||||
|
|
@ -367,15 +367,15 @@ PICKER KEYMAPS *cp-picker-keys*
|
|||
Useful when contest lists are outdated or incomplete
|
||||
|
||||
==============================================================================
|
||||
RUN PANEL *cp-run*
|
||||
PANEL *cp-run*
|
||||
|
||||
The run panel provides individual test case debugging. Problem time/memory
|
||||
The panel provides individual test case debugging. Problem time/memory
|
||||
limit constraints are in columns Time/Mem respectively. Used time/memory are
|
||||
in columns Runtime/RSS respectively.
|
||||
|
||||
Interface ~
|
||||
|
||||
The run panel uses the following table layout: >
|
||||
The panel uses the following table layout: >
|
||||
|
||||
┌─────┬────────┬──────────────┬───────────┬──────────┬──────────┬─────────────┐
|
||||
│ # │ Status │ Runtime (ms) │ Time (ms) │ RSS (MB) │ Mem (MB) │ Exit Code │
|
||||
|
|
@ -502,7 +502,7 @@ Customize highlight groups after your colorscheme loads:
|
|||
})
|
||||
|
||||
==============================================================================
|
||||
RUN PANEL KEYMAPS *cp-test-keys*
|
||||
PANEL KEYMAPS *cp-test-keys*
|
||||
|
||||
<c-n> Navigate to next test case
|
||||
<c-p> Navigate to previous test case
|
||||
|
|
|
|||
|
|
@ -109,9 +109,9 @@ function M.handle_command(opts)
|
|||
if cmd.action == 'interact' then
|
||||
ui.toggle_interactive(cmd.interactor_cmd)
|
||||
elseif cmd.action == 'run' then
|
||||
ui.toggle_run_panel()
|
||||
ui.toggle_panel()
|
||||
elseif cmd.action == 'debug' then
|
||||
ui.toggle_run_panel({ debug = true })
|
||||
ui.toggle_panel({ debug = true })
|
||||
elseif cmd.action == 'next' then
|
||||
setup.navigate_problem(1)
|
||||
elseif cmd.action == 'prev' then
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
---@field default_language string
|
||||
---@field overrides? table<string, CpPlatformOverrides>
|
||||
|
||||
---@class RunPanelConfig
|
||||
---@class PanelConfig
|
||||
---@field ansi boolean
|
||||
---@field diff_mode "none"|"vim"|"git"
|
||||
---@field max_output_lines integer
|
||||
|
|
@ -34,7 +34,7 @@
|
|||
---@field setup_code? fun(state: cp.State)
|
||||
|
||||
---@class CpUI
|
||||
---@field run_panel RunPanelConfig
|
||||
---@field panel PanelConfig
|
||||
---@field diff DiffConfig
|
||||
---@field picker string|nil
|
||||
|
||||
|
|
@ -106,7 +106,7 @@ M.defaults = {
|
|||
scrapers = constants.PLATFORMS,
|
||||
filename = nil,
|
||||
ui = {
|
||||
run_panel = { ansi = true, diff_mode = 'none', max_output_lines = 50 },
|
||||
panel = { ansi = true, diff_mode = 'none', max_output_lines = 50 },
|
||||
diff = {
|
||||
git = {
|
||||
args = { 'diff', '--no-index', '--word-diff=plain', '--word-diff-regex=.', '--no-prefix' },
|
||||
|
|
@ -232,16 +232,16 @@ function M.setup(user_config)
|
|||
})
|
||||
|
||||
vim.validate({
|
||||
ansi = { cfg.ui.run_panel.ansi, 'boolean' },
|
||||
ansi = { cfg.ui.panel.ansi, 'boolean' },
|
||||
diff_mode = {
|
||||
cfg.ui.run_panel.diff_mode,
|
||||
cfg.ui.panel.diff_mode,
|
||||
function(v)
|
||||
return vim.tbl_contains({ 'none', 'vim', 'git' }, v)
|
||||
end,
|
||||
"diff_mode must be 'none', 'vim', or 'git'",
|
||||
},
|
||||
max_output_lines = {
|
||||
cfg.ui.run_panel.max_output_lines,
|
||||
cfg.ui.panel.max_output_lines,
|
||||
function(v)
|
||||
return type(v) == 'number' and v > 0 and v == math.floor(v)
|
||||
end,
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ local user_config = {}
|
|||
local config = nil
|
||||
local initialized = false
|
||||
|
||||
--- Root handler for all `:CP ...` commands
|
||||
---@return nil
|
||||
function M.handle_command(opts)
|
||||
local commands = require('cp.commands')
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
---@field timeout_ms number
|
||||
---@field memory_mb number
|
||||
|
||||
---@class RunPanelState
|
||||
---@class PanelState
|
||||
---@field test_cases RanTestCase[]
|
||||
---@field current_index number
|
||||
---@field buffer number?
|
||||
|
|
@ -37,8 +37,8 @@ local execute = require('cp.runner.execute')
|
|||
local logger = require('cp.log')
|
||||
local state = require('cp.state')
|
||||
|
||||
---@type RunPanelState
|
||||
local run_panel_state = {
|
||||
---@type PanelState
|
||||
local panel_state = {
|
||||
test_cases = {},
|
||||
current_index = 1,
|
||||
buffer = nil,
|
||||
|
|
@ -113,8 +113,8 @@ local function run_single_test_case(test_case)
|
|||
local run_template = eff and eff.commands and eff.commands.run or {}
|
||||
local cmd = build_command(run_template, substitutions)
|
||||
local stdin_content = (test_case.input or '') .. '\n'
|
||||
local timeout_ms = (run_panel_state.constraints and run_panel_state.constraints.timeout_ms) or 0
|
||||
local memory_mb = run_panel_state.constraints and run_panel_state.constraints.memory_mb or 0
|
||||
local timeout_ms = (panel_state.constraints and panel_state.constraints.timeout_ms) or 0
|
||||
local memory_mb = panel_state.constraints and panel_state.constraints.memory_mb or 0
|
||||
|
||||
local r = execute.run(cmd, stdin_content, timeout_ms, memory_mb)
|
||||
|
||||
|
|
@ -122,7 +122,7 @@ local function run_single_test_case(test_case)
|
|||
local out = r.stdout or ''
|
||||
local highlights = {}
|
||||
if out ~= '' then
|
||||
if config.ui.run_panel.ansi then
|
||||
if config.ui.panel.ansi then
|
||||
local parsed = ansi.parse_ansi_text(out)
|
||||
out = table.concat(parsed.lines, '\n')
|
||||
highlights = parsed.highlights
|
||||
|
|
@ -131,7 +131,7 @@ local function run_single_test_case(test_case)
|
|||
end
|
||||
end
|
||||
|
||||
local max_lines = config.ui.run_panel.max_output_lines
|
||||
local max_lines = config.ui.panel.max_output_lines
|
||||
local lines = vim.split(out, '\n')
|
||||
if #lines > max_lines then
|
||||
local trimmed = {}
|
||||
|
|
@ -185,9 +185,9 @@ function M.load_test_cases()
|
|||
state.get_problem_id()
|
||||
)
|
||||
|
||||
run_panel_state.test_cases = create_sentinal_panel_data(tcs)
|
||||
run_panel_state.current_index = 1
|
||||
run_panel_state.constraints = load_constraints_from_cache(
|
||||
panel_state.test_cases = create_sentinal_panel_data(tcs)
|
||||
panel_state.current_index = 1
|
||||
panel_state.constraints = load_constraints_from_cache(
|
||||
state.get_platform() or '',
|
||||
state.get_contest_id() or '',
|
||||
state.get_problem_id()
|
||||
|
|
@ -200,7 +200,7 @@ end
|
|||
---@param index number
|
||||
---@return boolean
|
||||
function M.run_test_case(index)
|
||||
local tc = run_panel_state.test_cases[index]
|
||||
local tc = panel_state.test_cases[index]
|
||||
if not tc then
|
||||
return false
|
||||
end
|
||||
|
|
@ -227,16 +227,16 @@ end
|
|||
---@return RanTestCase[]
|
||||
function M.run_all_test_cases()
|
||||
local results = {}
|
||||
for i = 1, #run_panel_state.test_cases do
|
||||
for i = 1, #panel_state.test_cases do
|
||||
M.run_test_case(i)
|
||||
results[i] = run_panel_state.test_cases[i]
|
||||
results[i] = panel_state.test_cases[i]
|
||||
end
|
||||
return results
|
||||
end
|
||||
|
||||
---@return RunPanelState
|
||||
function M.get_run_panel_state()
|
||||
return run_panel_state
|
||||
---@return PanelState
|
||||
function M.get_panel_state()
|
||||
return panel_state
|
||||
end
|
||||
|
||||
---@param output string|nil
|
||||
|
|
@ -247,7 +247,7 @@ function M.handle_compilation_failure(output)
|
|||
local txt
|
||||
local hl = {}
|
||||
|
||||
if config.ui.run_panel.ansi then
|
||||
if config.ui.panel.ansi then
|
||||
local p = ansi.parse_ansi_text(output or '')
|
||||
txt = table.concat(p.lines, '\n')
|
||||
hl = p.highlights
|
||||
|
|
@ -255,7 +255,7 @@ function M.handle_compilation_failure(output)
|
|||
txt = (output or ''):gsub('\027%[[%d;]*[a-zA-Z]', '')
|
||||
end
|
||||
|
||||
for _, tc in ipairs(run_panel_state.test_cases) do
|
||||
for _, tc in ipairs(panel_state.test_cases) do
|
||||
tc.status = 'fail'
|
||||
tc.actual = txt
|
||||
tc.actual_highlights = hl
|
||||
|
|
|
|||
|
|
@ -275,7 +275,7 @@ local function data_row(c, idx, tc, is_current, test_state)
|
|||
return line, hi
|
||||
end
|
||||
|
||||
---@param test_state RunPanelState
|
||||
---@param test_state PanelState
|
||||
---@return string[], Highlight[] lines and highlight positions
|
||||
function M.render_test_list(test_state)
|
||||
local lines, highlights = {}, {}
|
||||
|
|
|
|||
|
|
@ -164,7 +164,7 @@ function M.update_diff_panes(
|
|||
config,
|
||||
setup_keybindings_for_buffer
|
||||
)
|
||||
local test_state = run.get_run_panel_state()
|
||||
local test_state = run.get_panel_state()
|
||||
local current_test = test_state.test_cases[test_state.current_index]
|
||||
|
||||
if not current_test then
|
||||
|
|
@ -185,7 +185,7 @@ function M.update_diff_panes(
|
|||
actual_content = actual_content
|
||||
end
|
||||
|
||||
local desired_mode = is_compilation_failure and 'single' or config.ui.run_panel.diff_mode
|
||||
local desired_mode = is_compilation_failure and 'single' or config.ui.panel.diff_mode
|
||||
local highlight = require('cp.ui.highlight')
|
||||
local diff_namespace = highlight.create_namespace()
|
||||
local ansi_namespace = vim.api.nvim_create_namespace('cp_ansi_highlights')
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
local M = {}
|
||||
|
||||
---@class RunOpts
|
||||
---@class PanelOpts
|
||||
---@field debug? boolean
|
||||
|
||||
local config_module = require('cp.config')
|
||||
|
|
@ -21,7 +21,7 @@ function M.disable()
|
|||
end
|
||||
|
||||
if active_panel == 'run' then
|
||||
M.toggle_run_panel()
|
||||
M.toggle_panel()
|
||||
elseif active_panel == 'interactive' then
|
||||
M.toggle_interactive()
|
||||
else
|
||||
|
|
@ -204,8 +204,8 @@ function M.toggle_interactive(interactor_cmd)
|
|||
state.set_active_panel('interactive')
|
||||
end
|
||||
|
||||
---@param run_opts? RunOpts
|
||||
function M.toggle_run_panel(run_opts)
|
||||
---@param panel_opts? PanelOpts
|
||||
function M.toggle_panel(panel_opts)
|
||||
if state.get_active_panel() == 'run' then
|
||||
if current_diff_layout then
|
||||
current_diff_layout.cleanup()
|
||||
|
|
@ -294,13 +294,13 @@ function M.toggle_run_panel(run_opts)
|
|||
)
|
||||
end
|
||||
|
||||
local function refresh_run_panel()
|
||||
local function refresh_panel()
|
||||
if not test_buffers.tab_buf or not vim.api.nvim_buf_is_valid(test_buffers.tab_buf) then
|
||||
return
|
||||
end
|
||||
local run_render = require('cp.runner.run_render')
|
||||
run_render.setup_highlights()
|
||||
local test_state = run.get_run_panel_state()
|
||||
local test_state = run.get_panel_state()
|
||||
local tab_lines, tab_highlights = run_render.render_test_list(test_state)
|
||||
utils.update_buffer_content(
|
||||
test_buffers.tab_buf,
|
||||
|
|
@ -312,29 +312,29 @@ function M.toggle_run_panel(run_opts)
|
|||
end
|
||||
|
||||
local function navigate_test_case(delta)
|
||||
local test_state = run.get_run_panel_state()
|
||||
local test_state = run.get_panel_state()
|
||||
if vim.tbl_isempty(test_state.test_cases) then
|
||||
return
|
||||
end
|
||||
test_state.current_index = (test_state.current_index + delta - 1) % #test_state.test_cases + 1
|
||||
refresh_run_panel()
|
||||
refresh_panel()
|
||||
end
|
||||
|
||||
setup_keybindings_for_buffer = function(buf)
|
||||
vim.keymap.set('n', 'q', function()
|
||||
M.toggle_run_panel()
|
||||
M.toggle_panel()
|
||||
end, { buffer = buf, silent = true })
|
||||
vim.keymap.set('n', 't', function()
|
||||
local modes = { 'none', 'git', 'vim' }
|
||||
local current_idx = 1
|
||||
for i, mode in ipairs(modes) do
|
||||
if config.ui.run_panel.diff_mode == mode then
|
||||
if config.ui.panel.diff_mode == mode then
|
||||
current_idx = i
|
||||
break
|
||||
end
|
||||
end
|
||||
config.ui.run_panel.diff_mode = modes[(current_idx % #modes) + 1]
|
||||
refresh_run_panel()
|
||||
config.ui.panel.diff_mode = modes[(current_idx % #modes) + 1]
|
||||
refresh_panel()
|
||||
end, { buffer = buf, silent = true })
|
||||
vim.keymap.set('n', '<c-n>', function()
|
||||
navigate_test_case(1)
|
||||
|
|
@ -351,7 +351,7 @@ function M.toggle_run_panel(run_opts)
|
|||
config.hooks.before_run(state)
|
||||
end)
|
||||
end
|
||||
if run_opts and run_opts.debug and config.hooks and config.hooks.before_debug then
|
||||
if panel_opts and panel_opts.debug and config.hooks and config.hooks.before_debug then
|
||||
vim.schedule_wrap(function()
|
||||
config.hooks.before_debug(state)
|
||||
end)
|
||||
|
|
@ -365,10 +365,10 @@ function M.toggle_run_panel(run_opts)
|
|||
run.handle_compilation_failure(compile_result.output)
|
||||
end
|
||||
|
||||
refresh_run_panel()
|
||||
refresh_panel()
|
||||
|
||||
vim.schedule(function()
|
||||
if config.ui.run_panel.ansi then
|
||||
if config.ui.panel.ansi then
|
||||
local ansi = require('cp.ui.ansi')
|
||||
ansi.setup_highlight_groups()
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ describe('run module', function()
|
|||
|
||||
describe('basic functionality', function()
|
||||
it('can get panel state', function()
|
||||
local state = run.get_run_panel_state()
|
||||
local state = run.get_panel_state()
|
||||
assert.is_table(state)
|
||||
assert.is_table(state.test_cases)
|
||||
end)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue