From 0a84f830c6d3cc3a93197902c32f6dfc7a3b8d9b Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Mon, 25 Aug 2025 15:20:20 +0200 Subject: update --- bin/isdarktty | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'bin') 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) }' -- cgit v1.2.3