From fe42b5c4a797a0fa0cc6a4c75a1cce1984527146 Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Wed, 15 Jan 2020 22:41:45 -0500 Subject: [PATCH] Clear necessary lines before rendering --- examples/views/main.go | 2 +- tea.go | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/examples/views/main.go b/examples/views/main.go index 2572288..d42ba88 100644 --- a/examples/views/main.go +++ b/examples/views/main.go @@ -186,7 +186,7 @@ func chosenView(m Model) string { label = fmt.Sprintf("Downloaded. Exiting in %d...", m.Ticks) } - return msg + "\n\n\n\n\n\n " + label + "\n" + progressbar(80, m.Progress) + "%" + return msg + "\n\n " + label + "\n" + progressbar(80, m.Progress) + "%" } func checkbox(label string, checked bool) string { diff --git a/tea.go b/tea.go index 6c90265..cc042d7 100644 --- a/tea.go +++ b/tea.go @@ -11,6 +11,9 @@ import ( // Escape sequence const esc = "\033[" +// 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{} @@ -150,9 +153,10 @@ func (p *Program) render(model Model, init bool) { view = strings.Replace(view, "\n", "\r\n", -1) if !init { - clearLines(strings.Count(view, "\r\n")) + clearLines(linesRendered) } io.WriteString(p.rw, view) + linesRendered = strings.Count(view, "\r\n") } // Hide the cursor @@ -178,8 +182,8 @@ func clearLine() { // Clear a given number of lines func clearLines(n int) { for i := 0; i < n; i++ { - cursorUp(1) clearLine() + cursorUp(1) } }