diff --git a/rtv/objects.py b/rtv/objects.py index bfa18bb..eb030b5 100644 --- a/rtv/objects.py +++ b/rtv/objects.py @@ -57,10 +57,14 @@ def curses_session(): try: curses.start_color() except: + _logger.warning('Curses failed to initialize color support') pass # Hide the blinking cursor - curses.curs_set(0) + try: + curses.curs_set(0) + except: + _logger.warning('Curses failed to initialize the cursor mode') # Assign the terminal's default (background) color to code -1 curses.use_default_colors() diff --git a/rtv/terminal.py b/rtv/terminal.py index 28668d2..e6cfc48 100644 --- a/rtv/terminal.py +++ b/rtv/terminal.py @@ -26,7 +26,6 @@ from . import exceptions from . import mime_parsers from .objects import LoadScreen, Color - try: # Added in python 3.4+ from html import unescape @@ -122,6 +121,17 @@ class Terminal(object): """ return curses.flash() + @staticmethod + def curs_set(val): + """ + Change the cursor visibility, may fail for some terminals with limited + cursor support. + """ + try: + curses.curs_set(val) + except: + pass + @staticmethod def addch(window, y, x, ch, attr): """ @@ -628,7 +638,7 @@ class Terminal(object): window.clear() # Set cursor mode to 1 because 2 doesn't display on some terminals - curses.curs_set(1) + self.curs_set(1) # Keep insert_mode off to avoid the recursion error described here # http://bugs.python.org/issue13051 @@ -656,7 +666,7 @@ class Terminal(object): except exceptions.EscapeInterrupt: out = None - curses.curs_set(0) + self.curs_set(0) return self.strip_textpad(out) def prompt_input(self, prompt, key=False): @@ -687,13 +697,13 @@ class Terminal(object): input_win.refresh() if key: - curses.curs_set(1) + self.curs_set(1) ch = self.getch() # We can't convert the character to unicode, because it may return # Invalid values for keys that don't map to unicode characters, # e.g. F1 text = ch if ch != self.ESCAPE else None - curses.curs_set(0) + self.curs_set(0) else: text = self.text_input(input_win)