mirror of https://github.com/mickael-menu/zk
Don't prompt the user when the terminal is not interactive
parent
eb130a8107
commit
1b905dacfd
@ -0,0 +1,22 @@
|
|||||||
|
package term
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/mattn/go-isatty"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Terminal offers utilities to interact with the terminal.
|
||||||
|
type Terminal struct {
|
||||||
|
NoInput bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func New() *Terminal {
|
||||||
|
return &Terminal{}
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsInteractive returns whether the app is attached to an interactive terminal
|
||||||
|
// and can prompt the user.
|
||||||
|
func (t *Terminal) IsInteractive() bool {
|
||||||
|
return !t.NoInput && isatty.IsTerminal(os.Stdin.Fd())
|
||||||
|
}
|
@ -1,9 +0,0 @@
|
|||||||
package tty
|
|
||||||
|
|
||||||
type TTY struct {
|
|
||||||
NoInput bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func New() *TTY {
|
|
||||||
return &TTY{}
|
|
||||||
}
|
|
Loading…
Reference in New Issue