fix: remove resetLinesRendered calls around exec

Resetting the lines rendered around exec was causing issues with cursor
position after exec commands. For example, if you want to persist the
output of your program after an exec command that uses the altscreen,
this would break that functionality.

We really need to choose one behavior or the other here, and I think
removing these calls is the right choice.

Reference: https://github.com/charmbracelet/bubbletea/pull/1276
Reference: https://github.com/charmbracelet/bubbletea/issues/1275
This commit is contained in:
Ayman Bagabas 2025-10-14 13:34:51 -04:00
parent d5c30299df
commit 78e3b36c60
No known key found for this signature in database
GPG key ID: C8D51D2157C919AC
5 changed files with 1 additions and 29 deletions

View file

@ -228,21 +228,6 @@ func (s *cursedRenderer) writeString(str string) (int, error) {
return s.scr.WriteString(str) //nolint:wrapcheck
}
// resetLinesRendered implements renderer.
func (s *cursedRenderer) resetLinesRendered() {
s.mu.Lock()
defer s.mu.Unlock()
if s.lastView != nil && !s.lastView.AltScreen {
var frameHeight int
if s.lastFrame != nil {
frameHeight = strings.Count(*s.lastFrame, "\n") + 1
}
io.WriteString(s.w, strings.Repeat("\n", max(0, frameHeight-1))) //nolint:errcheck,gosec
}
}
// flush implements renderer.
func (s *cursedRenderer) flush() error {
s.mu.Lock()

View file

@ -114,7 +114,6 @@ func (p *Program) exec(c ExecCommand, fn ExecCallback) {
// Execute system command.
if err := c.Run(); err != nil {
p.renderer.resetLinesRendered()
_ = p.RestoreTerminal() // also try to restore the terminal.
if fn != nil {
go p.Send(fn(err))
@ -122,9 +121,6 @@ func (p *Program) exec(c ExecCommand, fn ExecCallback) {
return
}
// Maintain the existing output from the command
p.renderer.resetLinesRendered()
// Have the program re-capture input.
err := p.RestoreTerminal()
if fn != nil {

View file

@ -42,11 +42,6 @@ type spyRenderer struct {
calledReset bool
}
func (r *spyRenderer) resetLinesRendered() {
r.calledReset = true
r.renderer.resetLinesRendered()
}
func TestTeaExec(t *testing.T) {
type test struct {
name string

View file

@ -56,5 +56,4 @@ func (nilRenderer) reset() {}
func (nilRenderer) writeString(string) (int, error) { return 0, nil }
// hit implements the Renderer interface.
func (n nilRenderer) hit(MouseMsg) []Msg { return nil }
func (n nilRenderer) resetLinesRendered() {}
func (n nilRenderer) hit(MouseMsg) []Msg { return nil }

View file

@ -61,9 +61,6 @@ type renderer interface {
repaint()
writeString(string) (int, error)
// resetLinesRendered ensures exec output remains on screen on exit
resetLinesRendered()
}
// repaintMsg forces a full repaint.