For capturing console input, you simply have to read from os.Stdin.
-Daniel
package scan
import ("bufio"; "os")
func Input(str string) string {
print(str)
reader := bufio.NewReader(os.Stdin)
input, _ := reader.ReadString('\n')
return input
Yes. It would work better to do a single bufio.NewReader
and then repeatedly call ReadString. Reading from a bufio.Reader
can read beyond what it returns (it has a buffer), so as written
this Input function will skip over chunks of data when stdin
is a file, because the buffer is discarded every time Input returns.
> func Input(str string) string {
> print(str)
> reader := bufio.NewReader(os.Stdin)
> input, _ := reader.ReadString('\n')
> return input
> }
Russ