diff options
author | Akianonymus <anonymus.aki@gmail.com> | 2022-09-04 18:32:02 +0530 |
---|---|---|
committer | Akianonymus <anonymus.aki@gmail.com> | 2022-09-06 15:06:14 +0530 |
commit | 5f7680e7e7ccad68bd9962bcbb40dfde1c3669a1 (patch) | |
tree | 0345c3393e3f64d77042224dc6b3e4672b1e901e /lua/colorizer/utils.lua | |
parent | colorizer: Make sure it works without giving any config (diff) |
Fix https://github.com/NvChad/nvim-colorizer.lua/issues/12 | Add support for tailwind colors
Three methods
normal: Use the hardcoded colors
lsp: Use lsp to fetch colors
both: Use the hardcoded colors and use lsp too if available
although this is hardcoding, but working with what we got, has all the
colors tailwind provides, atleast the prebuilt ones
for new defined colors, have to enable the lsp method
Generated using https://github.com/tailwindlabs/tailwindcss/raw/master/src/public/colors.js
and https://github.com/tailwindlabs/tailwindcss/raw/master/src/corePlugins.js
use a different namespace than default for tailwind lsp method
only try to use lsp method if attached
Misc changes
export the user_default_settings to doc
clear name space after the lines are processed for a smooth transition
cleanup some code
Diffstat (limited to 'lua/colorizer/utils.lua')
-rw-r--r-- | lua/colorizer/utils.lua | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/lua/colorizer/utils.lua b/lua/colorizer/utils.lua index 0cb09ee..3b501ac 100644 --- a/lua/colorizer/utils.lua +++ b/lua/colorizer/utils.lua @@ -22,22 +22,26 @@ local CATEGORY_ALPHANUM = bor(CATEGORY_ALPHA, CATEGORY_DIGIT) -- do not run the loop multiple times local b = string.byte +local byte_values = { ["0"] = b "0", ["9"] = b "9", ["a"] = b "a", ["f"] = b "f", ["z"] = b "z" } +local extra_char = { [b "-"] = true } + for i = 0, 255 do local v = 0 + local lowercase = bor(i, 0x20) -- Digit is bit 1 - if i >= b "0" and i <= b "9" then + if i >= byte_values["0"] and i <= byte_values["9"] then v = bor(v, lshift(1, 0)) v = bor(v, lshift(1, 2)) - v = bor(v, lshift(i - b "0", 4)) - end - local lowercase = bor(i, 0x20) - -- Alpha is bit 2 - if lowercase >= b "a" and lowercase <= b "z" then + v = bor(v, lshift(i - byte_values["0"], 4)) + elseif lowercase >= byte_values["a"] and lowercase <= byte_values["z"] then + -- Alpha is bit 2 v = bor(v, lshift(1, 1)) - if lowercase <= b "f" then + if lowercase <= byte_values["f"] then v = bor(v, lshift(1, 2)) - v = bor(v, lshift(lowercase - b "a" + 10, 4)) + v = bor(v, lshift(lowercase - byte_values["a"] + 10, 4)) end + elseif extra_char[i] then + v = i end BYTE_CATEGORY[i] = v end |