Move last render height info to the program level

This commit is contained in:
Christian Rocha 2020-01-18 10:36:39 -05:00
parent b72cce8f00
commit 11006d0a90
No known key found for this signature in database
GPG Key ID: D6CC7A16E5878018
1 changed files with 4 additions and 6 deletions

10
tea.go
View File

@ -10,9 +10,6 @@ import (
"github.com/pkg/term" "github.com/pkg/term"
) )
// The number of lines we last rendered
var linesRendered = 0
// Msg represents an action. It's used by Update to update the UI. // Msg represents an action. It's used by Update to update the UI.
type Msg interface{} type Msg interface{}
@ -39,6 +36,7 @@ type Program struct {
view View view View
subscriptions []Sub subscriptions []Sub
rw io.ReadWriter rw io.ReadWriter
linesRendered int
} }
// ErrMsg is just a regular message containing an error. We handle it in Update // ErrMsg is just a regular message containing an error. We handle it in Update
@ -165,11 +163,11 @@ func (p *Program) render(model Model) {
// start of a column after a newline // start of a column after a newline
view = strings.Replace(view, "\n", "\r\n", -1) view = strings.Replace(view, "\n", "\r\n", -1)
if linesRendered > 0 { if p.linesRendered > 0 {
clearLines(linesRendered) clearLines(p.linesRendered)
} }
io.WriteString(p.rw, view) io.WriteString(p.rw, view)
linesRendered = strings.Count(view, "\r\n") p.linesRendered = strings.Count(view, "\r\n")
} }
// UseSysLog sets up logging to log the system log. This becomes helpful when // UseSysLog sets up logging to log the system log. This becomes helpful when