Created
January 4, 2022 02:54
-
-
Save violet4/6e8e4367a78de72f17f55cde2a2d81e7 to your computer and use it in GitHub Desktop.
interactive python curses script that uses redshift to change the gamma/redness using arrow keys
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| import curses | |
| import subprocess | |
| import re | |
| # use something that won't hurt the eyes if it's evening | |
| brightness_re = re.compile(r'Color temperature: (\d+)K') | |
| start_brightness = 3000 | |
| print_str = ''' | |
| increment by: 50<- {increment} ->50 | |
| current brightness: V {brightness} ^ | |
| to exit, press any key other than the arrow keys | |
| ''' | |
| def print_screen(screen, brightness, increment): | |
| screen.addstr(0, 0, print_str.format(brightness=brightness, increment=increment)) | |
| screen.refresh() | |
| def main(screen): | |
| brightness = start_brightness | |
| increment = 200 | |
| while True: | |
| print_screen(screen, brightness, increment) | |
| ch = screen.getch() | |
| if ch == curses.KEY_DOWN: | |
| brightness -= increment | |
| elif ch == curses.KEY_UP: | |
| brightness += increment | |
| elif ch == curses.KEY_LEFT: | |
| increment -= 50 | |
| elif ch == curses.KEY_RIGHT: | |
| increment += 50 | |
| else: | |
| return brightness | |
| if brightness < 1000: | |
| brightness = 1000 | |
| elif brightness > 25000: | |
| brightness = 25000 | |
| subprocess.check_output(['redshift', '-PO', str(brightness)]) | |
| if __name__ == '__main__': | |
| brightness = curses.wrapper(main) | |
| print('set brightness to', brightness) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment