michael-lazar / rtv

Browse Reddit from your terminal
MIT License
4.65k stars 278 forks source link

Lag/Jitter Issue for Redraws upon page-scrolling keypresses #656

Closed mightymiff closed 5 years ago

mightymiff commented 5 years ago

Do you know what causes the jitter on button presses? I am not quite sure what happens, but it seems like there is a redraw that blanks the screen for a fraction of a second after almost every button press, such as when scrolling through Reddit submissions with the j/k keys.

As someone who is visually sensitive, this is something of a bother, and it would be much appreciated if you had a moment to look into it at some point. Interestingly when the redraws involve scrolling to content not immediately visible on the page (think: page-down vs arrow-down), the redraw is not always noticeable, and the redraw is also less noticeable when scrolling up vs. when scrolling down.

This does not appear to be a terminal issue as no such jitter occurs in any other application (such as w3m) and it appears to follow a cyclical pattern (I refer here to a predictable lag/jitter pattern such as: long-long-long-short-no lag, repeat) within RTV.

Anyone else experience this?

michael-lazar commented 5 years ago

Curses tries its best to optimize redrawing characters to the screen, but how this actually happens under the hood depends on the specific capabilities that are exposed by your terminal (terminfo). It sounds like your terminal/environment is forcing the whole screen to clear instead of intelligently overwriting the characters that have changed.

What specific terminal are you using? Is your $TERM setting being overridden in your profile or .bashrc?

mightymiff commented 5 years ago

Thanks for the reply and linking related issues.

I am running urxvt and my TERM is set to xterm-256color. I DO specify my term name in my .Xresources file: URxvt.termName: xterm-256color . I am not running a terminal multiplexer.

So far no luck fixing the issue by messing with redraw calls referenced in the other issues. Will let you know if I get a chance to explore more freely.

    def draw(self):                                                             
        """                                                                     
        Clear the terminal screen and redraw all of the sub-windows             
        """                                                                     
        n_rows, n_cols = self.term.stdscr.getmaxyx()                            
        if n_rows < self.term.MIN_HEIGHT or n_cols < self.term.MIN_WIDTH:       
            # TODO: Will crash when you try to navigate if the terminal is too  
            # small at startup because self._subwindows will never be populated 
            return                                                              

        self._row = 0                                                           
        self._draw_header()                                                     
        self._draw_banner()                                                     
        self._draw_content()                                                    
        self._draw_footer()                                                     
        # self.term.stdscr.touchwin()                                           
        # self.term.clear_screen()                                                
        self.term.stdscr.clearok(True)                                          
        self.term.stdscr.refresh()
mightymiff commented 5 years ago

I spoke too soon. The issue appears to be fully resolved with the configuration below. Thank you. Great tool, by the way, :).

    def draw(self):                                                             
        """                                                                     
        Clear the terminal screen and redraw all of the sub-windows             
        """                                                                     
        n_rows, n_cols = self.term.stdscr.getmaxyx()                            
        if n_rows < self.term.MIN_HEIGHT or n_cols < self.term.MIN_WIDTH:       
            # TODO: Will crash when you try to navigate if the terminal is too  
            # small at startup because self._subwindows will never be populated 
            return                                                              

        self._row = 0                                                           
        self._draw_header()                                                     
        self._draw_banner()                                                     
        self._draw_content()                                                    
        self._draw_footer()                                                     
        self.term.stdscr.touchwin()                                             
        #self.term.clear_screen()                                               
        #self.term.stdscr.clearok(True)                                         
        self.term.stdscr.refresh()  
michael-lazar commented 5 years ago

Awesome! I suspect you could have also fixed you problem by switching from xterm-256color to rxvt-unicode (link) or the equivalent package in your distro.