From 62f5502f7ba4f80f814f04f6fe2b07a5e25b38b0 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sun, 10 Oct 2021 22:40:26 -0700 Subject: [PATCH] fixes #485 Optimize screen.Clear() (#491) --- tscreen.go | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/tscreen.go b/tscreen.go index 1cffedf..2c161cc 100644 --- a/tscreen.go +++ b/tscreen.go @@ -341,13 +341,13 @@ func (t *tScreen) prepareCursorStyles() { // via our terminal database. if t.ti.CursorDefault != "" { t.cursorStyles = map[CursorStyle]string{ - CursorStyleDefault: t.ti.CursorDefault, - CursorStyleBlinkingBlock: t.ti.CursorBlinkingBlock, - CursorStyleSteadyBlock: t.ti.CursorSteadyBlock, + CursorStyleDefault: t.ti.CursorDefault, + CursorStyleBlinkingBlock: t.ti.CursorBlinkingBlock, + CursorStyleSteadyBlock: t.ti.CursorSteadyBlock, CursorStyleBlinkingUnderline: t.ti.CursorBlinkingUnderline, - CursorStyleSteadyUnderline: t.ti.CursorSteadyUnderline, - CursorStyleBlinkingBar: t.ti.CursorBlinkingBar, - CursorStyleSteadyBar: t.ti.CursorSteadyBar, + CursorStyleSteadyUnderline: t.ti.CursorSteadyUnderline, + CursorStyleBlinkingBar: t.ti.CursorBlinkingBar, + CursorStyleSteadyBar: t.ti.CursorSteadyBar, } } else if t.ti.Mouse != "" { t.cursorStyles = map[CursorStyle]string{ @@ -358,7 +358,6 @@ func (t *tScreen) prepareCursorStyles() { CursorStyleSteadyUnderline: "\x1b[4 q", CursorStyleBlinkingBar: "\x1b[5 q", CursorStyleSteadyBar: "\x1b[6 q", - } } } @@ -549,6 +548,18 @@ func (t *tScreen) SetStyle(style Style) { func (t *tScreen) Clear() { t.Fill(' ', t.style) + t.Lock() + t.clear = true + w, h := t.cells.Size() + // because we are going to clear (see t.clear) in the next cycle, + // let's also unmark the dirty bit so that we don't waste cycles + // drawing things that are already dealt with via the clear escape sequence. + for row := 0; row < h; row++ { + for col := 0; col < w; col++ { + t.cells.SetDirty(col, row, false) + } + } + t.Unlock() } func (t *tScreen) Fill(r rune, style Style) {