4 ms·
I wonder why the author didn't just read() in bytes from STDIN_FILENO? No need to use stuff like fget*.
by jevinskie 13y ago
I wonder why the author didn't just read() in bytes from STDIN_FILENO? No need to use stuff like fget*.
- evmar 13y agoI think by default your terminal is in "cooked" mode, where stdin is buffered a line at a time. Try cat /dev/fd/0 then type some things including backspace and enter. However, you don't need ncurses to change this behavior. termios is the lower-level C API. You can do it from Go with the syscall APIs but I suspect it might be frustrating to make portable. https://code.google.com/p/go/source/browse/ssh/terminal/util.go?repo=crypto&r=33d6505b6597ddd49a330ed2f8707bcb2c52318c#37 https://code.google.com/p/go/source/browse/ssh/terminal/util...
- zellyn 13y agoYep, it's a bit gnarly. But at least linux/MacOS is straightforward: https://groups.google.com/d/msg/golang-nuts/yRkGpw624-I/htJtgKNUIZMJ https://groups.google.com/d/msg/golang-nuts/yRkGpw624-I/htJt...
- songgao 13y agoThere's a package that does that: https://github.com/nsf/termbox-go https://github.com/nsf/termbox-go
- jevinskie 13y agoAh you're right, I was thinking TTY didn't buffer at all but it does line buffering. That is contrasted to regular buffering if it wasn't a TTY.
- jlarocco 13y agoNeither fget*() or read() from stdin would work because stdin is buffered. It's possible to change the mode, but it would require calling the terminal control functions, and that'd requiring calling out to C anyway, so might as well use ncurses.
- zaphar 13y agoNope, you don't have to touch C at all. The syscall package has all you need. But it's still a lot of lowlevel coding. Ncurses is probably easier.