@@ -666,6 +666,9 @@ func (p *Pager) StartPaging(screen twin.Screen, chromaStyle *chroma.Style, chrom
666666
667667 log .Info ("Entering pager main loop..." )
668668
669+ paintedWhileReading := false
670+ paintedAfter := time .Duration (0 )
671+
669672 // Main loop
670673 spinner := ""
671674 for ! p .quit {
@@ -696,23 +699,40 @@ func (p *Pager) StartPaging(screen twin.Screen, chromaStyle *chroma.Style, chrom
696699 p .DeInit = false // Makes ReprintAfterExit() be called on the way out
697700 p .quit = true
698701
699- log .Info ("Exiting because of --quit-if-one-screen, everything fit on one screen and we're done" )
702+ if paintedWhileReading {
703+ log .Warnf ("--quit-if-one-screen blinked: input was still arriving after %s so we painted rather than wait, all of it had arrived after %s" ,
704+ paintedAfter , time .Since (r .StartedAt ))
705+ } else {
706+ log .Info ("Exiting because of --quit-if-one-screen: everything fits on one screen" )
707+ }
700708
701709 // Exit the main loop
702710 break
703711 }
704712
705- // Highlighting can still grow the contents past one screen, so we
706- // don't know yet whether we are staying. Painting now and quitting
707- // right after is the blink of issue #425, so paint nothing and let
708- // the event read below wait for highlighting instead: it signals
709- // MaybeDone when it lands.
713+ // Two things can still flip canQuit from "yes" to "no":
714+ // highlighting and reading (we don't know the final count until
715+ // it's done). We hold the paint below for highlighting, since it's
716+ // fast and bounded, but not for reading: a slow or endless producer
717+ // would otherwise leave the screen blank forever. So when reading
718+ // is the only thing still pending, we paint immediately and risk
719+ // the blink from issue #464, instead of holding out the way #425's
720+ // fix does for highlighting.
710721 //
711722 // Somebody who is interacting gets painted for regardless, which
712723 // also means a reader that never finishes highlighting costs them a
713724 // keypress rather than the whole session.
714725 holdPaint := canQuit && ! p .sawUserInput
715726 if ! holdPaint {
727+ quitIfOneScreenApplies := p .QuitIfOneScreen && ! p .isShowingHelp && len (p .readers ) == 1
728+ stillReading := ! r .ReadingDone .Load ()
729+ if quitIfOneScreenApplies && stillReading && ! paintedWhileReading {
730+ // Remembered so that if this does turn into the #464
731+ // blink, the warning above can say how early we painted.
732+ paintedWhileReading = true
733+ paintedAfter = time .Since (r .StartedAt )
734+ }
735+
716736 p .redraw (spinner )
717737 }
718738 }
0 commit comments