Files
aicli/input/stdin.go
Jay 1936f055e2
All checks were successful
Release / release (push) Successful in 3m17s
Refactored, added comprehensive testing.
2025-10-26 23:23:43 -04:00

29 lines
563 B
Go

package input
import (
"io"
"os"
)
// DetectStdin checks if stdin contains piped data and reads it.
// Returns content and true if stdin is a pipe/file, empty string and false if terminal.
func DetectStdin() (string, bool) {
stat, err := os.Stdin.Stat()
if err != nil {
return "", false
}
// Terminal (character device) = no stdin data
if (stat.Mode() & os.ModeCharDevice) != 0 {
return "", false
}
// Pipe or file redirection detected
content, err := io.ReadAll(os.Stdin)
if err != nil {
return "", false
}
return string(content), true
}