summaryrefslogtreecommitdiffstats
path: root/deluge/ui/console/modes
diff options
context:
space:
mode:
Diffstat (limited to 'deluge/ui/console/modes')
-rw-r--r--deluge/ui/console/modes/basemode.py22
-rw-r--r--deluge/ui/console/modes/connectionmanager.py7
-rw-r--r--deluge/ui/console/modes/torrentdetail.py2
-rw-r--r--deluge/ui/console/modes/torrentlist/torrentactions.py1
4 files changed, 18 insertions, 14 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
diff --git a/deluge/ui/console/modes/connectionmanager.py b/deluge/ui/console/modes/connectionmanager.py
index 0ccdd93..ce8b6f5 100644
--- a/deluge/ui/console/modes/connectionmanager.py
+++ b/deluge/ui/console/modes/connectionmanager.py
@@ -127,12 +127,14 @@ class ConnectionManager(BaseMode, PopupsHandler):
def add_host(self, hostname, port, username, password):
log.info('Adding host: %s', hostname)
+ if port.isdecimal():
+ port = int(port)
try:
self.hostlist.add_host(hostname, port, username, password)
except ValueError as ex:
self.report_message(_('Error adding host'), f'{hostname}: {ex}')
else:
- self.update_select_host_popup()
+ self.pop_popup()
def delete_host(self, host_id):
log.info('Deleting host: %s', host_id)
@@ -195,7 +197,8 @@ class ConnectionManager(BaseMode, PopupsHandler):
if chr(c) == 'q':
return
elif chr(c) == 'D':
- host_id = self.popup.current_selection()[1]
+ host_index = self.popup.current_selection()
+ host_id = self.popup.inputs[host_index].name
self.delete_host(host_id)
return
elif chr(c) == 'a':
diff --git a/deluge/ui/console/modes/torrentdetail.py b/deluge/ui/console/modes/torrentdetail.py
index 16bd08a..4383d58 100644
--- a/deluge/ui/console/modes/torrentdetail.py
+++ b/deluge/ui/console/modes/torrentdetail.py
@@ -181,7 +181,6 @@ class TorrentDetail(BaseMode, PopupsHandler):
self.refresh()
def set_state(self, state):
-
if state.get('files'):
self.full_names = {x['index']: x['path'] for x in state['files']}
@@ -363,7 +362,6 @@ class TorrentDetail(BaseMode, PopupsHandler):
).addCallback(self.set_state)
def draw_files(self, files, depth, off, idx):
-
color_selected = 'blue'
color_partially_selected = 'magenta'
color_highlighted = 'white'
diff --git a/deluge/ui/console/modes/torrentlist/torrentactions.py b/deluge/ui/console/modes/torrentlist/torrentactions.py
index 6450118..a153e11 100644
--- a/deluge/ui/console/modes/torrentlist/torrentactions.py
+++ b/deluge/ui/console/modes/torrentlist/torrentactions.py
@@ -240,7 +240,6 @@ def torrent_action(action, *args, **kwargs):
# Creates the popup. mode is the calling mode, tids is a list of torrents to take action upon
def torrent_actions_popup(mode, torrent_ids, details=False, action=None, close_cb=None):
-
if action is not None:
torrent_action(action, mode=mode, torrent_ids=torrent_ids)
return