feat: Add support for useing color_name like red and cterm values to set colors in lualine
This commit is contained in:
parent
fd5f635f4f
commit
7a45a4f7fe
|
@ -15,6 +15,7 @@ lualine theme at lua/lualine/themes/{your_colorscheme}.lua in you repo.
|
|||
<summary><b>theme example</b></summary>
|
||||
|
||||
To create a custom theme you need to define a colorscheme for each of vim's modes. Each mode has a `fg` and `bg` field for every lualine section.
|
||||
To specify colors you can use #rrggbb/color_name(like: red)/cterm_color(0-255).
|
||||
You can add special effects with `gui`.
|
||||
|
||||
Though the example shows a,b,c being set you can specify theme for x, y, z too.
|
||||
|
|
|
@ -6,7 +6,23 @@ local utils = require 'lualine.utils.utils'
|
|||
local section_highlight_map = {x = 'c', y = 'b', z = 'a'}
|
||||
local active_theme = nil
|
||||
|
||||
local function sanitize_color(color)
|
||||
if type(color) == 'string' then
|
||||
if color:sub(1,1) == '#' then return color end -- RGB value
|
||||
local converter = require 'lualine.utils.cterm_colors'
|
||||
return converter.color_name2rgb(color)
|
||||
elseif type(color) == 'number' then
|
||||
if color > 255 then
|
||||
error("What's this it can't be higher then 255 and you've given "..color)
|
||||
end
|
||||
local converter = require 'lualine.utils.cterm_colors'
|
||||
return converter.cterm2rgb(color)
|
||||
end
|
||||
end
|
||||
|
||||
function M.highlight(name, foreground, background, gui, reload)
|
||||
foreground = sanitize_color(foreground)
|
||||
background = sanitize_color(background)
|
||||
local command = {'highlight', name}
|
||||
if foreground and foreground ~= 'none' then
|
||||
table.insert(command, 'guifg=' .. foreground)
|
||||
|
|
|
@ -300,4 +300,20 @@ function M.get_cterm_color(hex_color)
|
|||
return closest_cterm_color
|
||||
end
|
||||
|
||||
function M.color_name2rgb(name)
|
||||
local color_val = vim.api.nvim_get_color_by_name(name)
|
||||
if color_val == -1 then
|
||||
return '#'..name -- Assuming it's 'rrggbb' without # not rad instead of red
|
||||
end
|
||||
return string.format('#%06x', color_val)
|
||||
end
|
||||
|
||||
function M.cterm2rgb(color)
|
||||
local color_data = color_table[color + 1]
|
||||
if color_data ~= nil then
|
||||
color_data = color_data[2]
|
||||
return string.format("#%02x%02x%02x", color_data[1], color_data[2], color_data[3])
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
Loading…
Reference in New Issue