diff options
| author | Marc Vertes <mvertes@free.fr> | 2025-08-25 13:11:36 +0200 |
|---|---|---|
| committer | Marc Vertes <mvertes@free.fr> | 2025-08-25 13:11:36 +0200 |
| commit | d1403578402a0694457da8b5f628d37c4f3836f4 (patch) | |
| tree | dab09810ce48d74cdeecce2faa2c1ea908607d10 /bin | |
| parent | 20bad3245424e6a6b2372925c3f9e8da01a2fd75 (diff) | |
add bin/isdarktty
Diffstat (limited to 'bin')
| -rwxr-xr-x | bin/isdarktty | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/bin/isdarktty b/bin/isdarktty new file mode 100755 index 0000000..8d01b89 --- /dev/null +++ b/bin/isdarktty @@ -0,0 +1,20 @@ +#!/bin/sh + +# compute luminance of the current terminal + +oldstty=$(stty -g) +stty raw -echo min 0 time 0 +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 + # print 0.33 * r + 0.5 * g + 0.16 * b + exit (0.33 * r + 0.5 * g + 0.16 * b > 0.5) +}' |
