Use hsl to define colors. Add a bunch of groups

This commit is contained in:
Daniel Lundin 2024-06-07 17:46:35 +02:00
parent cc8b832a87
commit b7fa034ed4
No known key found for this signature in database
2 changed files with 133 additions and 18 deletions

71
lua/dieter/hsl.lua Normal file
View file

@ -0,0 +1,71 @@
-- https://github.com/EmmanuelOga/columns/blob/master/utils/color.lua
local M = {}
--- Converts an HSL color value to RGB. Conversion formula
--- adapted from http://en.wikipedia.org/wiki/HSL_color_space.
--- Assumes h, s, and l are contained in the set [0, 1] and
--- returns r, g, and b in the set [0, 255].
---
--- @param h number The hue
--- @param s number The saturation
--- @param l number The lightness
--- @return number, number, number # The RGB representation
function M.hslToRgb(h, s, l)
--- @type number, number, number
local r, g, b
if s == 0 then
r, g, b = l, l, l -- achromatic
else
--- @param p number
--- @param q number
--- @param t number
local function hue2rgb(p, q, t)
if t < 0 then
t = t + 1
end
if t > 1 then
t = t - 1
end
if t < 1 / 6 then
return p + (q - p) * 6 * t
end
if t < 1 / 2 then
return q
end
if t < 2 / 3 then
return p + (q - p) * (2 / 3 - t) * 6
end
return p
end
--- @type number
local q
if l < 0.5 then
q = l * (1 + s)
else
q = l + s - l * s
end
local p = 2 * l - q
r = hue2rgb(p, q, h + 1 / 3)
g = hue2rgb(p, q, h)
b = hue2rgb(p, q, h - 1 / 3)
end
return r * 255, g * 255, b * 255
end
--- Converts an HSL color value to RGB in Hex representation.
--- @param h number The hue
--- @param s number The saturation
--- @param l number The lightness
--- @return string # The hex representation
function M.hslToHex(h, s, l)
local r, g, b = M.hslToRgb(h / 360, s / 100, l / 100)
return string.format("#%02x%02x%02x", r, g, b)
end
return M

View file

@ -7,21 +7,37 @@ local colors = {
intense = "#000000",
primary = "#ff0000",
secondary = "#00ff00",
diagnostic_error = "#ff0038",
diagnostic_warning = "#ffcc00",
diagnostic_info = "#47eae0",
diagnostic_hint = "#47eae0",
string = hsl(96, 50, 33),
comment = hsl(230, 66, 40),
comment_error = hsl(2, 85, 40),
diagnostic_error = hsl(347, 80, 45),
diagnostic_warning = hsl(30, 100, 50),
diagnostic_info = hsl(145, 80, 30),
diagnostic_hint = hsl(145, 80, 30),
diff_add = "#00ff77",
diff_change = "#47eae0",
diff_delete = "#ff0038",
add = hsl(84, 75, 67),
popup_error_bg = hsl(0, 90, 99),
popup_warning_bg = hsl(27, 90, 99),
popup_info_bg = hsl(112, 90, 99),
popup_hint_bg = hsl(112, 90, 99),
add = hsl(84, 50, 80),
add_quarter = hsl(84, 80, 95),
change = hsl(41, 50, 75),
change = hsl(41, 80, 80),
change_quarter = hsl(224, 100, 85),
delete = hsl(350, 100, 40),
delete_quarter = hsl(350, 100, 85),
dialog_bg = hsl(224, 5, 92),
selection = hsl(270, 75, 92),
highlight_subtle = "#f0f0f0",
dimmed = "#cccccc",
},
@ -47,15 +63,24 @@ local colors = {
local c = colors[vim.o.background]
local theme = {
Constant = { link = "Normal" },
Delimiter = { link = "Normal" },
Identifier = { link = "Normal" },
Normal = { fg = c.foreground, bg = c.background },
Constant = { link = "NormalNC" },
Delimiter = { link = "NormalNC" },
Identifier = { link = "NormalNC" },
Keyword = { fg = c.foreground, bold = true },
Operator = { link = "Normal" },
Special = { link = "Normal" },
String = { link = "Normal" },
Type = { link = "Normal" },
Operator = { link = "NormalNC" },
Special = { link = "NormalNC" },
Type = { link = "NormalNC" },
String = { fg = c.string },
Comment = { fg = c.comment, italic = true, bold = true },
CommentError = { fg = c.comment_error, italic = true, bold = true },
["@comment.note"] = { link = "Comment" },
["@comment.todo"] = { link = "CommentError" },
["@comment.error"] = { link = "CommentError" },
["@comment.warning"] = { link = "CommentError" },
DiffAdd = { fg = c.add, bg = c.add_quarter },
GitSignsAdd = { fg = c.add, bg = c.background },
@ -68,12 +93,20 @@ local theme = {
GitSignsDeleteNr = { link = "DiffDelete" },
-- Treesitter
["@function"] = { link = "Normal" },
["@special"] = { link = "Normal" },
["@variable"] = { link = "Normal" },
["@function"] = { link = "NormalNC" },
["@special"] = { link = "NormalNC" },
["@variable"] = { link = "NormalNC" },
-- UI Elements
CursorLine = { bg = c.highlight_subtle },
DiagnosticError = { fg = c.diagnostic_error, italic = true },
DiagnosticUnderlineError = { fg = c.diagnostic_error, undercurl = true },
DiagnosticFloatingError = { fg = c.diagnostic_error, bg = c.popup_error_bg },
DiagnosticFloatingWarn = { fg = c.diagnostic_warning, bg = c.popup_warning_bg },
DiagnosticFloatingInfo = { fg = c.diagnostic_info, bg = c.popup_info_bg },
DiagnosticFloatingHint = { fg = c.diagnostic_hint, bg = c.popup_hint_bg },
DiagnosticSignError = { fg = c.diagnostic_error },
DiagnosticSignHint = { fg = c.diagnostic_hint },
DiagnosticSignInfo = { fg = c.diagnostic_info },
@ -83,8 +116,19 @@ local theme = {
IndentLineCurrent = { fg = c.dimmed },
TreesitterContext = { reverse = true },
TreesitterContextLineNumber = { bg = c.dimmed, reverse = true, italic = true },
InclineNormal = { bg = "bg" },
InclineNormalNC = { bg = "bg" },
InclineNormal = { bg = c.background },
InclineNormalNC = { bg = c.background },
WinSeparator = { bg = c.dialog_bg },
NormalFloat = { bg = c.dialog_bg },
Title = { fg = c.foreground, bold = true },
TelescopeNormal = { fg = c.foreground, bg = c.background },
TelescopeBorder = { bold = true },
TelescopeSelection = { reverse = true },
TelescopeResultsComment = { fg = c.foreground, italic = true },
Visual = { bg = c.selection },
}
vim.cmd("hi clear")