gruber-darker.nvim/lua/gruber-darker/color.lua

42 lines
732 B
Lua
Raw Permalink Normal View History

2023-03-25 23:06:57 +01:00
---@class Color
---@field private value integer|nil
local Color = {}
Color.__index = Color
---Create a new color
---@param value integer
---@return Color
2023-03-25 23:06:57 +01:00
function Color.new(value)
local color = setmetatable({
value = value,
}, Color)
return color
end
---Create the "NONE" color
---@return Color
2023-03-25 23:06:57 +01:00
function Color.none()
local color = setmetatable({
value = nil,
}, Color)
return color
end
---Get hexadecimal color value as a string
---@return string
function Color:to_string()
2023-03-25 23:43:49 +01:00
if self.value == nil then
return "NONE"
end
2023-03-25 23:06:57 +01:00
2023-03-25 23:43:49 +01:00
-- special edge case for BLACK where
-- "#0" is returned, which is invalid to Neovim
if self.value == 0 then
return "#000000"
end
2023-03-25 23:06:57 +01:00
return string.format("#%x", self.value)
end
return Color