How to read a single char/keypress in real time from the standard input/keyboard?

Hi,

Is it possible to read a single character from standard input (or the tty directly), without waiting for a newline character?

If I do io:get_chars(standard_io, [], 1), I get the next character, but the problem is that a whole line is collected before the function call returns with that single character. Is it possible to consume every keypress from the stdin (including the arrow keys), without waiting for the enter at the end of the line?

Hello!

It is not currently possible, but it will be in the next release of Erlang/OTP. See Implement lazy-read and noshell raw mode by garazdawi · Pull Request #8962 · erlang/otp · GitHub. If you want to you can build the current master branch and it will work for you now without having to wait for the next release.

1 Like

Great news.
The os:setenv("VISUAL", ...), user_drv ! {self(), {open_editor, ""}} hack won’t be missed.

1 Like