feat: add colors to signify (#61)

Co-authored-by: hoob3rt <pelczarskihubert@gmail.com>
This commit is contained in:
Shadman 2021-02-18 00:29:50 +06:00 committed by GitHub
parent ec55986f3e
commit 0dd0a23cac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 107 additions and 33 deletions

View File

@ -244,6 +244,17 @@ Default options act as default for all components
- fileformat
- icons_enabled (true)\
Whether to displays icon before component
- signify
- colored (true)\
Whether to show colors. Colors are automaticaly
extracted from colorscheme . If you want to change
any of those you can use options given below.
- color_added ('#90ee90')\
Foreground color of added section
- color_modified ('#f0e130')\
Foreground color of modified section
- color_removed ('#ff0038')\
Foreground color of removed section
**Example:**
```lua

View File

@ -1,5 +1,4 @@
*lualine.txt*
*lualine* *lualine.nvim*
lualine.txt *lualine-nvim* *lualine*
Author: hoob3rt (https://github.com/hoob3rt)
License: MIT License
@ -279,7 +278,23 @@ List of options are given below.
• fileformat~
• icons_enabled (true)
Whether to displays icon before component
Whether to displays icon before component. Colors
are automaticaly extracted from colorscheme . If you
want to change any of those you can use options given below.
• signify~
• colored (true)
Whether to show colors
• color_added ('#90ee90')
Foreground color of added section
• color_modified ('#f0e130')
Foreground color of modified section
• color_removed ('#ff0038')
Foreground color of removed section
Example:~
>

View File

@ -18,6 +18,4 @@ lualine-setting_a_theme lualine.txt /*lualine-setting_a_theme*
lualine-starting_lualine lualine.txt /*lualine-starting_lualine*
lualine-usage_and_customization lualine.txt /*lualine-usage_and_customization*
lualine-vim-plug lualine.txt /*lualine-vim-plug*
lualine.nvim lualine.txt /*lualine.nvim*
lualine.txt lualine.txt /*lualine.txt*
lualline-contents lualine.txt /*lualline-contents*

View File

@ -1,33 +1,77 @@
-- Copyright (c) 2020-2021 hoob3rt
-- Copyright (c) 2020-2021 shadmansaleh
-- MIT license, see LICENSE for more details.
local function signify()
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
options.color_added = utils.extract_highlight_colors('diffAdded', 'foreground') or default_color_added
end
if not options.color_modified then
options.color_modified = utils.extract_highlight_colors('diffChanged', 'foreground') or default_color_modified
end
if not options.color_removed then
options.color_removed = utils.extract_highlight_colors('diffRemoved', 'foreground') or default_color_removed
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
-- create highlights
if options.colored then
create_highlights()
utils.expand_set_theme(create_highlights)
options.custom_highlight = true
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 added, modified, removed = unpack(vim.fn['sy#repo#get_stats']())
if added == -1 then return '' end
local symbols = {
'+',
'-',
'~',
}
local result = {}
local data = {
added,
removed,
modified,
}
for range=1,3 do
if data[range] ~= nil and data[range] > 0
then table.insert(result,symbols[range]..''..data[range]..' ')
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, '')
return table.concat(result, ' ')
else
return ''
end
end
end
return signify
return { init = function(options) return signify(options) end }

View File

@ -14,4 +14,10 @@ function M.expand_set_theme(func)
end
end
-- Note for now only works for termguicolors scope can be background or foreground
function M.extract_highlight_colors(color_group, scope)
local color = string.format('#%06x', vim.api.nvim_get_hl_by_name(color_group, true)[scope])
return color or nil
end
return M