From 05f850d25f4b0c07a5c05ab41db2bd185c23f517 Mon Sep 17 00:00:00 2001 From: Antoine Cotten Date: Sat, 10 Sep 2022 13:42:14 +0200 Subject: [PATCH] feat(utils): support extracting 'sp' scope hl color --- lua/lualine/highlight.lua | 1 + lua/lualine/utils/utils.lua | 6 +++++- tests/spec/utils_spec.lua | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lua/lualine/highlight.lua b/lua/lualine/highlight.lua index 20764b5..f297d8b 100644 --- a/lua/lualine/highlight.lua +++ b/lua/lualine/highlight.lua @@ -78,6 +78,7 @@ function M.get_lualine_hl(name) local hl_def = { fg = hl.fg ~= 'None' and vim.deepcopy(hl.fg) or nil, bg = hl.bg ~= 'None' and vim.deepcopy(hl.bg) or nil, + sp = hl.sp ~= 'None' and vim.deepcopy(hl.sp) or nil, } if hl.gui then for _, flag in ipairs(vim.split(hl.gui, ',')) do diff --git a/lua/lualine/utils/utils.lua b/lua/lualine/utils/utils.lua index bc28b43..82b9af2 100644 --- a/lua/lualine/utils/utils.lua +++ b/lua/lualine/utils/utils.lua @@ -5,7 +5,7 @@ local M = {} -- Note for now only works for termguicolors scope can be bg or fg or any other -- attr parameter like bold/italic/reverse ---@param color_group string hl_group name ----@param scope string bg | fg +---@param scope string bg | fg | sp ---@return table|string returns #rrggbb formatted color when scope is specified ---- or complete color table when scope isn't specified function M.extract_highlight_colors(color_group, scope) @@ -23,6 +23,10 @@ function M.extract_highlight_colors(color_group, scope) color.fg = string.format('#%06x', color.foreground) color.foreground = nil end + if color.special ~= nil then + color.sp = string.format('#%06x', color.special) + color.special = nil + end end if scope then return color[scope] diff --git a/tests/spec/utils_spec.lua b/tests/spec/utils_spec.lua index 59af60c..c62ae82 100644 --- a/tests/spec/utils_spec.lua +++ b/tests/spec/utils_spec.lua @@ -11,11 +11,11 @@ describe('Utils', function() local utils = require('lualine.utils.utils') it('can retrive highlight groups', function() - local hl2 = { fg = '#aabbcc', bg = '#889977', reverse = true } + local hl2 = { fg = '#aabbcc', bg = '#889977', sp = '#997788', reverse = true, undercurl = true } -- handles non existing hl groups eq(utils.extract_highlight_colors('hl2'), nil) -- create highlight - vim.cmd(string.format('hi hl2 guifg=%s guibg=%s gui=reverse', hl2.fg, hl2.bg)) + vim.cmd(string.format('hi hl2 guifg=%s guibg=%s guisp=%s gui=reverse,undercurl', hl2.fg, hl2.bg, hl2.sp)) -- Can retrieve entire highlight table eq(utils.extract_highlight_colors('hl2'), hl2) -- Can retrieve specific parts of highlight