fix: ensure terminal state is restored after panics in Batch/Sequence commands (#1818)

Co-authored-by: TRAE AI Assistant <trae@bytedance.com>
Co-authored-by: Drew Smirnoff <drew@charm.land>
This commit is contained in:
Wu Shuwen 2026-11-12 21:24:49 +08:00 committed by GitHub
parent 73b79b3737
commit f3d74b724c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

6
tea.go
View file

@ -1394,14 +1394,14 @@ func (p *Program) recoverFromPanic(r interface{}) {
}
}
// recoverFromGoPanic recovers from a goroutine panic, prints a stack trace and
// signals for the program to be killed and terminal restored to a usable state.
// recoverFromGoPanic recovers from a goroutine panic, prints a stack trace,
// restores the terminal to a usable state, and signals the program to be killed.
func (p *Program) recoverFromGoPanic(r interface{}) {
select {
case p.errs <- ErrProgramPanic:
default:
}
p.cancel()
p.shutdown(true)
// We use "\r\n" to ensure the output is formatted even when restoring the
// terminal does not work or when raw mode is still active.
rec := strings.ReplaceAll(fmt.Sprintf("%s", r), "\n", "\r\n")