forked from Mirrors/bubbletea
Clear necessary lines before rendering
This commit is contained in:
parent
7c7c8f7c86
commit
fe42b5c4a7
|
@ -186,7 +186,7 @@ func chosenView(m Model) string {
|
||||||
label = fmt.Sprintf("Downloaded. Exiting in %d...", m.Ticks)
|
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 {
|
func checkbox(label string, checked bool) string {
|
||||||
|
|
8
tea.go
8
tea.go
|
@ -11,6 +11,9 @@ import (
|
||||||
// Escape sequence
|
// Escape sequence
|
||||||
const esc = "\033["
|
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.
|
// Msg represents an action. It's used by Update to update the UI.
|
||||||
type Msg interface{}
|
type Msg interface{}
|
||||||
|
|
||||||
|
@ -150,9 +153,10 @@ func (p *Program) render(model Model, init bool) {
|
||||||
view = strings.Replace(view, "\n", "\r\n", -1)
|
view = strings.Replace(view, "\n", "\r\n", -1)
|
||||||
|
|
||||||
if !init {
|
if !init {
|
||||||
clearLines(strings.Count(view, "\r\n"))
|
clearLines(linesRendered)
|
||||||
}
|
}
|
||||||
io.WriteString(p.rw, view)
|
io.WriteString(p.rw, view)
|
||||||
|
linesRendered = strings.Count(view, "\r\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hide the cursor
|
// Hide the cursor
|
||||||
|
@ -178,8 +182,8 @@ func clearLine() {
|
||||||
// Clear a given number of lines
|
// Clear a given number of lines
|
||||||
func clearLines(n int) {
|
func clearLines(n int) {
|
||||||
for i := 0; i < n; i++ {
|
for i := 0; i < n; i++ {
|
||||||
cursorUp(1)
|
|
||||||
clearLine()
|
clearLine()
|
||||||
|
cursorUp(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue