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

var output = java.lang.System.out;
var input = new java.io.InputStreamReader(java.lang.System["in"]);

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

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

/**
 * Read a single character from the standard input.
 */
function read() {
    return String.fromCharCode(input.read());
}

/**
 * Read a single line from the standard input. 
 * @param password {Boolean} if true character echo is replaced with '*'
 */
function readln(password) {
    var buffer = [];
    var c;
    while ((c = read()) != '\r' && c != '\n') {
        if (password) {
            write('*');
        } else {
            write(c);
        }
        buffer.push(c);
    }
    return buffer.join('');
}

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

@@ -147,56 +147,37 @@
 new 
-java.io.InputStreamReader(java.lang.System%5B%22in%22%5D
+Packages.jline.ConsoleReader(
 );%0A%0A
@@ -707,16 +707,26 @@
 put.read
+VirtualKey
 ());%0A%7D%0A%0A
@@ -775,17 +775,16 @@
 d input.
- 
 %0A * @par
@@ -791,334 +791,490 @@
 am p
-assword %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(''
+rompt %7BString%7D optional prompt to display%0A * @param echoChar %7BString%7D character to use as echo,%0A *         e.g. '*' for passwords or '' for no echo.%0A */%0Afunction readln(prompt, echoChar) %7B%0A    prompt = prompt %7C%7C '';%0A    if (typeof echoChar == 'string') %7B%0A        var echo = echoChar == '' ?%0A               new java.lang.Character(0) :%0A               new java.lang.Character(echoChar.charCodeAt(0));%0A        return input.readLine(prompt, echo);%0A    %7D%0A    return input.readLine(prompt
 );%0A%7D

Use jline ConsoleReader for shell read() and readln() methods to allow line editing.