diff options
author | hut <hut@lavabit.com> | 2010-09-30 03:47:00 +0200 |
---|---|---|
committer | hut <hut@lavabit.com> | 2010-09-30 03:47:25 +0200 |
commit | 5cb67eeb96d337b55deea20131fc44a3d5447251 (patch) | |
tree | 41ec388f1a39a52e79a896202dd5324662bf88f1 | |
parent | 512f386be8753775ec824a6d9cbaf6527d50eda4 (diff) | |
download | ranger-5cb67eeb96d337b55deea20131fc44a3d5447251.tar.gz |
gui.curses_shortcuts: bugfix, simplification
-rw-r--r-- | ranger/gui/curses_shortcuts.py | 36 |
1 files changed, 9 insertions, 27 deletions
diff --git a/ranger/gui/curses_shortcuts.py b/ranger/gui/curses_shortcuts.py index 65886d7e..006ea4d0 100644 --- a/ranger/gui/curses_shortcuts.py +++ b/ranger/gui/curses_shortcuts.py @@ -44,41 +44,23 @@ class CursesShortcuts(SettingsAware): addstr(*args) -- failsafe version of self.win.addstr(*args) """ - def addstr(self, *args): + def _addxyz_wrapper(self, function, args): try: - self.win.addstr(*args) + function(*args) except (_curses.error, TypeError): pass except UnicodeEncodeError: - try: - self.win.addstr(*(obj.encode('utf8') for obj in args)) - except UnicodeEncodeError: - try: - self.win.addstr(*(ascii_only(obj) for obj in args)) - except (_curses.error, TypeError): - pass + function(*(obj.encode('utf8') if hasattr(obj, 'encode') \ + else obj for obj in args)) + + def addstr(self, *args): + self._addxyz_wrapper(self.win.addstr, args) def addnstr(self, *args): - try: - self.win.addnstr(*args) - except (_curses.error, TypeError): - pass - except UnicodeEncodeError: - try: - self.win.addnstr(*(ascii_only(obj) for obj in args)) - except (_curses.error, TypeError): - pass + self._addxyz_wrapper(self.win.addnstr, args) def addch(self, *args): - try: - self.win.addch(*args) - except (_curses.error, TypeError): - pass - except UnicodeEncodeError: - try: - self.win.addch(*(ascii_only(obj) for obj in args)) - except (_curses.error, TypeError): - pass + self._addxyz_wrapper(self.win.addch, args) def color(self, *keys): """Change the colors from now on.""" |