1# -*- coding: utf-8 -*- 2# 3# Copyright (C) 2016 bendikro <bro.devel+deluge@gmail.com> 4# 5# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with 6# the additional special exception to link portions of this program with the OpenSSL library. 7# See LICENSE for more details. 8# 9 10from __future__ import unicode_literals 11 12try: 13 import curses 14except ImportError: 15 pass 16 17KEY_BELL = 7 # CTRL-/ ^G (curses.keyname(KEY_BELL) == "^G") 18KEY_TAB = 9 19KEY_ENTER2 = 10 20KEY_ESC = 27 21KEY_SPACE = 32 22KEY_BACKSPACE2 = 127 23 24KEY_ALT_AND_ARROW_UP = 564 25KEY_ALT_AND_ARROW_DOWN = 523 26 27KEY_ALT_AND_KEY_PPAGE = 553 28KEY_ALT_AND_KEY_NPAGE = 548 29 30KEY_CTRL_AND_ARROW_UP = 566 31KEY_CTRL_AND_ARROW_DOWN = 525 32 33 34def is_printable_chr(c): 35 return c >= 32 and c <= 126 36 37 38def is_int_chr(c): 39 return c > 47 and c < 58 40 41 42class Curser(object): 43 INVISIBLE = 0 44 NORMAL = 1 45 VERY_VISIBLE = 2 46 47 48def safe_curs_set(visibility): 49 """ 50 Args: 51 visibility(int): 0, 1, or 2, for invisible, normal, or very visible 52 53 curses.curs_set fails on monochrome terminals so use this 54 to ignore errors 55 """ 56 try: 57 curses.curs_set(visibility) 58 except curses.error: 59 pass 60 61 62class ReadState(object): 63 IGNORED = 0 64 READ = 1 65 CHANGED = 2 66