Last active
November 5, 2016 18:37
-
-
Save junegunn/6d4ee557a37aa981700b14f0b3eb7793 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" | |
"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() | |
} |
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
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