This commit is a rewrite of larger parts of the console code. The motivation behind the rewrite is to cleanup the code and reduce code duplication to make it easier to understand and modify, and allow any form of code reuse. Most changes are to the interactive console, but also to how the different modes (BaseMode subclasses) are used and set up. * Address [#2097] - Improve match_torrent search match: Instead of matching e.g. torrent name with name.startswith(pattern) now check for asterix at beginning and end of pattern and search with startswith, endswith or __contains__ according to the pattern. Various smaller fixes: * Add errback handler to connection failed * Fix cmd line console mixing str and unicode input * Fix handling delete backwards with ALT+Backspace * Fix handling resizing of message popups * Fix docs generation warnings * Lets not stop the reactor on exception in basemode.. * Markup for translation arg help strings * Main functionality improvements: - Add support for indentation in formatting code in popup messages (like help) - Add filter sidebar - Add ComboBox and UI language selection - Add columnsview to allow rearranging the torrentlist columns and changing column widths. - Removed Columns pane in preferences as columnsview.py is sufficient - Remove torrent info panel (short cut 'i') as the torrent detail view is sufficient * Cleanups and code restructuring - Made BaseModes subclass of Component - Rewrite of most of basic window/panel to allow easier code reuse - Implemented better handling of multple popups by stacking popups. This makes it easier to return to previous popup when opening multiple popups. * Refactured console code: - modes/ for the different modes - Renamed Legacy mode to CmdLine - Renamed alltorrent.py to torrentlist.py and split the code into - torrentlist/columnsview.py - torrentlist/torrentsview.py - torrentlist/search_mode.py (minor mode) - torrentlist/queue_mode.py (minor mode) - cmdline/ for cmd line commands - utils/ for utility files - widgets/ for reusable GUI widgets - fields.py: Base widgets like TextInput, SelectInput, ComboInput - popup.py: Popup windows - inputpane.py: The BaseInputPane used to manage multiple base widgets in a panel - window.py: The BaseWindow used by all panels needing a curses screen - sidebar.py: The Sidebar panel - statusbars.py: The statusbars - Moved option parsing code from main.py to parser.py
64 lines
1.2 KiB
Python
64 lines
1.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
#
|
|
# Copyright (C) 2016 bendikro <bro.devel+deluge@gmail.com>
|
|
#
|
|
# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
|
|
# the additional special exception to link portions of this program with the OpenSSL library.
|
|
# See LICENSE for more details.
|
|
#
|
|
|
|
try:
|
|
import curses
|
|
except ImportError:
|
|
pass
|
|
|
|
KEY_BELL = 7 # CTRL-/ ^G (curses.keyname(KEY_BELL) == "^G")
|
|
KEY_TAB = 9
|
|
KEY_ENTER2 = 10
|
|
KEY_ESC = 27
|
|
KEY_SPACE = 32
|
|
KEY_BACKSPACE2 = 127
|
|
|
|
KEY_ALT_AND_ARROW_UP = 564
|
|
KEY_ALT_AND_ARROW_DOWN = 523
|
|
|
|
KEY_ALT_AND_KEY_PPAGE = 553
|
|
KEY_ALT_AND_KEY_NPAGE = 548
|
|
|
|
KEY_CTRL_AND_ARROW_UP = 566
|
|
KEY_CTRL_AND_ARROW_DOWN = 525
|
|
|
|
|
|
def is_printable_char(c):
|
|
return c >= 32 and c <= 126
|
|
|
|
|
|
def is_int_chr(c):
|
|
return c > 47 and c < 58
|
|
|
|
|
|
class Curser(object):
|
|
INVISIBLE = 0
|
|
NORMAL = 1
|
|
VERY_VISIBLE = 2
|
|
|
|
|
|
def safe_curs_set(visibility):
|
|
"""
|
|
Args:
|
|
visibility(int): 0, 1, or 2, for invisible, normal, or very visible
|
|
|
|
curses.curs_set fails on monochrome terminals so use this
|
|
to ignore errors
|
|
"""
|
|
try:
|
|
curses.curs_set(visibility)
|
|
except curses.error:
|
|
pass
|
|
|
|
|
|
class ReadState(object):
|
|
IGNORED = 0
|
|
READ = 1
|
|
CHANGED = 2
|