mirror of
https://github.com/fiatjaf/nak.git
synced 2024-11-22 08:19:06 -05:00
fix pipe check.
This commit is contained in:
parent
78932833df
commit
6f72d3c133
14
helpers.go
14
helpers.go
|
@ -20,17 +20,17 @@ const (
|
||||||
func getStdinLinesOrBlank() chan string {
|
func getStdinLinesOrBlank() chan string {
|
||||||
ch := make(chan string)
|
ch := make(chan string)
|
||||||
go func() {
|
go func() {
|
||||||
r := bufio.NewReader(os.Stdin)
|
if stat, _ := os.Stdin.Stat(); stat.Mode()&os.ModeCharDevice == 0 {
|
||||||
if _, err := r.Peek(1); err != nil {
|
// piped
|
||||||
ch <- ""
|
scanner := bufio.NewScanner(os.Stdin)
|
||||||
close(ch)
|
|
||||||
} else {
|
|
||||||
scanner := bufio.NewScanner(r)
|
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
ch <- scanner.Text()
|
ch <- scanner.Text()
|
||||||
}
|
}
|
||||||
close(ch)
|
} else {
|
||||||
|
// not piped
|
||||||
|
ch <- ""
|
||||||
}
|
}
|
||||||
|
close(ch)
|
||||||
}()
|
}()
|
||||||
return ch
|
return ch
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user