mirror of
https://github.com/taigrr/bubbletea.git
synced 2026-04-02 02:59:09 -07:00
fix(regression): auto-open a TTY when stdin is not a TTY (#746)
The regression was introduced in precisely this revision:
fcc805f3da
Closes #745.
This commit is contained in:
32
tea.go
32
tea.go
@@ -392,20 +392,12 @@ func (p *Program) Run() (Model, error) {
|
|||||||
case defaultInput:
|
case defaultInput:
|
||||||
p.input = os.Stdin
|
p.input = os.Stdin
|
||||||
|
|
||||||
case ttyInput:
|
// The user has not set a custom input, so we need to check whether or
|
||||||
// Open a new TTY, by request
|
// not standard input is a terminal. If it's not, we open a new TTY for
|
||||||
f, err := openInputTTY()
|
// input. This will allow things to "just work" in cases where data was
|
||||||
if err != nil {
|
// piped in or redirected to the application.
|
||||||
return p.initialModel, err
|
//
|
||||||
}
|
// To disable input entirely pass nil to the [WithInput] program option.
|
||||||
defer f.Close() //nolint:errcheck
|
|
||||||
p.input = f
|
|
||||||
|
|
||||||
case customInput:
|
|
||||||
// If the user hasn't set a custom input, and input's not a terminal,
|
|
||||||
// open a TTY so we can capture input as normal. This will allow things
|
|
||||||
// to "just work" in cases where data was piped or redirected into this
|
|
||||||
// application.
|
|
||||||
f, isFile := p.input.(*os.File)
|
f, isFile := p.input.(*os.File)
|
||||||
if !isFile {
|
if !isFile {
|
||||||
break
|
break
|
||||||
@@ -420,6 +412,18 @@ func (p *Program) Run() (Model, error) {
|
|||||||
}
|
}
|
||||||
defer f.Close() //nolint:errcheck
|
defer f.Close() //nolint:errcheck
|
||||||
p.input = f
|
p.input = f
|
||||||
|
|
||||||
|
case ttyInput:
|
||||||
|
// Open a new TTY, by request
|
||||||
|
f, err := openInputTTY()
|
||||||
|
if err != nil {
|
||||||
|
return p.initialModel, err
|
||||||
|
}
|
||||||
|
defer f.Close() //nolint:errcheck
|
||||||
|
p.input = f
|
||||||
|
|
||||||
|
case customInput:
|
||||||
|
// (There is nothing extra to do.)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle signals.
|
// Handle signals.
|
||||||
|
|||||||
Reference in New Issue
Block a user