Misc fixes, color script and hex <-> color conversions

This commit is contained in:
2024-05-03 22:31:08 +01:00
parent 435b7a0929
commit c853d7b743
4 changed files with 41 additions and 2 deletions

View File

@@ -67,4 +67,37 @@ pushall() {
fi
}
hex2color(){
hex=${1#"#"}
r=$(printf '0x%0.2s' "$hex")
g=$(printf '0x%0.2s' ${hex#??})
b=$(printf '0x%0.2s' ${hex#????})
printf '%03d' "$(( (r<75?0:(r-35)/40)*6*6 +
(g<75?0:(g-35)/40)*6 +
(b<75?0:(b-35)/40) + 16 ))"
}
color2hex(){
dec=$(($1%256)) ### input must be a number in range 0-255.
if [ "$dec" -lt "16" ]; then
bas=$(( dec%16 ))
mul=128
[ "$bas" -eq "7" ] && mul=192
[ "$bas" -eq "8" ] && bas=7
[ "$bas" -gt "8" ] && mul=255
a="$(( (bas&1) *mul ))"
b="$(( ((bas&2)>>1)*mul ))"
c="$(( ((bas&4)>>2)*mul ))"
printf 'dec= %3s basic= #%02x%02x%02x\n' "$dec" "$a" "$b" "$c"
elif [ "$dec" -gt 15 ] && [ "$dec" -lt 232 ]; then
b=$(( (dec-16)%6 )); b=$(( b==0?0: b*40 + 55 ))
g=$(( (dec-16)/6%6)); g=$(( g==0?0: g*40 + 55 ))
r=$(( (dec-16)/36 )); r=$(( r==0?0: r*40 + 55 ))
printf 'dec= %3s color= #%02x%02x%02x\n' "$dec" "$r" "$g" "$b"
else
gray=$(( (dec-232)*10+8 ))
printf 'dec= %3s gray= #%02x%02x%02x\n' "$dec" "$gray" "$gray" "$gray"
fi
}
set completion-ignore-case On

View File

@@ -216,9 +216,9 @@ default_floating_border pixel 3
smart_borders on
# Border colors
client.focused #fab387 #fab387 #1e1e2e
client.focused #d75f5f #d75f5f #1e1e2e
client.unfocused #1e1e2e #1e1e2e #cdd6f4
client.focused_inactive #fab387 #fab387 #1e1e2e
client.focused_inactive #1e1e2e #1e1e2e #1e1e2e
client.placeholder #f9e2af #f9e2af #1e1e2e
client.urgent #f38ba8 #f38ba8 #1e1e2e
client.background #1e1e2e