Manually echo output
This commit is contained in:
parent
b3344dbe89
commit
1161119269
24
gilo.go
24
gilo.go
@ -7,6 +7,22 @@ import (
|
||||
"os"
|
||||
)
|
||||
|
||||
func isAscii(char rune) bool {
|
||||
ord := int(char)
|
||||
|
||||
return ord < 0x80
|
||||
}
|
||||
|
||||
func isCtrl(char rune) bool {
|
||||
if ! isAscii(char) {
|
||||
return false
|
||||
}
|
||||
|
||||
ord:= int(char)
|
||||
|
||||
return ord == 0x7f || ord < 0x20
|
||||
}
|
||||
|
||||
func goRaw() (*term.State, error) {
|
||||
state, err := term.MakeRaw(int(os.Stdin.Fd()))
|
||||
|
||||
@ -14,11 +30,13 @@ func goRaw() (*term.State, error) {
|
||||
}
|
||||
|
||||
func main() {
|
||||
// Go to proper raw mode
|
||||
oldState, err := goRaw()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Restore canonical mode at exit
|
||||
defer term.Restore(int(os.Stdin.Fd()), oldState)
|
||||
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
@ -33,6 +51,12 @@ func main() {
|
||||
case char == 'q':
|
||||
fmt.Println("bye!\r")
|
||||
return
|
||||
case isCtrl(char):
|
||||
fmt.Printf("%d\n", char)
|
||||
default:
|
||||
fmt.Printf("%d ('%c')\n", char, char)
|
||||
}
|
||||
|
||||
_ = os.Stdout.Sync()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user