fuzzyworld

template / commit

Fixed piping.

dc7227fadc7ceb0aff5881cca48c8827eca158c8 · Pavel Safronov · 2022-12-10 00:53:21 -0800 · parents 61ec18589dac

Fixed piping.
 main.go | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/main.go b/main.go
index 2a8abd0..b9b5a03 100644
--- a/main.go
+++ b/main.go
@@ -326,13 +326,15 @@ func mainLogic(settings Settings) error {
 		return fmt.Errorf("error finding profile: %v", err)
 	}
 
-	var pipeInputScanner *bufio.Scanner = nil
 	stat, err := os.Stdin.Stat()
 	if err != nil {
 		return fmt.Errorf("error getting stdin stat: %w", err)
 	}
-	if stat.Size() > 0 {
+	var pipeInputScanner *bufio.Scanner = nil
+	incomingPipeData := (stat.Mode() & os.ModeCharDevice) == 0
+	if incomingPipeData {
 		pipeInputScanner = bufio.NewScanner(os.Stdin)
+		fmt.Printf("Reading from stdin\n")
 	}
 
 	// process profile