RingoJS javascript - get user input on console

1.2k views Asked by At

When using Rhino or RingoJS, one can use print on the console REPL to print output (alert is not available).

What can be used to read user input on the console, instead of prompt?

Is there somewhere I can find information on these conventions, what APIs are available in Rhino and/or RingoJS, or is there a CommonJS guide they are adhering to?

1

There are 1 answers

1
maerics On BEST ANSWER

The short answer is that currently there is no standard (widely supported) way of reading bytes from the standard input stream. With Rhino you could simply use the Java "System.in" input stream; RingoJS does apparently implement the System module.

It looks like the CommonJS group is still working on a draft of the "System" specification which includes a "stdin" object which should be an input stream and behave just like a file opened in "r" mode; such an object should also include a "read()" method. Note however that these are all draft specs and it looks like very few JavaScript environments provide implementations. In an environment which does implement the System and IO specs you should be able to do something like this:

var system = require('system');
system.stdin.read(10); // Read ten bytes.