Permalink
Browse files

Have repl use JReadline instead of JLine.

  • Loading branch information...
1 parent dc45953 commit b8623e40aa910659ca71091b859f09c5ea24593f @lance lance committed Aug 27, 2012
Showing with 18 additions and 18 deletions.
  1. +3 −3 pom.xml
  2. +15 −15 src/main/java/org/dynjs/cli/Repl.java
View
@@ -118,9 +118,9 @@
<scope>compile</scope>
</dependency>
<dependency>
- <groupId>jline</groupId>
- <artifactId>jline</artifactId>
- <version>2.6</version>
+ <groupId>org.jboss.jreadline</groupId>
+ <artifactId>jreadline</artifactId>
+ <version>0.19</version>
<scope>compile</scope>
</dependency>
@@ -20,10 +20,11 @@
import java.io.OutputStream;
import java.io.PrintWriter;
-import jline.console.ConsoleReader;
import org.dynjs.exception.DynJSException;
import org.dynjs.runtime.DynJS;
+import org.jboss.jreadline.console.Console;
+import org.jboss.jreadline.console.ConsoleOutput;
public class Repl {
@@ -33,34 +34,33 @@
+ System.lineSeparator();
public static final String PROMPT = "dynjs> ";
private final DynJS runtime;
- private final InputStream in;
private final OutputStream out;
public Repl(DynJS runtime, InputStream in, OutputStream out) {
this.runtime = runtime;
- this.in = in;
this.out = out;
}
public void run() {
- ConsoleReader console = null;
try {
- console = new ConsoleReader(in, out);
- console.println(WELCOME_MESSAGE);
- String statement = null;
- while ((statement = console.readLine(PROMPT)) != null) {
- if ("exit".equals(statement.trim())) {
- return;
+ Console console = new Console();
+ console.pushToStdOut( WELCOME_MESSAGE );
+ ConsoleOutput line = null;
+ while ((line = console.read(PROMPT)) != null) {
+ String statement = line.getBuffer();
+ if (statement.equalsIgnoreCase( "exit" )) {
+ break;
} else {
try {
+// console.pushToStdOut( "Eval: " + statement );
Object object = runtime.evaluate(statement);
- System.out.println(object.toString());
+ console.pushToStdOut(object.toString());
} catch (DynJSException e) {
- console.println(e.getClass().getSimpleName());
- console.println(e.getLocalizedMessage());
- console.println("Error parsing statement: " + statement.toString());
+ console.pushToStdErr(e.getClass().getSimpleName() + "\n");
+ console.pushToStdErr(e.getLocalizedMessage() + "\n");
+ console.pushToStdErr("Error parsing statement: " + statement + "\n");
} catch (IncompatibleClassChangeError e) {
- console.println("Error parsing statement: " + statement.toString());
+ console.pushToStdErr("Error parsing statement: " + statement + "\n");
} catch (Exception e) {
e.printStackTrace(new PrintWriter(out));
}

0 comments on commit b8623e4

Please sign in to comment.