From 4fc6972e3d66d5b42c6ff44dd4f1d15db5aed03c Mon Sep 17 00:00:00 2001 From: Akianonymus Date: Sat, 27 Aug 2022 23:11:35 +0530 Subject: Use string.format to convert to hex --- lua/colorizer.lua | 8 ++++---- test/expectation.txt | 5 ++--- 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) ]] - -- cgit v1.2.3-70-g09d2