diff options
author | Mattias Andrée <maandree@operamail.com> | 2014-04-12 20:07:20 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2014-04-12 20:07:20 +0200 |
commit | 87a24da650c5667d27404b68ea03418c9400804c (patch) | |
tree | 1da6f468f5af8d536233d6a5c4d037d9fe4fbd24 | |
parent | ensure that redshift is running without locale settings (diff) | |
download | nightshift-87a24da650c5667d27404b68ea03418c9400804c.tar.gz nightshift-87a24da650c5667d27404b68ea03418c9400804c.tar.bz2 nightshift-87a24da650c5667d27404b68ea03418c9400804c.tar.xz |
user interface: hide cursor, set lflags, get window size + fetch window size updates
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r-- | src/interface.py | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/interface.py b/src/interface.py index d6535a2..96c48b4 100644 --- a/src/interface.py +++ b/src/interface.py @@ -19,6 +19,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. ''' import sys +import fcntl +import struct +import signal +import termios import threading @@ -26,15 +30,25 @@ def user_interface(): ''' Start user interface ''' - print('\033[?1049h') + print('\033[?1049h\033[?25l') + saved_stty = termios.tcgetattr(sys.stdout.fileno()) + stty = termios.tcgetattr(sys.stdout.fileno()) + stty[3] &= ~(termios.ICANON | termios.ECHO | termios.ISIG) try: + termios.tcsetattr(sys.stdout.fileno(), termios.TCSAFLUSH, stty) + (height, width) = struct.unpack('hh', fcntl.ioctl(sys.stdout.fileno(), termios.TIOCGWINSZ, '1234')) sock.sendall('status\n'.encode('utf-8')) + def winch(signal, frame): + nonlocal height, width + (height, width) = struct.unpack('hh', fcntl.ioctl(sys.stdout.fileno(), termios.TIOCGWINSZ, '1234')) + signal.signal(signal.SIGWINCH, winch) def callback(status): if status is None: return print('\033[H\033[2J', end = '') for key in status: print(key + ': ' + status[key]) + print(str(width) + ' x ' + str(height)) #brightness = [float(status['%s brightness' % k]) for k in ('Night', 'Current', 'Daytime')] #temperature = [float(status['%s temperature' % k]) for k in ('Night', 'Current', 'Daytime')] #dayness = float(status['Dayness']) @@ -49,7 +63,8 @@ def user_interface(): except: pass finally: - print('\033[?1049l') + termios.tcsetattr(sys.stdout.fileno(), termios.TCSAFLUSH, saved_stty) + print('\033[?25h\033[?1049l') def ui_status(callback): |