From e9cd4c445818726446a59db550331fc296046194 Mon Sep 17 00:00:00 2001 From: Michael Lazar Date: Fri, 6 Jan 2017 22:47:29 -0800 Subject: [PATCH 1/2] Add safety check for terminals without cursor support. --- rtv/objects.py | 6 +++++- rtv/terminal.py | 20 +++++++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) 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) From f3deea5abc06f7b22830a313f90929cbd8eac0b0 Mon Sep 17 00:00:00 2001 From: Michael Lazar Date: Tue, 10 Jan 2017 18:36:44 -0800 Subject: [PATCH 2/2] Fix bug in tmux when TERM is set to xterm-256color --- rtv/page.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/rtv/page.py b/rtv/page.py index d0cef8d..f3dd17a 100644 --- a/rtv/page.py +++ b/rtv/page.py @@ -341,7 +341,14 @@ class Page(object): self._draw_content() self._draw_footer() self._add_cursor() - self.term.stdscr.touchwin() + # Note: There used to be a call to stdscr.touchwin() here. However, a + # bug was discovered in tmux when $TERM was set to `xterm-256color`, + # where only part of the screen got redrawn when scrolling. The correct + # solution is to use `screen-256color` (which gets set automatically by + # tmux) but many people override ther $TERM in their tmux.conf or + # .bashrc file. Using clearok() instead seems to fix the problem, at + # the expense of slightly more expensive screen refreshes. + self.term.stdscr.clearok(True) self.term.stdscr.refresh() def _draw_header(self):