Skip to content

Instantly share code, notes, and snippets.

@junegunn

junegunn/keys.go

Last active Nov 5, 2016
Embed
What would you like to do?
package main
import (
"fmt"
"os"
"syscall"
)
func GetBytes() []byte {
_in, _ := os.OpenFile("/dev/tty", syscall.O_RDONLY, 0)
var _buf []byte
getch := func(nonblock bool) int {
b := make([]byte, 1)
syscall.SetNonblock(int(_in.Fd()), nonblock)
_, err := _in.Read(b)
if err != nil {
return -1
}
return int(b[0])
}
c := getch(false)
_buf = append(_buf, byte(c))
for {
c = getch(true)
if c == -1 {
break
}
_buf = append(_buf, byte(c))
fmt.Println(" -- ", _buf)
}
fmt.Println(" xx ", _buf)
return _buf
}
func main() {
GetBytes()
}
require 'curses'
Curses.init_screen
Curses.raw
Curses.noecho
loop do
ord = Curses.getch
break if ord == 3
Curses.addstr ord.ord.to_s + ' '
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment