Darken and lighten functions for schemes

This commit is contained in:
Dakedres 2024-04-12 16:30:20 -06:00
parent bd4a42425c
commit a51ff516a0

View File

@ -20,6 +20,41 @@ rgb_b() {
printf "$((0x${MO_FUNCTION_ARGS[0]:4:4}))" printf "$((0x${MO_FUNCTION_ARGS[0]:4:4}))"
} }
rgb() {
rgb_r; printf " "
rgb_g; printf " "
rgb_b; printf " "
}
clamp() {
if [[ $1 -lt 0 ]]; then
printf "0"
else
if [[ $1 -gt 255 ]]; then
printf "255"
else
printf "%s" "$1"
fi
fi
}
lighten() {
mod="${MO_FUNCTION_ARGS[1]}"
parts=("$(rgb_r)" "$(rgb_g)" "$(rgb_b)")
vars=""
for part in "${parts[@]}"; do
let var=$part+$mod
vars=$vars"$(clamp "$var") "
done
printf "%02x%02x%02x" $vars
}
darken() {
MO_FUNCTION_ARGS[1]="-${MO_FUNCTION_ARGS[1]}"
lighten
}
set -a # All variables after this will be exported set -a # All variables after this will be exported
source $SCHEME source $SCHEME
mo "$TEMPLATE" mo "$TEMPLATE"