feat: enable to set symbols for diff component (#116)
Changes logic to store diffs in `git_diff` because the original has stored them in a list: ``` {1, 2, 3} => {added = 1, modified = 2, removed = 3} ```
This commit is contained in:
parent
8c8a489612
commit
e4723362c4
|
@ -246,6 +246,7 @@ colored | true | displays diff status in color if set to `true` |
|
||||||
color_added | `DiffAdd` foreground color | changes diff's added section foreground color | color in `#rrggbb` format
|
color_added | `DiffAdd` foreground color | changes diff's added section foreground color | color in `#rrggbb` format
|
||||||
color_modified | `DiffChange` foreground color | changes diff's changed section foreground color | color in `#rrggbb` format
|
color_modified | `DiffChange` foreground color | changes diff's changed section foreground color | color in `#rrggbb` format
|
||||||
color_removed | `DiffDelete` foreground color | changes diff's removed section foreground color | color in `#rrggbb` format
|
color_removed | `DiffDelete` foreground color | changes diff's removed section foreground color | color in `#rrggbb` format
|
||||||
|
symbols | `{added = '+', modified = '~', removed = '-'}` | changes diff's symbols | table containing on or more symbols |
|
||||||
|
|
||||||
|
|
||||||
##### Component options example
|
##### Component options example
|
||||||
|
|
|
@ -332,12 +332,28 @@ List of options are given below.
|
||||||
|
|
||||||
• color_added (DiffAdd foreground color)
|
• color_added (DiffAdd foreground color)
|
||||||
Foreground color of added section
|
Foreground color of added section
|
||||||
|
Color in #rrggbb format
|
||||||
|
|
||||||
• color_modified (DiffChange foreground color)
|
• color_modified (DiffChange foreground color)
|
||||||
Foreground color of modified section
|
Foreground color of modified section
|
||||||
|
Color in #rrggbb format
|
||||||
|
|
||||||
• color_removed (DiffDelete foreground color)
|
• color_removed (DiffDelete foreground color)
|
||||||
Foreground color of removed section
|
Foreground color of removed section
|
||||||
|
Color in #rrggbb format
|
||||||
|
|
||||||
|
• symbols ({added = '+', modified = '~', removed = '-'})
|
||||||
|
Changes diff's symbol characters. You can set some symbols partly.
|
||||||
|
Color in #rrggbb format
|
||||||
|
>
|
||||||
|
{
|
||||||
|
'diff',
|
||||||
|
-- set the added symbol and use defaults for modified and removed.
|
||||||
|
symbols = {
|
||||||
|
added = 'A',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
<
|
||||||
|
|
||||||
Example:~
|
Example:~
|
||||||
>
|
>
|
||||||
|
|
|
@ -34,7 +34,7 @@ local function process_diff(data)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
git_diff = { added, modified, removed }
|
git_diff = { added = added, modified = modified, removed = removed }
|
||||||
end
|
end
|
||||||
|
|
||||||
-- variable to store git_diff getter async function
|
-- variable to store git_diff getter async function
|
||||||
|
@ -64,7 +64,7 @@ local function update_git_diff_getter()
|
||||||
if diff_data ~= '' then
|
if diff_data ~= '' then
|
||||||
process_diff(diff_data)
|
process_diff(diff_data)
|
||||||
else
|
else
|
||||||
git_diff = {0, 0, 0}
|
git_diff = { added = 0, modified = 0, removed = 0}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
@ -102,9 +102,9 @@ local function diff(options)
|
||||||
-- create highlights and save highlight_name in highlights table
|
-- create highlights and save highlight_name in highlights table
|
||||||
local function create_highlights()
|
local function create_highlights()
|
||||||
highlights = {
|
highlights = {
|
||||||
highlight.create_component_highlight_group({fg = options.color_added}, 'diff_added', options),
|
added = highlight.create_component_highlight_group({fg = options.color_added}, 'diff_added', options),
|
||||||
highlight.create_component_highlight_group({fg = options.color_modified}, 'diff_modified', options),
|
modified = highlight.create_component_highlight_group({fg = options.color_modified}, 'diff_modified', options),
|
||||||
highlight.create_component_highlight_group({fg = options.color_removed}, 'diff_removed', options),
|
removed = highlight.create_component_highlight_group({fg = options.color_removed}, 'diff_removed', options),
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -124,27 +124,32 @@ local function diff(options)
|
||||||
return function()
|
return function()
|
||||||
if git_diff == nil then return '' end
|
if git_diff == nil then return '' end
|
||||||
|
|
||||||
local symbols = {'+', '~', '-'}
|
local default_symbols = {
|
||||||
|
added = '+',
|
||||||
|
modified = '~',
|
||||||
|
removed = '-',
|
||||||
|
}
|
||||||
|
options.symbols = vim.tbl_extend('force', default_symbols, options.symbols or {})
|
||||||
local colors = {}
|
local colors = {}
|
||||||
if options.colored then
|
if options.colored then
|
||||||
-- load the highlights and store them in colors table
|
-- load the highlights and store them in colors table
|
||||||
for _, highlight_name in ipairs(highlights) do
|
for name, highlight_name in pairs(highlights) do
|
||||||
table.insert(colors, highlight.component_format_highlight(highlight_name))
|
colors[name] = highlight.component_format_highlight(highlight_name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local result = {}
|
local result = {}
|
||||||
-- loop though data and load available sections in result table
|
-- loop though data and load available sections in result table
|
||||||
for range=1,3 do
|
for _, name in ipairs{'added', 'modified', 'removed'} do
|
||||||
if git_diff[range] ~= nil and git_diff[range] > 0 then
|
if git_diff[name] and git_diff[name] > 0 then
|
||||||
if options.colored then
|
if options.colored then
|
||||||
table.insert(result,colors[range]..symbols[range]..git_diff[range])
|
table.insert(result,colors[name]..options.symbols[name]..git_diff[name])
|
||||||
else
|
else
|
||||||
table.insert(result,symbols[range]..git_diff[range])
|
table.insert(result,options.symbols[name]..git_diff[name])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if result[1] ~= nil then
|
if #result > 0 then
|
||||||
return table.concat(result, ' ')
|
return table.concat(result, ' ')
|
||||||
else
|
else
|
||||||
return ''
|
return ''
|
||||||
|
@ -159,18 +164,11 @@ end
|
||||||
-- modified = modified_count,
|
-- modified = modified_count,
|
||||||
-- removed = removed_count,
|
-- removed = removed_count,
|
||||||
-- }
|
-- }
|
||||||
-- error_code = { -1, -1, -1 }
|
-- error_code = { added = -1, modified = -1, removed = -1 }
|
||||||
local function get_sign_count()
|
local function get_sign_count()
|
||||||
update_git_diff_getter()
|
update_git_diff_getter()
|
||||||
update_git_diff()
|
update_git_diff()
|
||||||
if git_diff then
|
return git_diff or { added = -1, modified = -1, removed = -1 }
|
||||||
return{
|
|
||||||
added = git_diff[1],
|
|
||||||
modified = git_diff[2],
|
|
||||||
removed = git_diff[3]
|
|
||||||
}
|
|
||||||
end
|
|
||||||
return {-1, -1, -1}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
Loading…
Reference in New Issue