Permalink
Browse files

Filter input that turses currently doesn't handle

Closes #179
Closes #185
  • Loading branch information...
1 parent 3f6cee4 commit 411e79ea54aecd87fb9285c4770c646777f2d7d5 @dialelo committed Mar 1, 2014
Showing with 11 additions and 2 deletions.
  1. +11 −2 turses/core.py
View
13 turses/core.py
@@ -43,6 +43,7 @@ class InputHandler(object):
"""
Maps user input to calls to :class:`Controller` functions.
"""
+ ALLOWED_MOUSE_KEYS = (4, 5)
def __init__(self, controller):
self.controller = controller
@@ -147,6 +148,14 @@ def command(self, key):
"""
return configuration.key_mappings.get(key)
+ def filter_input(self, keys, raw):
+ accepted_keys = []
+ for key in keys:
+ if (not self.is_mouse_input(key) or
+ key[1] in self.ALLOWED_MOUSE_KEYS):
+ accepted_keys.append(key)
+ return accepted_keys
+
def handle(self, key):
"""Handle input."""
command = self.command(key)
@@ -329,11 +338,11 @@ def main_loop(self):
if not hasattr(self, 'loop'):
# Creating the main loop for the first time
self.input_handler = InputHandler(self)
- handler = self.input_handler.handle
self.loop = urwid.MainLoop(self.ui,
configuration.palette,
handle_mouse=True,
- unhandled_input=handler)
+ unhandled_input=self.input_handler.handle,
+ input_filter=self.input_handler.filter_input)
# Authenticate API just before starting main loop
self.authenticate_api()

0 comments on commit 411e79e

Please sign in to comment.