diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-06-24 17:38:25 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-06-24 17:38:25 +0000 |
commit | d269eb36c8f4d05fb0f8e9b8a00998dd41f0c829 (patch) | |
tree | 4268cb5c733a3b88e7c5b765a30f5b9fd81c804e /deluge/ui/console/modes/basemode.py | |
parent | Adding upstream version 2.1.1. (diff) | |
download | deluge-d269eb36c8f4d05fb0f8e9b8a00998dd41f0c829.tar.xz deluge-d269eb36c8f4d05fb0f8e9b8a00998dd41f0c829.zip |
Adding upstream version 2.1.2~dev0+20230529.upstream/2.1.2_dev0+20230529
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'deluge/ui/console/modes/basemode.py')
-rw-r--r-- | deluge/ui/console/modes/basemode.py | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/deluge/ui/console/modes/basemode.py b/deluge/ui/console/modes/basemode.py index 5ebaf86..a8ab1db 100644 --- a/deluge/ui/console/modes/basemode.py +++ b/deluge/ui/console/modes/basemode.py @@ -8,7 +8,10 @@ # import logging +import signal +import struct import sys +from typing import Tuple import deluge.component as component import deluge.ui.console.utils.colors as colors @@ -22,10 +25,8 @@ except ImportError: pass try: - import signal - import struct - import termios from fcntl import ioctl + from termios import TIOCGWINSZ except ImportError: pass @@ -62,17 +63,20 @@ class InputKeyHandler: class TermResizeHandler: def __init__(self): try: - signal.signal(signal.SIGWINCH, self.on_terminal_size) + signal.signal(signal.SIGWINCH, self.on_resize) except ValueError as ex: log.debug('TermResize unavailable, unable to catch SIGWINCH signal: %s', ex) except AttributeError as ex: log.debug('TermResize unavailable, no SIGWINCH signal on Windows: %s', ex) - def on_terminal_size(self, *args): - # Get the new rows and cols value - rows, cols = struct.unpack('hhhh', ioctl(0, termios.TIOCGWINSZ, b'\000' * 8))[ - 0:2 - ] + @staticmethod + def get_window_size(fd: int = 0) -> Tuple[int, int]: + """Return the tty window size as row, col.""" + return struct.unpack('4h', ioctl(fd, TIOCGWINSZ, b'\x00' * 8))[0:2] + + def on_resize(self, _signum, _frame): + """Handler for SIGWINCH when terminal changes size""" + rows, cols = self.get_window_size() curses.resizeterm(rows, cols) return rows, cols |