How to obtain raw character input?

755 views
Skip to first unread message

ray

unread,
Dec 13, 2009, 5:22:35 AM12/13/09
to golang-nuts
When using the read function in the OS package, Go seems to use Linux
cooked mode. I cannot see a flag value to add to os.Open() to request
Linux raw mode. What I want to do is read a character from standard-in
without having to wait for the enter key to be pressed. Has anyone got
a solution (hopefully without writing a lot of C code)?

msw

unread,
Dec 13, 2009, 9:39:12 PM12/13/09
to golang-nuts
There's always exec.Run("stty" ....) but it gives me the non-portable
willies.

ziyu_huang

unread,
Dec 13, 2009, 9:45:43 PM12/13/09
to golang-nuts
Actually, it's portable enough for most unix system.
You can see how JLine use it.

ray

unread,
Dec 16, 2009, 11:50:47 AM12/16/09
to golang-nuts
Thanks msw and ziyu_huang. I copied the technique from JLine, and
after many silly errors on my part, it now works well.
I have used exec.Run() with argv of: "/bin/stty", "-F", "/dev/tty", "-
icanon", "min", "1"

On Dec 14, 2:45 am, ziyu_huang <ziyu4hu...@gmail.com> wrote:
> Actually, it's portable enough for most unix system.
> You can see how JLine use it.
>
> On 12月14日, 上午10時39分, msw <matt.wart...@gmail.com> wrote:
>
> > There's always exec.Run("stty" ....) but it gives me the non-portable
> > willies.
>
> > On Dec 13, 5:22 am, ray <r...@hollett.demon.co.uk> wrote:
>
> > > When using the read function in the OS package, Go seems to use Linux
> > > cooked mode. I cannot see a flag value to add to os.Open() to request
> > > Linuxrawmode. What I want to do is read a character from standard-in
Reply all
Reply to author
Forward
0 new messages