From 11006d0a904268aa06486c2eebd6c3dfedeb2b3c Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Sat, 18 Jan 2020 10:36:39 -0500 Subject: [PATCH] Move last render height info to the program level --- tea.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/tea.go b/tea.go index 4fdcf52..c54af21 100644 --- a/tea.go +++ b/tea.go @@ -10,9 +10,6 @@ import ( "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. type Msg interface{} @@ -39,6 +36,7 @@ type Program struct { view View subscriptions []Sub rw io.ReadWriter + linesRendered int } // 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 view = strings.Replace(view, "\n", "\r\n", -1) - if linesRendered > 0 { - clearLines(linesRendered) + if p.linesRendered > 0 { + clearLines(p.linesRendered) } 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