Clear necessary lines before rendering

This commit is contained in:
Christian Rocha 2020-01-15 22:41:45 -05:00
parent 7c7c8f7c86
commit fe42b5c4a7
No known key found for this signature in database
GPG Key ID: D6CC7A16E5878018
2 changed files with 7 additions and 3 deletions

View File

@ -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 {

8
tea.go
View File

@ -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)
}
}