aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkianonymus <anonymus.aki@gmail.com>2022-08-27 23:11:35 +0530
committerAkianonymus <anonymus.aki@gmail.com>2022-08-27 23:11:35 +0530
commit4fc6972e3d66d5b42c6ff44dd4f1d15db5aed03c (patch)
tree121520b881fefac9a0cd151f3712f2b554ee7713
parentfix: error when invalid hsl/rgb values (diff)
Use string.format to convert to hex
-rw-r--r--lua/colorizer.lua8
-rw-r--r--test/expectation.txt5
2 files changed, 6 insertions, 7 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
diff --git a/test/expectation.txt b/test/expectation.txt
index 7813fe8..da3deb6 100644
--- a/test/expectation.txt
+++ b/test/expectation.txt
@@ -1,5 +1,5 @@
-- vim:ft=lua
-require'colorizer'.attach_to_buffer(0, {css=true})
+require("colorizer").attach_to_buffer(0, { css = true })
--[[ SUCCESS
#F0F
@@ -15,7 +15,7 @@ Blue Gray LightBlue Gray100 White
White
#def
#deadbeef
-rgba(0,0,0,0)
+rgba(200,30,0,0)
rgb(0,0,0)
rgb(10, 100 , 100)
hsl(300,50%,50%)
@@ -43,4 +43,3 @@ hsla(300,50%,50,1.0000000000000001)
hsla(300,50,50,1.0000000000000001)
hsla(361,50,50,1.0000000000000001)
]]
-