@@ -258,13 +258,8 @@ func (r *standardRenderer) flush() {
258
258
}
259
259
}
260
260
261
- lastLinesRendered := r .linesRendered
262
- if r .altScreenActive {
263
- lastLinesRendered = r .altLinesRendered
264
- }
265
-
266
261
// Clearing left over content from last render.
267
- if lastLinesRendered > len (newLines ) {
262
+ if r . lastLinesRendered () > len (newLines ) {
268
263
buf .WriteString (ansi .EraseScreenBelow )
269
264
}
270
265
@@ -295,6 +290,14 @@ func (r *standardRenderer) flush() {
295
290
r .buf .Reset ()
296
291
}
297
292
293
+ // lastLinesRendered returns the number of lines rendered lastly.
294
+ func (r * standardRenderer ) lastLinesRendered () int {
295
+ if r .altScreenActive {
296
+ return r .altLinesRendered
297
+ }
298
+ return r .linesRendered
299
+ }
300
+
298
301
// write writes to the internal buffer. The buffer will be outputted via the
299
302
// ticker which calls flush().
300
303
func (r * standardRenderer ) write (s string ) {
@@ -507,7 +510,7 @@ func (r *standardRenderer) setWindowTitle(title string) {
507
510
func (r * standardRenderer ) setIgnoredLines (from int , to int ) {
508
511
// Lock if we're going to be clearing some lines since we don't want
509
512
// anything jacking our cursor.
510
- if r .linesRendered > 0 {
513
+ if r .lastLinesRendered () > 0 {
511
514
r .mtx .Lock ()
512
515
defer r .mtx .Unlock ()
513
516
}
@@ -520,16 +523,17 @@ func (r *standardRenderer) setIgnoredLines(from int, to int) {
520
523
}
521
524
522
525
// Erase ignored lines
523
- if r .linesRendered > 0 {
526
+ lastLinesRendered := r .lastLinesRendered ()
527
+ if lastLinesRendered > 0 {
524
528
buf := & bytes.Buffer {}
525
529
526
- for i := r . linesRendered - 1 ; i >= 0 ; i -- {
530
+ for i := lastLinesRendered - 1 ; i >= 0 ; i -- {
527
531
if _ , exists := r .ignoreLines [i ]; exists {
528
532
buf .WriteString (ansi .EraseEntireLine )
529
533
}
530
534
buf .WriteString (ansi .CursorUp1 )
531
535
}
532
- buf .WriteString (ansi .SetCursorPosition (0 , r . linesRendered )) // put cursor back
536
+ buf .WriteString (ansi .SetCursorPosition (0 , lastLinesRendered )) // put cursor back
533
537
_ , _ = r .out .Write (buf .Bytes ())
534
538
}
535
539
}
@@ -575,7 +579,7 @@ func (r *standardRenderer) insertTop(lines []string, topBoundary, bottomBoundary
575
579
buf .WriteString (ansi .SetScrollingRegion (0 , r .height ))
576
580
577
581
// Move cursor back to where the main rendering routine expects it to be
578
- buf .WriteString (ansi .SetCursorPosition (0 , r .linesRendered ))
582
+ buf .WriteString (ansi .SetCursorPosition (0 , r .lastLinesRendered () ))
579
583
580
584
_ , _ = r .out .Write (buf .Bytes ())
581
585
}
@@ -604,7 +608,7 @@ func (r *standardRenderer) insertBottom(lines []string, topBoundary, bottomBound
604
608
buf .WriteString (ansi .SetScrollingRegion (0 , r .height ))
605
609
606
610
// Move cursor back to where the main rendering routine expects it to be
607
- buf .WriteString (ansi .SetCursorPosition (0 , r .linesRendered ))
611
+ buf .WriteString (ansi .SetCursorPosition (0 , r .lastLinesRendered () ))
608
612
609
613
_ , _ = r .out .Write (buf .Bytes ())
610
614
}
0 commit comments