From 8783bedb353dae5bd5e78b3e210ae68148d7eaf8 Mon Sep 17 00:00:00 2001 From: Sangharsha <67364489+noob6t5@users.noreply.github.com> Date: Wed, 30 Jul 2025 16:37:42 +0545 Subject: [PATCH] Solved issue for without piped input --- main.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/main.go b/main.go index 58d2049..f1a16dc 100644 --- a/main.go +++ b/main.go @@ -51,6 +51,20 @@ func main() { } } + // ==== ADDED BLOCK: check if stdin is a terminal and bail if yes ==== + fi, err := os.Stdin.Stat() + if err != nil { + fmt.Fprintf(os.Stderr, "failed to stat stdin: %v\n", err) + os.Exit(1) + } + + if (fi.Mode() & os.ModeCharDevice) != 0 { + fmt.Fprintln(os.Stderr, "anew: expects input via pipe or redirection. Example:") + fmt.Fprintln(os.Stderr, " cat newthings.txt | anew things.txt") + os.Exit(1) + } + // ==== END ADDED BLOCK ==== + // read the lines, append and output them if they're new sc := bufio.NewScanner(os.Stdin) @@ -76,3 +90,4 @@ func main() { } } } +