add vertical box bar as default visual representaion for percentages

This commit is contained in:
koksnuss
2018-05-27 01:57:10 +02:00
parent 33dd3a4168
commit 8a2b50249b
8 changed files with 182 additions and 77 deletions

View File

@ -2,7 +2,8 @@
DIR="/sys/class/backlight"
[[ "${BLOCK_INSTANCE}" == "color" ]] && MODE="color" || MODE="bw"
[[ "$BLOCK_INSTANCE" =~ "color" ]] && MODE="color" || MODE="bw"
[[ "$BLOCK_INSTANCE" =~ "long" || "$BLOCK_BUTTON" == 1 ]] && LONG=true
if [[ -d "$DIR/acpi_video0" ]]; then
DIR="$DIR/acpi_video0"
@ -14,26 +15,45 @@ else
exit 33
fi
cat "$DIR/brightness" "$DIR/max_brightness" | gawk -v MODE="$MODE" '
NR==1 { current_brightness = $1 }
NR==2 { max_brightness = $1 }
cat "$DIR/brightness" "$DIR/max_brightness" | gawk -v MODE="$MODE" -v LONG="$LONG" '
NR==1 { cbr = $1 }
NR==2 { mbr = $1 }
END {
relative_brightness = ( current_brightness / max_brightness ) * 100
printf("%d%\n", relative_brightness)
printf("%d\n", relative_brightness)
if (MODE == "color") {
if (relative_brightness < 50) {
print("#04B431\n")
} else if (relative_brightness < 60) {
print("#A8FF00\n")
} else if (relative_brightness < 70) {
print("#FFF600\n")
} else if (relative_brightness < 80) {
print("#FFAE00\n")
} else if (relative_brightness < 90) {
print("#FF0000\n")
load = ( cbr / mbr ) * 100
if (LONG == "true") {
printf("%d%\n", load)
} else {
if (load < 100 / 9) {
printf("▁\n▁\n")
} else if (load < 100 / 9 * 2 ) {
printf("▁\n▁\n")
} else if (load < 100 / 9 * 3 ) {
printf("▂\n▂\n")
} else if (load < 100 / 9 * 4 ) {
printf("▃\n▃\n")
} else if (load < 100 / 9 * 5 ) {
printf("▄\n▄\n")
} else if (load < 100 / 9 * 6 ) {
printf("▅\n▅\n")
} else if (load < 100 / 9 * 7 ) {
printf("▆\n▆\n")
} else if (load < 100 / 9 * 8 ) {
printf("▇\n▇\n")
} else {
exit 33
printf("█\n█\n")
}
}
if (MODE == "color") {
if (load < 60) {
print("#04B431\n")
} else if (load < 50) {
print("#A8FF00\n")
} else if (load < 80) {
print("#FFF600\n")
} else if (load < 90) {
print("#FFAE00\n")
} else {
print("#FF0000\n")
}
} else {
printf("\n")