@@ -76,6 +76,19 @@ local function sanitize_color(color)
7676 end
7777end
7878
79+ --- converts color_name type colors to cterm format and let cterm color pass through
80+ --- @param color string | number
81+ --- @return string
82+ local function sanitize_color_for_cterm (color )
83+ if type (color ) == ' number' then
84+ if color > 255 then
85+ error (" What's this it can't be higher then 255 and you've given " .. color )
86+ end
87+ return color
88+ end
89+ return modules .color_utils .rgb2cterm (sanitize_color (color ))
90+ end
91+
7992function M .get_lualine_hl (name )
8093 local hl = loaded_highlights [name ]
8194 if hl and not hl .empty then
@@ -113,24 +126,25 @@ function M.highlight(name, foreground, background, gui, link)
113126 end
114127 vim .list_extend (command , { ' link' , name , link })
115128 else
116- foreground = sanitize_color (foreground )
117- background = sanitize_color (background )
129+ local foreground_rgb = sanitize_color (foreground )
130+ local background_rgb = sanitize_color (background )
118131 gui = (gui ~= nil and gui ~= ' ' ) and gui or ' None'
119132 if
120133 loaded_highlights [name ]
121- and loaded_highlights [name ].fg == foreground
122- and loaded_highlights [name ].bg == background
134+ and loaded_highlights [name ].fg == foreground_rgb
135+ and loaded_highlights [name ].bg == background_rgb
123136 and loaded_highlights [name ].gui == gui
124137 then
125138 return -- color is already defined why are we doing this anyway ?
126139 end
127140 table.insert (command , name )
128- table.insert (command , ' guifg=' .. foreground )
129- table.insert (command , ' guibg=' .. background )
141+ table.insert (command , ' guifg=' .. foreground_rgb )
142+ table.insert (command , ' guibg=' .. background_rgb )
130143 table.insert (command , ' gui=' .. gui )
131144 if create_cterm_colors then
132- table.insert (command , ' ctermfg=' .. modules .color_utils .rgb2cterm (foreground ))
133- table.insert (command , ' ctermbg=' .. modules .color_utils .rgb2cterm (background ))
145+ -- Not setting color from xxxground_rgb to let possible user 256 number through
146+ table.insert (command , ' ctermfg=' .. sanitize_color_for_cterm (foreground ))
147+ table.insert (command , ' ctermbg=' .. sanitize_color_for_cterm (background ))
134148 table.insert (command , ' cterm=' .. gui )
135149 end
136150 end
0 commit comments