Skip to content

Instantly share code, notes, and snippets.

@junegunn
Last active November 5, 2016 18:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save junegunn/6d4ee557a37aa981700b14f0b3eb7793 to your computer and use it in GitHub Desktop.
Save junegunn/6d4ee557a37aa981700b14f0b3eb7793 to your computer and use it in GitHub Desktop.
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