Simple text user interface question

Per Hedeland <>
Sun Aug 7 20:02:32 CEST 2005

"Sebastian Bello" <> wrote:
>One more question: I tried io:get_chars('Input key: ', 1) but it seems to
>wait for an ENTER and to cut the read characters to the specified length.
>I'm in fact looking for a way to read just N (in this case 1) keys from the
>keyboard, *without* waiting for an ENTER. Any ideas?

Well, now you're getting into the really system-dependant stuff -
dependant not on terminal type but on OS. And since you're running
Windows, I won't presume to have any useful advice.

On Unix, the default mode of the tty driver is to collect complete lines
before delivering anything to the application - which is what the vast
majority of applications want. On most Unices, you can get the behaviour
you want by invoking Erlang as

stty -icanon min 1 time 0; erl -oldshell

You will have a *very* unfriendly shell though - this is probably more
appropriate for cases where you don't want to have a shell at all.
(Also, depending on your *Unix* shell, the tty may be in a "weird" mode
after exiting Erlang.)

However, it can be noted that the "ttsl" driver used by the standard
shell (both on Unix and Windows, though the driver is different) already
puts the tty in this "one character at a time" mode - it is necessary to
be able to do general "command-line editing" (hm, from a quick look at
the Windows version, it seems it doesn't actually do anything special
for this...). But somewhere in the Erlang I/O chain, the "deliver only
complete lines" behaviour is re-instated - again probably since that's
what most applications want. You can hunt through the source to find
where, and possibly find a way to turn it off...

--Per Hedeland

More information about the erlang-questions mailing list