Standard input is the conventional stream a command-line process reads from. In a terminal game, it carries the player’s typed guess after Enter is pressed. section 5.0 section 5.1.2
A Go program can turn terminal input into a validated game value through a short pipeline:
- Pass os.Stdin to the game constructor as an io.Reader. section 5.1.2
- Wrap that reader with bufio.NewReader for buffered line reading. section 5.1.2
- Call ReadLine to obtain one attempted guess at a time. section 5.1.2
- Convert the input to []rune so character counts support Unicode words. section 5.1.2
- Report read errors or invalid lengths, then continue prompting until the guess is acceptable. section 5.1.2
Connecting a terminal to a game
g := gordle.New(os.Stdin) g.Play() The game reads a line such as "apple" and accepts it when its rune length matches the configured solution length; a four-character input is rejected. section 5.1.2
Listing 5.5 game.go: Using Game with a reader
// Game holds all the information we need to play a game of gordle.
type Game struct {
reader *bufio.Reader
}
The listing shows the Game structure retaining a *bufio.Reader, making standard input an explicit dependency of the game. section 5.1.2




