fix: close the TTY files opened for input when Run returns (#1855)
Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
12b7b4d0eb
commit
13fb42d8ea
1 changed files with 8 additions and 1 deletions
9
tea.go
9
tea.go
|
|
@ -1083,10 +1083,17 @@ func (p *Program) Run() (returnModel Model, returnErr error) {
|
|||
} else if p.input == nil {
|
||||
p.input = os.Stdin
|
||||
if !term.IsTerminal(os.Stdin.Fd()) {
|
||||
ttyIn, _, err := OpenTTY()
|
||||
ttyIn, ttyOut, err := OpenTTY()
|
||||
if err != nil {
|
||||
return p.initialModel, fmt.Errorf("bubbletea: error opening TTY: %w", err)
|
||||
}
|
||||
// Nothing else owns these files: close them when Run returns so
|
||||
// each Run doesn't leak a /dev/tty fd (on Windows, CONIN$ and
|
||||
// CONOUT$ handles).
|
||||
defer func() {
|
||||
_ = ttyIn.Close()
|
||||
_ = ttyOut.Close()
|
||||
}()
|
||||
p.input = ttyIn
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue