2021-02-17 18:29:50 +00:00
|
|
|
-- Copyright (c) 2020-2021 shadmansaleh
|
2021-02-13 00:03:57 +00:00
|
|
|
-- MIT license, see LICENSE for more details.
|
|
|
|
|
2021-02-17 18:29:50 +00:00
|
|
|
local utils = require'lualine.utils.utils'
|
|
|
|
local highlight = require"lualine.highlight"
|
|
|
|
|
|
|
|
local default_color_added = "#f0e130"
|
|
|
|
local default_color_removed = "#90ee90"
|
|
|
|
local default_color_modified = "#ff0038"
|
|
|
|
|
|
|
|
local function signify(options)
|
|
|
|
if options.colored == nil then options.colored = true end
|
|
|
|
-- apply colors
|
|
|
|
if not options.color_added then
|
2021-02-20 03:21:05 +00:00
|
|
|
options.color_added = utils.extract_highlight_colors('diffAdded', 'guifg') or default_color_added
|
2021-02-17 18:29:50 +00:00
|
|
|
end
|
|
|
|
if not options.color_modified then
|
2021-02-20 03:21:05 +00:00
|
|
|
options.color_modified = utils.extract_highlight_colors('diffChanged', 'guifg') or default_color_modified
|
2021-02-17 18:29:50 +00:00
|
|
|
end
|
|
|
|
if not options.color_removed then
|
2021-02-20 03:21:05 +00:00
|
|
|
options.color_removed = utils.extract_highlight_colors('diffRemoved', 'guifg') or default_color_removed
|
2021-02-17 18:29:50 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local highlights = {}
|
|
|
|
|
|
|
|
-- create highlights and save highlight_name in highlights table
|
|
|
|
local function create_highlights()
|
|
|
|
highlights = {
|
|
|
|
highlight.create_component_highlight_group({fg = options.color_added}, 'signify_added', options),
|
|
|
|
highlight.create_component_highlight_group({fg = options.color_modified}, 'signify_modified', options),
|
|
|
|
highlight.create_component_highlight_group({fg = options.color_removed}, 'signify_removed', options),
|
|
|
|
}
|
|
|
|
end
|
2021-01-03 23:37:49 +00:00
|
|
|
|
2021-02-17 18:29:50 +00:00
|
|
|
-- create highlights
|
|
|
|
if options.colored then
|
|
|
|
create_highlights()
|
|
|
|
utils.expand_set_theme(create_highlights)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Function that runs everytime statusline is updated
|
|
|
|
return function()
|
|
|
|
-- check if signify is available
|
|
|
|
if vim.fn.exists('*sy#repo#get_stats') == 0 then return '' end
|
|
|
|
local data = vim.fn['sy#repo#get_stats']()
|
|
|
|
if data[1] == -1 then return '' end
|
|
|
|
|
|
|
|
local symbols = {'+', '~', '-'}
|
|
|
|
local colors = {}
|
|
|
|
if options.colored then
|
|
|
|
-- load the highlights and store them in colors table
|
|
|
|
for _, highlight_name in ipairs(highlights) do
|
|
|
|
table.insert(colors, highlight.component_format_highlight(highlight_name))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local result = {}
|
|
|
|
-- loop though data and load available sections in result table
|
|
|
|
for range=1,3 do
|
|
|
|
if data[range] ~= nil and data[range] > 0 then
|
|
|
|
if options.colored then
|
|
|
|
table.insert(result,colors[range]..symbols[range]..data[range])
|
|
|
|
else
|
|
|
|
table.insert(result,symbols[range]..data[range])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if result[1] ~= nil then
|
|
|
|
return table.concat(result, ' ')
|
|
|
|
else
|
|
|
|
return ''
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-02-04 21:12:35 +00:00
|
|
|
|
2021-02-17 18:29:50 +00:00
|
|
|
return { init = function(options) return signify(options) end }
|