Skip to content

Instantly share code, notes, and snippets.

@violet4
Created January 4, 2022 02:54
Show Gist options
  • Select an option

  • Save violet4/6e8e4367a78de72f17f55cde2a2d81e7 to your computer and use it in GitHub Desktop.

Select an option

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
#!/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