diff options
author | Akianonymus <anonymus.aki@gmail.com> | 2022-08-27 23:11:35 +0530 |
---|---|---|
committer | Akianonymus <anonymus.aki@gmail.com> | 2022-08-27 23:11:35 +0530 |
commit | 4fc6972e3d66d5b42c6ff44dd4f1d15db5aed03c (patch) | |
tree | 121520b881fefac9a0cd151f3712f2b554ee7713 /lua | |
parent | fix: error when invalid hsl/rgb values (diff) |
Use string.format to convert to hex
Diffstat (limited to 'lua')
-rw-r--r-- | lua/colorizer.lua | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/lua/colorizer.lua b/lua/colorizer.lua index 6ecf8d1..5980443 100644 --- a/lua/colorizer.lua +++ b/lua/colorizer.lua @@ -329,7 +329,7 @@ do if not b then return end - local rgb_hex = tohex(bor(lshift(r, 16), lshift(g, 8), b), 6) + local rgb_hex = string.format("%02x%02x%02x", r, g, b) return match_end - 1, rgb_hex end @@ -360,7 +360,7 @@ do if r == nil or g == nil or b == nil then return end - local rgb_hex = tohex(bor(lshift(floor(r), 16), lshift(floor(g), 8), floor(b)), 6) + local rgb_hex = string.format("%02x%02x%02x", r, g, b) return match_end - 1, rgb_hex end @@ -392,7 +392,7 @@ do if not b then return end - local rgb_hex = tohex(bor(lshift(floor(r * a), 16), lshift(floor(g * a), 8), floor(b * a)), 6) + local rgb_hex = string.format("%02x%02x%02x", r * a, g * a, b * a) return match_end - 1, rgb_hex end @@ -427,7 +427,7 @@ do if r == nil or g == nil or b == nil then return end - local rgb_hex = tohex(bor(lshift(floor(r * a), 16), lshift(floor(g * a), 8), floor(b * a)), 6) + local rgb_hex = string.format("%02x%02x%02x", r * a, g * a, b * a) return match_end - 1, rgb_hex end end |