Last active
July 18, 2018 04:58
-
-
Save JVero/181600d721db28733e309794420c6c80 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import( | |
"fmt" | |
"log" | |
"golang.org/x/crypto/ssh/terminal" | |
"bufio" | |
"os" | |
"bytes" | |
) | |
func main() { | |
reader := bufio.NewReader(os.Stdin) | |
var buffer bytes.Buffer | |
oldState, err := terminal.MakeRaw(0) | |
if err != nil { | |
log.Fatal(err) | |
} | |
defer terminal.Restore(0, oldState) | |
num_chars := 0 | |
for true { | |
char, _, err := reader.ReadRune(); | |
if char == 13 { | |
fmt.Println("You typed ", num_chars, " characters") | |
return | |
} | |
num_chars++ | |
if err != nil { | |
log.Fatal(err) | |
} | |
buffer.WriteRune(char) | |
fmt.Println(buffer.String()) | |
} | |
if err != nil { | |
fmt.Println(err) | |
} | |
} | |
~ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment