github.com/stevenmatthewt/agent@v3.5.4+incompatible/stdin/stdin.go (about) 1 package stdin 2 3 import ( 4 "os" 5 ) 6 7 // This is a tricky problem and we have gone through several iterations before 8 // settling on something that works well for recent golang across windows, 9 // linux and macos. 10 11 func IsReadable() bool { 12 fi, err := os.Stdin.Stat() 13 if err != nil { 14 return false 15 } 16 17 // Character devices in Linux/Unix are unbuffered devices that have 18 // direct access to underlying hardware and don't allow reading single characters at a time 19 if (fi.Mode() & os.ModeCharDevice) == os.ModeCharDevice { 20 return false 21 } 22 23 return true 24 }