From 370cfa0642252b80af17d66e87a41a8d6452269e Mon Sep 17 00:00:00 2001 From: Ryan Reno Date: Tue, 20 Jun 2017 21:07:24 -0700 Subject: [PATCH 1/3] Issue #343 Added method to clear screen --- rtv/page.py | 5 ++++- rtv/terminal.py | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/rtv/page.py b/rtv/page.py index d71e597..2235604 100644 --- a/rtv/page.py +++ b/rtv/page.py @@ -397,7 +397,10 @@ class Page(object): # 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) + # However clearok() introduced a screen flash bug to urxvt users so the + # clear_screen() method chooses which of the two stdscr methods to use + # based on the $TERM environment variable + self.term.clear_screen() self.term.stdscr.refresh() def _draw_header(self): diff --git a/rtv/terminal.py b/rtv/terminal.py index 401f942..df1a4c4 100644 --- a/rtv/terminal.py +++ b/rtv/terminal.py @@ -769,3 +769,11 @@ class Terminal(object): out = '\n'.join(stack) return out + + # Resolves tmux touchwin() bug and urxvt clearok() flashing bug + def clear_screen(self): + if os.environ['TERM'] is not 'xterm-256color': + self.stdscr.touchwin() + else: + self.stdscr.clearok(True) + \ No newline at end of file From 7739d31b116c74a7e0caad682278d2967158546d Mon Sep 17 00:00:00 2001 From: Ryan Reno Date: Thu, 22 Jun 2017 19:06:04 -0700 Subject: [PATCH 2/3] #343 added attribute to hold rxvt-unicode-256color variable instead of calling os.environ every time the screen is cleared. Also changed 'is not' to != in if statement --- rtv/terminal.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/rtv/terminal.py b/rtv/terminal.py index df1a4c4..96698e9 100644 --- a/rtv/terminal.py +++ b/rtv/terminal.py @@ -59,6 +59,7 @@ class Terminal(object): self.loader = LoadScreen(self) self._display = None self._mailcap_dict = mailcap.getcaps() + self._term = os.environ['TERM'] @property def up_arrow(self): @@ -772,8 +773,8 @@ class Terminal(object): # Resolves tmux touchwin() bug and urxvt clearok() flashing bug def clear_screen(self): - if os.environ['TERM'] is not 'xterm-256color': + if self._term != 'xterm-256color': self.stdscr.touchwin() else: self.stdscr.clearok(True) - \ No newline at end of file + From 4ff822373b7daf105129b99303541bf293a3ebfb Mon Sep 17 00:00:00 2001 From: Michael Lazar Date: Tue, 27 Jun 2017 23:20:05 -0400 Subject: [PATCH 3/3] Moving comments to docstrings --- rtv/page.py | 10 ---------- rtv/terminal.py | 23 +++++++++++++++++++++-- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/rtv/page.py b/rtv/page.py index 2235604..1ee6611 100644 --- a/rtv/page.py +++ b/rtv/page.py @@ -390,16 +390,6 @@ class Page(object): self._draw_content() self._draw_footer() self._add_cursor() - # 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. - # However clearok() introduced a screen flash bug to urxvt users so the - # clear_screen() method chooses which of the two stdscr methods to use - # based on the $TERM environment variable self.term.clear_screen() self.term.stdscr.refresh() diff --git a/rtv/terminal.py b/rtv/terminal.py index 96698e9..6ff4526 100644 --- a/rtv/terminal.py +++ b/rtv/terminal.py @@ -771,10 +771,29 @@ class Terminal(object): out = '\n'.join(stack) return out - # Resolves tmux touchwin() bug and urxvt clearok() flashing bug def clear_screen(self): + """ + In the beginning this always called touchwin(). However, a bug + was discovered in tmux when TERM was set to `xterm-256color`, where + only part of the screen got redrawn when scrolling. tmux automatically + sets TERM to `screen-256color`, but many people choose to override + this in their tmux.conf or .bashrc file which can cause issues. + Using clearok() instead seems to fix the problem, with the trade off + of slightly more expensive screen refreshes. + + Update: It was discovered that using clearok() introduced a + separate bug for urxvt users in which their screen flashed when + scrolling. Heuristics were added to make it work with as many + configurations as possible. It's still not perfect + (e.g. urxvt + xterm-256color) will screen flash, but it should + work in all cases if the user sets their TERM correctly. + + Reference: + https://github.com/michael-lazar/rtv/issues/343 + https://github.com/michael-lazar/rtv/issues/323 + """ + if self._term != 'xterm-256color': self.stdscr.touchwin() else: self.stdscr.clearok(True) -