gilo/terminal/io.go

34 lines
417 B
Go

package terminal
import (
"bufio"
"fmt"
"os"
)
var reader = bufio.NewReader(os.Stdin)
func ReadKey() (rune, int) {
ch, size, err := reader.ReadRune()
if err != nil {
panic(err)
}
return ch, size
}
func Read() (string, int) {
var buff []byte
size, err := reader.Read(buff)
if err != nil {
panic(err)
}
return string(buff), size
}
// Print string to stdout
func Write(s string) {
fmt.Print(s)
}