Skip to content

Instantly share code, notes, and snippets.

@JVero
Last active July 18, 2018 04:58
Show Gist options
  • Save JVero/181600d721db28733e309794420c6c80 to your computer and use it in GitHub Desktop.
Save JVero/181600d721db28733e309794420c6c80 to your computer and use it in GitHub Desktop.
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