@@ -76,6 +76,19 @@ local function sanitize_color(color)
76
76
end
77
77
end
78
78
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
+
79
92
function M .get_lualine_hl (name )
80
93
local hl = loaded_highlights [name ]
81
94
if hl and not hl .empty then
@@ -113,24 +126,25 @@ function M.highlight(name, foreground, background, gui, link)
113
126
end
114
127
vim .list_extend (command , { ' link' , name , link })
115
128
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 )
118
131
gui = (gui ~= nil and gui ~= ' ' ) and gui or ' None'
119
132
if
120
133
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
123
136
and loaded_highlights [name ].gui == gui
124
137
then
125
138
return -- color is already defined why are we doing this anyway ?
126
139
end
127
140
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 )
130
143
table.insert (command , ' gui=' .. gui )
131
144
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 ))
134
148
table.insert (command , ' cterm=' .. gui )
135
149
end
136
150
end
0 commit comments