diff options
| author | Marc Vertes <mvertes@free.fr> | 2025-08-25 15:20:20 +0200 |
|---|---|---|
| committer | Marc Vertes <mvertes@free.fr> | 2025-08-25 15:20:20 +0200 |
| commit | 0a84f830c6d3cc3a93197902c32f6dfc7a3b8d9b (patch) | |
| tree | 719b019529f1664e4a0942f8204b3e4f861d32f5 | |
| parent | d1403578402a0694457da8b5f628d37c4f3836f4 (diff) | |
update
| -rwxr-xr-x | bin/isdarktty | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/bin/isdarktty b/bin/isdarktty index 8d01b89..334d8a0 100755 --- a/bin/isdarktty +++ b/bin/isdarktty @@ -1,20 +1,16 @@ #!/bin/sh -# compute luminance of the current terminal +# Check darkness by computing luminance of the current terminal. -oldstty=$(stty -g) +trap "stty $(stty -g)" EXIT stty raw -echo min 0 time 0 -printf "\e]11;?\e\\" +printf '\e]11;?\e\\' sleep 0.01 -read -r answer -stty "$oldstty" -awk -v s="$answer" 'BEGIN { - hex="123456789abcdef" - split(s, a, "") - r = (16 * index(hex, a[10]) + index(hex, a[11])) / 255 - g = (16 * index(hex, a[15]) + index(hex, a[16])) / 255 - b = (16 * index(hex, a[20]) + index(hex, a[21])) / 255 +awk -v FS='' -v hex=123456789abcdef '{ + r = (16 * index(hex, $10) + index(hex, $11)) / 255 + g = (16 * index(hex, $15) + index(hex, $16)) / 255 + b = (16 * index(hex, $20) + index(hex, $21)) / 255 # print 0.33 * r + 0.5 * g + 0.16 * b exit (0.33 * r + 0.5 * g + 0.16 * b > 0.5) }' |
