forked from Mirrors/bubbletea
Remove an extraneous var and rename another var for clarity
This commit is contained in:
parent
99df3d4226
commit
e7130c9633
16
tea.go
16
tea.go
|
@ -47,9 +47,8 @@ type Program struct {
|
||||||
update Update
|
update Update
|
||||||
view View
|
view View
|
||||||
|
|
||||||
mutex sync.Mutex
|
mutex sync.Mutex
|
||||||
linesRendered int
|
currentRender string
|
||||||
contentRendered string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Quit is a command that tells the program to exit.
|
// Quit is a command that tells the program to exit.
|
||||||
|
@ -163,11 +162,12 @@ func (p *Program) render(model Model) {
|
||||||
view := p.view(model)
|
view := p.view(model)
|
||||||
|
|
||||||
// The view hasn't changed; no need to render
|
// The view hasn't changed; no need to render
|
||||||
if view == p.contentRendered {
|
if view == p.currentRender {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
p.contentRendered = view
|
p.currentRender = view
|
||||||
|
linesRendered := strings.Count(p.currentRender, "\r\n")
|
||||||
|
|
||||||
// Add carriage returns to ensure that the cursor travels to the start of a
|
// Add carriage returns to ensure that the cursor travels to the start of a
|
||||||
// column after a newline. Keep in mind that this means that in the rest
|
// column after a newline. Keep in mind that this means that in the rest
|
||||||
|
@ -175,13 +175,11 @@ func (p *Program) render(model Model) {
|
||||||
view = strings.Replace(view, "\n", "\r\n", -1)
|
view = strings.Replace(view, "\n", "\r\n", -1)
|
||||||
|
|
||||||
p.mutex.Lock()
|
p.mutex.Lock()
|
||||||
if p.linesRendered > 0 {
|
if linesRendered > 0 {
|
||||||
termenv.ClearLines(p.linesRendered)
|
termenv.ClearLines(linesRendered)
|
||||||
}
|
}
|
||||||
_, _ = io.WriteString(os.Stdout, view)
|
_, _ = io.WriteString(os.Stdout, view)
|
||||||
p.mutex.Unlock()
|
p.mutex.Unlock()
|
||||||
|
|
||||||
p.linesRendered = strings.Count(view, "\r\n")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// AltScreen exits the altscreen. This is just a wrapper around the termenv
|
// AltScreen exits the altscreen. This is just a wrapper around the termenv
|
||||||
|
|
Loading…
Reference in New Issue