[erlang-questions] Problems writing ncurses port and undocumented erl -nouser flag

Patrick Mahoney <>
Sun Jan 4 22:33:52 CET 2009


I'm trying to write an ncurses port for simple client
software in erlang (e.g. irc client).  My initial problem
was that both ncurses and erlang seem to be competing for
input on fd 0 so ncurses doesn't get all the user input.  I
was able to solve it by using "-noinput -nouser" flags to
erl, but "-nouser" is undocumented, so I'm wondering if this
I'm using it correctly.

My initial idea was something like this:

  Port = open_port({spawn, "./ncurses_port 3 4"},
                   [{packet,2}, nouse_stdio, binary])

ncurses_port is a C program using ei and fds 3,4 for
communicating with erlang and inherits fds 0,1 which are the
tty that ncurses routines will control.

erl(3) states that the -noinput flag "Ensures that the
Erlang runtime system never tries to read any input".  So I
started erlang like this:

  erl -noinput ncurses.erl -run ncurses

But when reading user input, I don't get all the chars
because erlang is also reading from fd 0.  I can extract
these missing chars from the user process
(lib/kernel/src/user.erl) like this:

  user ! {io_request, self(), result, {get_chars, '', 2}},
  receive
    {io_reply, result, Data} ->
      io:format("got chars: ~p~n", [Data])
  end

Looking in lib/kernel/src/user_sup.erl, when the "noinput"
flag is present, the user process is started with
user:start_out() which does open_port({fd,0,1},
[out,binary]); the "out" option to open_port makes that port
only available for output as stated in the erlang(3)
manpage.

I spotted a "nouser" flag in lib/kernel/src/user_sup.erl,
which causes it to not start the user process.  Is this a
supported flag (it's not documented in the erl(3) manpage)?

When I start erlang like this:

  erl -noinput -nouser ncurses.erl -run ncurses

ncurses input seems to behave as I expect.

So, is there something ncurses might be doing to the file
descriptors that would break whatever the "out" option does?
Is the erlang documentation in error?  Is using "-nouser" to
avoid the user process an appropriate solution?

Thanks.



More information about the erlang-questions mailing list