Clear lines before handing them over to the scrolling renderer

This commit is contained in:
Christian Rocha 2020-06-25 19:22:37 -04:00
parent 8d26b4ebd7
commit f7ec07de3c
No known key found for this signature in database
GPG Key ID: D6CC7A16E5878018
1 changed files with 24 additions and 3 deletions

View File

@ -175,17 +175,38 @@ func (r *renderer) write(s string) {
// setIngoredLines speicifies lines not to be touched by the standard Bubble Tea // setIngoredLines speicifies lines not to be touched by the standard Bubble Tea
// renderer. // renderer.
func (r *renderer) setIgnoredLines(from int, to int) { func (r *renderer) setIgnoredLines(from int, to int) {
// Lock if we're going to be clearing some lines since we don't want
// anything jacking our cursor.
if r.linesRendered > 0 {
r.mtx.Lock()
defer r.mtx.Unlock()
}
if r.ignoreLines == nil { if r.ignoreLines == nil {
r.ignoreLines = make(map[int]struct{}) r.ignoreLines = make(map[int]struct{})
} }
for i := from; i < to; i++ { for i := from; i < to; i++ {
r.ignoreLines[i] = struct{}{} r.ignoreLines[i] = struct{}{}
} }
// Erase ignored lines
if r.linesRendered > 0 {
out := new(bytes.Buffer)
for i := r.linesRendered - 1; i >= 0; i-- {
if _, exists := r.ignoreLines[i]; exists {
clearLine(out)
}
cursorUp(out)
}
moveCursor(out, r.linesRendered, 0) // put cursor back
r.out.Write(out.Bytes())
}
} }
// clearIgnoredLines sets all lines to be rendered by the standard Bubble // clearIgnoredLines returns control of any ignored lines to the standard
// Tea renderer. Any lines previously set to be ignored can be rendered to // Bubble Tea renderer. That is, any lines previously set to be ignored can be
// again. // rendered to again.
func (r *renderer) clearIgnoredLines() { func (r *renderer) clearIgnoredLines() {
r.ignoreLines = nil r.ignoreLines = nil
} }