disable interactive when stdin is not a tty

This commit is contained in:
Cheney 2016-02-18 13:08:19 +08:00
parent 15e7be4ac2
commit 8181d5ed14
1 changed files with 8 additions and 1 deletions

View File

@ -48,6 +48,7 @@ type Config struct {
UniqueEditLine bool
// force use interactive even stdout is not a tty
StdinFd int
StdoutFd int
ForceUseInteractive bool
@ -58,7 +59,10 @@ type Config struct {
}
func (c *Config) useInteractive() bool {
return c.ForceUseInteractive || IsTerminal(c.StdoutFd)
if c.ForceUseInteractive {
return true
}
return IsTerminal(c.StdoutFd) && IsTerminal(c.StdinFd)
}
func (c *Config) Init() error {
@ -75,6 +79,9 @@ func (c *Config) Init() error {
if c.Stderr == nil {
c.Stderr = Stderr
}
if c.StdinFd == 0 {
c.StdinFd = StdinFd
}
if c.StdoutFd == 0 {
c.StdoutFd = StdoutFd
}