fix(ci): default to builtin Diff<> hl groups for diff panel
This commit is contained in:
parent
cae0ea1914
commit
5309cd0596
2 changed files with 101 additions and 105 deletions
115
doc/cp.txt
115
doc/cp.txt
|
|
@ -380,7 +380,7 @@ Example: Setting up and solving AtCoder contest ABC324
|
|||
|
||||
7. Continue solving problems with :CP next/:CP prev navigation
|
||||
|
||||
8. Switch to another file (e.g., previous contest): >
|
||||
8. Switch to another file (e.g. previous contest): >
|
||||
:e ~/contests/abc323/a.cpp
|
||||
:CP
|
||||
< Automatically restores abc323 contest context
|
||||
|
|
@ -421,9 +421,9 @@ The run panel uses the following table layout: >
|
|||
└─────┴────────┴──────────────┴───────────┴──────────┴─────────────┘
|
||||
┌──────────────────────────────────────────────────────────────────┐
|
||||
│Expected vs Actual │
|
||||
│4[-2-]{+3+} │
|
||||
│423 │
|
||||
│100 │
|
||||
│hello w[-o-]r{+o+}ld │
|
||||
│hello world │
|
||||
└──────────────────────────────────────────────────────────────────┘
|
||||
|
||||
Status Indicators ~
|
||||
|
|
@ -434,101 +434,6 @@ Test cases use competitive programming terminology with color highlighting:
|
|||
WA Wrong Answer (output mismatch) - Red
|
||||
TLE Time Limit Exceeded (timeout) - Orange
|
||||
RTE Runtime Error (non-zero exit) - Purple
|
||||
|
||||
Highlight Groups ~
|
||||
*cp-highlights*
|
||||
cp.nvim defines comprehensive highlight groups for test status, ANSI colors,
|
||||
and diff visualization.
|
||||
|
||||
Test Status Groups ~
|
||||
|
||||
CpTestAC Green foreground for AC status
|
||||
CpTestWA Red foreground for WA status
|
||||
CpTestTLE Orange foreground for TLE status
|
||||
CpTestRTE Purple foreground for RTE status
|
||||
CpTestPending Gray foreground for pending tests
|
||||
|
||||
ANSI Color Support ~
|
||||
*cp-ansi-colors*
|
||||
cp.nvim preserves ANSI colors from compiler output and program stderr using
|
||||
a sophisticated parsing system. Colors are automatically mapped to your
|
||||
terminal colorscheme via vim.g.terminal_color_* variables.
|
||||
|
||||
ANSI Highlight Groups:
|
||||
|
||||
CpAnsiBold Bold text formatting
|
||||
CpAnsiItalic Italic text formatting
|
||||
CpAnsiBoldItalic Combined bold and italic formatting
|
||||
|
||||
Color combinations (16 standard terminal colors):
|
||||
CpAnsiRed Standard red (terminal_color_1)
|
||||
CpAnsiBoldRed Bold red combination
|
||||
CpAnsiItalicRed Italic red combination
|
||||
CpAnsiBoldItalicRed Bold italic red combination
|
||||
|
||||
CpAnsiGreen Standard green (terminal_color_2)
|
||||
CpAnsiYellow Standard yellow (terminal_color_3)
|
||||
CpAnsiBlue Standard blue (terminal_color_4)
|
||||
CpAnsiMagenta Standard magenta (terminal_color_5)
|
||||
CpAnsiCyan Standard cyan (terminal_color_6)
|
||||
CpAnsiWhite Standard white (terminal_color_7)
|
||||
CpAnsiBlack Standard black (terminal_color_0)
|
||||
|
||||
Bright color variants:
|
||||
CpAnsiBrightRed Bright red (terminal_color_9)
|
||||
CpAnsiBrightGreen Bright green (terminal_color_10)
|
||||
CpAnsiBrightYellow Bright yellow (terminal_color_11)
|
||||
CpAnsiBrightBlue Bright blue (terminal_color_12)
|
||||
CpAnsiBrightMagenta Bright magenta (terminal_color_13)
|
||||
CpAnsiBrightCyan Bright cyan (terminal_color_14)
|
||||
CpAnsiBrightWhite Bright white (terminal_color_15)
|
||||
CpAnsiBrightBlack Bright black (terminal_color_8)
|
||||
|
||||
Each color supports Bold, Italic, and BoldItalic variants automatically.
|
||||
|
||||
Diff Highlight Groups ~
|
||||
|
||||
CpDiffAdded Green background for added text in diffs
|
||||
CpDiffRemoved Red background for removed text in diffs
|
||||
|
||||
Terminal Color Integration ~
|
||||
*cp-terminal-colors*
|
||||
ANSI colors automatically use your terminal's color palette through Neovim's
|
||||
vim.g.terminal_color_* variables. This ensures compiler colors match your
|
||||
colorscheme without manual configuration.
|
||||
|
||||
If your colorscheme doesn't set terminal colors, cp.nvim falls back to
|
||||
sensible defaults. You can override terminal colors in your configuration: >vim
|
||||
let g:terminal_color_1 = '#ff6b6b' " Custom red
|
||||
let g:terminal_color_2 = '#51cf66' " Custom green
|
||||
<
|
||||
|
||||
Highlight Customization ~
|
||||
*cp-highlight-custom*
|
||||
You can customize any highlight group by linking to existing groups or
|
||||
defining custom colors: >lua
|
||||
-- Link to existing colorscheme groups
|
||||
vim.api.nvim_set_hl(0, 'CpTestAC', { link = 'DiffAdd' })
|
||||
vim.api.nvim_set_hl(0, 'CpTestWA', { link = 'DiagnosticError' })
|
||||
|
||||
-- Define custom colors
|
||||
vim.api.nvim_set_hl(0, 'CpTestTLE', { fg = '#ffa500', bold = true })
|
||||
vim.api.nvim_set_hl(0, 'CpDiffAdded', { fg = '#10b981', bg = '#1e293b' })
|
||||
|
||||
-- Customize ANSI colors while preserving terminal integration
|
||||
vim.api.nvim_set_hl(0, 'CpAnsiRed', {
|
||||
fg = vim.g.terminal_color_1 or '#ef4444'
|
||||
})
|
||||
<
|
||||
|
||||
Place customizations in your init.lua or after the colorscheme loads to
|
||||
prevent them from being overridden: >lua
|
||||
vim.api.nvim_create_autocmd('ColorScheme', {
|
||||
callback = function()
|
||||
-- Your cp.nvim highlight customizations here
|
||||
vim.api.nvim_set_hl(0, 'CpTestAC', { link = 'String' })
|
||||
end
|
||||
})
|
||||
<
|
||||
|
||||
==============================================================================
|
||||
|
|
@ -586,10 +491,16 @@ Example combinations:
|
|||
CpAnsiItalicGreen Italic green combination
|
||||
CpAnsiBoldItalicYellow Bold italic yellow combination
|
||||
|
||||
Diff Highlight Groups ~
|
||||
Diff Highlighting ~
|
||||
|
||||
CpDiffAdded Green background for added text in diffs
|
||||
CpDiffRemoved Red background for removed text in diffs
|
||||
Diff visualization uses Neovim's built-in highlight groups that automatically
|
||||
adapt to your colorscheme:
|
||||
|
||||
DiffAdd Highlights added text in git diffs
|
||||
DiffDelete Highlights removed text in git diffs
|
||||
|
||||
These groups are automatically used by the git diff backend for character-level
|
||||
difference visualization with optimal colorscheme integration.
|
||||
|
||||
==============================================================================
|
||||
TERMINAL COLOR INTEGRATION *cp-terminal-colors*
|
||||
|
|
@ -615,7 +526,7 @@ defining custom colors: >lua
|
|||
|
||||
-- Define custom colors
|
||||
vim.api.nvim_set_hl(0, 'CpTestTLE', { fg = '#ffa500', bold = true })
|
||||
vim.api.nvim_set_hl(0, 'CpDiffAdded', { fg = '#10b981', bg = '#1e293b' })
|
||||
vim.api.nvim_set_hl(0, 'DiffAdd', { fg = '#10b981', bg = '#1e293b' })
|
||||
|
||||
-- Customize ANSI colors while preserving terminal integration
|
||||
vim.api.nvim_set_hl(0, 'CpAnsiRed', {
|
||||
|
|
|
|||
|
|
@ -58,10 +58,95 @@ local git_backend = {
|
|||
highlights = {},
|
||||
}
|
||||
else
|
||||
-- Parse git diff output to extract content and highlights
|
||||
local diff_content = result.stdout or ''
|
||||
local lines = {}
|
||||
local highlights = {}
|
||||
local line_num = 0
|
||||
|
||||
-- Extract content lines that start with space, +, or -
|
||||
for line in diff_content:gmatch('[^\n]*') do
|
||||
if
|
||||
line:match('^[%s%+%-]')
|
||||
or (not line:match('^[@%-+]') and not line:match('^index') and not line:match('^diff'))
|
||||
then
|
||||
-- This is content, not metadata
|
||||
local clean_line = line
|
||||
if line:match('^[%+%-]') then
|
||||
clean_line = line:sub(2) -- Remove +/- prefix
|
||||
end
|
||||
|
||||
-- Parse diff markers in the line
|
||||
local col_pos = 0
|
||||
local processed_line = ''
|
||||
local i = 1
|
||||
|
||||
while i <= #clean_line do
|
||||
local removed_start, removed_end = clean_line:find('%[%-[^%-]*%-]', i)
|
||||
local added_start, added_end = clean_line:find('{%+[^%+]*%+}', i)
|
||||
|
||||
local next_marker_start = nil
|
||||
local marker_type = nil
|
||||
|
||||
if removed_start and (not added_start or removed_start < added_start) then
|
||||
next_marker_start = removed_start
|
||||
marker_type = 'removed'
|
||||
elseif added_start then
|
||||
next_marker_start = added_start
|
||||
marker_type = 'added'
|
||||
end
|
||||
|
||||
if next_marker_start then
|
||||
-- Add text before marker
|
||||
if next_marker_start > i then
|
||||
local before_text = clean_line:sub(i, next_marker_start - 1)
|
||||
processed_line = processed_line .. before_text
|
||||
col_pos = col_pos + #before_text
|
||||
end
|
||||
|
||||
-- Extract and add marker content with highlighting
|
||||
local marker_end = (marker_type == 'removed') and removed_end or added_end
|
||||
local marker_text = clean_line:sub(next_marker_start, marker_end)
|
||||
local content_text
|
||||
|
||||
if marker_type == 'removed' then
|
||||
content_text = marker_text:sub(3, -3) -- Remove [- and -]
|
||||
table.insert(highlights, {
|
||||
line = line_num,
|
||||
col_start = col_pos,
|
||||
col_end = col_pos + #content_text,
|
||||
highlight_group = 'DiffDelete',
|
||||
})
|
||||
else -- added
|
||||
content_text = marker_text:sub(3, -3) -- Remove {+ and +}
|
||||
table.insert(highlights, {
|
||||
line = line_num,
|
||||
col_start = col_pos,
|
||||
col_end = col_pos + #content_text,
|
||||
highlight_group = 'DiffAdd',
|
||||
})
|
||||
end
|
||||
|
||||
processed_line = processed_line .. content_text
|
||||
col_pos = col_pos + #content_text
|
||||
i = marker_end + 1
|
||||
else
|
||||
-- No more markers, add rest of line
|
||||
local rest = clean_line:sub(i)
|
||||
processed_line = processed_line .. rest
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
table.insert(lines, processed_line)
|
||||
line_num = line_num + 1
|
||||
end
|
||||
end
|
||||
|
||||
return {
|
||||
content = {},
|
||||
highlights = {},
|
||||
raw_diff = result.stdout or '',
|
||||
content = lines,
|
||||
highlights = highlights,
|
||||
raw_diff = diff_content,
|
||||
}
|
||||
end
|
||||
end,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue