forked from Mirrors/bubbletea
Better logic in input checks
This commit is contained in:
parent
9f9b3aea96
commit
30fd7a8f20
22
tea.go
22
tea.go
|
@ -272,29 +272,35 @@ func (p *Program) Start() error {
|
||||||
p.outputIsTTY = isatty.IsTerminal(f.Fd())
|
p.outputIsTTY = isatty.IsTerminal(f.Fd())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case p.startupOptions.has(withInputTTY):
|
||||||
// Open a new TTY, by request
|
// Open a new TTY, by request
|
||||||
if p.startupOptions.has(withInputTTY) {
|
|
||||||
f, err := openInputTTY()
|
f, err := openInputTTY()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
p.input = f
|
p.input = f
|
||||||
|
|
||||||
|
case !p.startupOptions.has(withCustomInput):
|
||||||
|
// 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)
|
||||||
|
if !isFile {
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
// If input is not a terminal, and the user hasn't set a custom input, open
|
if isatty.IsTerminal(f.Fd()) {
|
||||||
// a TTY so we can capture input as normal. This will allow things to "just
|
break
|
||||||
// work" in cases where data was piped or redirected into this application.
|
}
|
||||||
if f, ok := p.input.(*os.File); ok {
|
|
||||||
inputIsTTY := isatty.IsTerminal(f.Fd())
|
|
||||||
|
|
||||||
if !inputIsTTY && !p.startupOptions.has(withCustomInput) {
|
|
||||||
f, err := openInputTTY()
|
f, err := openInputTTY()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
p.input = f
|
p.input = f
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Listen for SIGINT. Note that in most cases ^C will not send an
|
// Listen for SIGINT. Note that in most cases ^C will not send an
|
||||||
// interrupt because the terminal will be in raw mode and thus capture
|
// interrupt because the terminal will be in raw mode and thus capture
|
||||||
|
|
Loading…
Reference in New Issue