- commit
- 33e932039e43c26ea0380404acb903d87c935c65
- parent
- 8d9b52bc428eb64e60effeb190ea87f14ff3ca6a
- Author
- Tobias Bengfort <tobias.bengfort@gmx.net>
- Date
- 2015-03-22 19:18
Fix complexity
Diffstat
| M | dirtywords/curses.py | 34 | ++++++++++++++-------------------- |
| M | dirtywords/stupid.py | 51 | +++++++++++++++++++++++---------------------------- |
| M | setup.cfg | 1 | + |
3 files changed, 38 insertions, 48 deletions
diff --git a/dirtywords/curses.py b/dirtywords/curses.py
@@ -66,26 +66,20 @@ class Screen(base.Screen): 66 66 67 67 def _get_color(self, color): 68 68 r, g, b = color69 -1 r = int(round(r / 255.0)) * 25570 -1 g = int(round(g / 255.0)) * 25571 -1 b = int(round(b / 255.0)) * 25572 -173 -1 if (r, g, b) == (0, 0, 0):74 -1 return 075 -1 elif (r, g, b) == (255, 0, 0):76 -1 return 177 -1 elif (r, g, b) == (0, 255, 0):78 -1 return 279 -1 elif (r, g, b) == (255, 255, 0):80 -1 return 381 -1 elif (r, g, b) == (0, 0, 255):82 -1 return 483 -1 elif (r, g, b) == (255, 0, 255):84 -1 return 585 -1 elif (r, g, b) == (0, 255, 255):86 -1 return 687 -1 elif (r, g, b) == (255, 255, 255):88 -1 return 7-1 69 r = int(round(r / 255.0)) -1 70 g = int(round(g / 255.0)) -1 71 b = int(round(b / 255.0)) -1 72 -1 73 return { -1 74 '000': 0, -1 75 '100': 1, -1 76 '010': 2, -1 77 '110': 3, -1 78 '001': 4, -1 79 '101': 5, -1 80 '011': 6, -1 81 '111': 7, -1 82 }.get('%i%i%i' % (r, g, b)) 89 83 90 84 def putstr(self, y, x, s): 91 85 for i, ch in enumerate(s):
diff --git a/dirtywords/stupid.py b/dirtywords/stupid.py
@@ -46,6 +46,28 @@ class Screen(base.Screen): 46 46 finally: 47 47 termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_settings) 48 48 -1 49 def _codes2key(self, l): -1 50 codes = { -1 51 '13': KEYS['Return'], -1 52 '127': KEYS['Backspace'], -1 53 '27, 27': 27, -1 54 '27, 79, 70': KEYS['End'], -1 55 '27, 79, 72': KEYS['Home'], -1 56 '27, 91, 50, 126': KEYS['Insert'], -1 57 '27, 91, 51, 126': KEYS['Delete'], -1 58 '27, 91, 53, 126': KEYS['PageUp'], -1 59 '27, 91, 54, 126': KEYS['PageDown'], -1 60 '27, 91, 65': KEYS['Up'], -1 61 '27, 91, 66': KEYS['Down'], -1 62 '27, 91, 67': KEYS['Right'], -1 63 '27, 91, 68': KEYS['Left'], -1 64 } -1 65 key = ', '.join([str(i) for i in l]) -1 66 if key in codes: -1 67 return codes[key] -1 68 elif len(l) == 1: -1 69 return l[0] -1 70 49 71 def getch(self, blocking=True): 50 72 # Convert ANSI escape sequences to key constants 51 73 # This is implemented as a wrapper around :py:meth:`_getch` because @@ -71,34 +93,7 @@ class Screen(base.Screen): 71 93 # invalid? 72 94 pass 73 9574 -1 if l == [27, 27]:75 -1 return 2776 -1 if l == [27, 91, 68]:77 -1 return KEYS['Left']78 -1 elif l == [27, 91, 67]:79 -1 return KEYS['Right']80 -1 elif l == [27, 91, 66]:81 -1 return KEYS['Down']82 -1 elif l == [27, 91, 65]:83 -1 return KEYS['Up']84 -1 elif l == [27, 91, 54, 126]:85 -1 return KEYS['PageDown']86 -1 elif l == [27, 91, 53, 126]:87 -1 return KEYS['PageUp']88 -1 elif l == [27, 91, 51, 126]:89 -1 return KEYS['Delete']90 -1 elif l == [27, 91, 50, 126]:91 -1 return KEYS['Insert']92 -1 elif l == [127]:93 -1 return KEYS['Backspace']94 -1 elif l == [13]:95 -1 return KEYS['Return']96 -1 elif len(l) == 1:97 -1 return l[0]98 -1 elif l == [27, 79, 70]:99 -1 return KEYS['End']100 -1 elif l == [27, 79, 72]:101 -1 return KEYS['Home']-1 96 return self._codes2key(l) 102 97 103 98 def refresh(self): 104 99 spacing = '\n' * self.height * 2
diff --git a/setup.cfg b/setup.cfg
@@ -9,6 +9,7 @@ cover-html-dir=.cover 9 9 10 10 [flake8] 11 11 exclude=.env,.tox,.git,build,dist,docs -1 12 max-complexity=13 12 13 13 14 [build_sphinx] 14 15 source-dir = docs/source