fix pipe check.

This commit is contained in:
fiatjaf 2023-11-07 23:51:07 -03:00
parent 78932833df
commit 6f72d3c133
No known key found for this signature in database
GPG Key ID: BAD43C4BE5C1A3A1

View File

@ -20,17 +20,17 @@ const (
func getStdinLinesOrBlank() chan string {
ch := make(chan string)
go func() {
r := bufio.NewReader(os.Stdin)
if _, err := r.Peek(1); err != nil {
ch <- ""
close(ch)
} else {
scanner := bufio.NewScanner(r)
if stat, _ := os.Stdin.Stat(); stat.Mode()&os.ModeCharDevice == 0 {
// piped
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
ch <- scanner.Text()
}
close(ch)
} else {
// not piped
ch <- ""
}
close(ch)
}()
return ch
}