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 # Expand 3 to 4
if test (string length $hex) -eq 3 if test (string length $hex) -eq 3
set hex $(string join "" $hex 0) set hex $(string join "" $hex "F")
end end
# Expand 4 to 8 # Expand 4 to 8
if test (string length $hex) -eq 4 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 end
# Expand 6 to 8 # Expand 6 to 8
if test (string length $hex) -eq 6 if test (string length $hex) -eq 6
set hex $(string join "" $hex 00) set hex $(string join "" $hex "FF")
end end
# Convert hex to RGB # 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 b (math "0x$(string sub -s 5 -l 2 $hex) / 255")
set a (math "0x$(string sub -s 7 -l 2 $hex) / 255") set a (math "0x$(string sub -s 7 -l 2 $hex) / 255")
if test $a -eq 1
printf "{%.2f, %.2f, %.2f}\n" $r $g $b
else
printf "{%.2f, %.2f, %.2f, %.2f}\n" $r $g $b $a printf "{%.2f, %.2f, %.2f, %.2f}\n" $r $g $b $a
end
end end