fix: dont go interactive if not terminal (closes #48)

pull/59/head
sammyette 2021-06-01 22:13:33 -04:00
parent 7e970e9e81
commit 1623f0d85d
No known key found for this signature in database
GPG Key ID: 50EE40A2809851F5
1 changed files with 12 additions and 0 deletions

12
main.go
View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"bufio"
"fmt" "fmt"
"io" "io"
"os" "os"
@ -61,6 +62,10 @@ func main() {
interactive = true interactive = true
} }
if fileInfo, _ := os.Stdin.Stat(); (fileInfo.Mode() & os.ModeCharDevice) == 0 {
interactive = false
}
if getopt.NArgs() > 0 { if getopt.NArgs() > 0 {
interactive = false interactive = false
} }
@ -115,6 +120,13 @@ func main() {
lr = NewLineReader("") lr = NewLineReader("")
if fileInfo, _ := os.Stdin.Stat(); (fileInfo.Mode() & os.ModeCharDevice) == 0 {
scanner := bufio.NewScanner(bufio.NewReader(os.Stdin))
for scanner.Scan() {
RunInput(scanner.Text())
}
}
if *cmdflag != "" { if *cmdflag != "" {
RunInput(*cmdflag) RunInput(*cmdflag)
} }