From 87a24da650c5667d27404b68ea03418c9400804c Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 12 Apr 2014 20:07:20 +0200 Subject: user interface: hide cursor, set lflags, get window size + fetch window size updates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/interface.py | 19 +++++++++++++++++-- 1 file 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 . ''' 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): -- cgit v1.2.3-70-g09d2