gilo/terminal/io.go

38 lines
535 B
Go
Raw Normal View History

2021-03-24 16:23:17 -04:00
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
}
2021-03-26 13:35:58 -04:00
func Read() string {
scanner := bufio.NewScanner(os.Stdin)
if scanner.Scan() {
return scanner.Text()
}
err := scanner.Err()
2021-03-25 13:20:33 -04:00
if err != nil {
2021-03-26 13:35:58 -04:00
panic(fmt.Sprintf("Failed to read string from stdin %v", err))
2021-03-25 13:20:33 -04:00
}
2021-03-26 13:35:58 -04:00
return "(╯°□°)╯︵ ┻━┻"
2021-03-25 13:20:33 -04:00
}
2021-03-24 16:23:17 -04:00
// Print string to stdout
func Write(s string) {
fmt.Print(s)
}