// This module is evaluated on shell scopes,
// so to extend the helma shell just add stuff here.

var out = java.lang.System.out;

/**
 * Write 0..n arguments to standard output.
 */
function write() {
    var length = arguments.length;
    for (var i = 0; i < length; i++) {
        out.print(String(arguments[i]));
        if (i < length - 1)
            out.print(' ');
    }
}

/**
 * Write 0..n arguments to standard output, followed by a newline.
 */
function writeln() {
    write.apply(this, arguments);
    out.println();
}

/**
 * Quit the shell and exit the JVM.
 */
function quit() {
   java.lang.System.exit(0);
}

@@ -99,16 +99,19 @@
 %0Avar out
+put
  = java.
@@ -126,16 +126,83 @@
 tem.out;
+%0Avar input = new java.io.InputStreamReader(java.lang.System%5B%22in%22%5D);
 %0A%0A/**%0A *
@@ -347,24 +347,27 @@
 %0A        out
+put
 .print(Strin
@@ -423,24 +423,27 @@
          out
+put
 .print(' ');
@@ -589,16 +589,19 @@
 %0A    out
+put
 .println
@@ -603,24 +603,546 @@
 intln();%0A%7D%0A%0A
+/**%0A * Read a single character from the standard input.%0A */%0Afunction read() %7B%0A    return String.fromCharCode(input.read());%0A%7D%0A%0A/**%0A * Read a single line from the standard input. %0A * @param password %7BBoolean%7D if true character echo is replaced with '*'%0A */%0Afunction readln(password) %7B%0A    var buffer = %5B%5D;%0A    var c;%0A    while ((c = read()) != '%5Cr' && c != '%5Cn') %7B%0A        if (password) %7B%0A            write('*');%0A        %7D else %7B%0A            write(c);%0A        %7D%0A        buffer.push(c);%0A    %7D%0A    return buffer.join('');%0A%7D%0A%0A
 /**%0A * Quit 

Implement read() and readln() function in shell module.