fix alpha, dont print alpha when uneeded

This commit is contained in:
Mylloon 2024-10-06 20:56:38 +02:00
parent a1f7c195a8
commit 992c9eb003
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -27,17 +27,17 @@ function latex-color --description "Get the LaTeX color from HEX code"
# Expand 3 to 4
if test (string length $hex) -eq 3
set hex $(string join "" $hex 0)
set hex $(string join "" $hex "F")
end
# Expand 4 to 8
if test (string length $hex) -eq 4
set hex "$(string replace -ar '(.)' '$1$1' $hex)00"
set hex "$(string replace -ar '(.)' '$1$1' $hex)FF"
end
# Expand 6 to 8
if test (string length $hex) -eq 6
set hex $(string join "" $hex 00)
set hex $(string join "" $hex "FF")
end
# Convert hex to RGB
@ -46,5 +46,10 @@ function latex-color --description "Get the LaTeX color from HEX code"
set b (math "0x$(string sub -s 5 -l 2 $hex) / 255")
set a (math "0x$(string sub -s 7 -l 2 $hex) / 255")
printf "{%.2f, %.2f, %.2f, %.2f}\n" $r $g $b $a
if test $a -eq 1
printf "{%.2f, %.2f, %.2f}\n" $r $g $b
else
printf "{%.2f, %.2f, %.2f, %.2f}\n" $r $g $b $a
end
end