views:

87

answers:

2

I have an application that I'd like to have a prompt in. If it helps, this is a graph database implementation and I need a prompt just like any other database client (MySQL, Postgresql, etc.).

So far I have my own REPL like so:

object App extends Application {
    REPL ! Read
}

object REPL extends Actor {
    def act() {
        loop {
            react {
                case Read => {
                    print("prompt> ")
                    var message = Console.readLine
                    this ! Eval(message)
                }
                case More(sofar) => {
                    //Eval didn't see a semicolon
                    print("    --> ")
                    var message = Console.readLine
                    this ! Eval(sofar + " " + message)
                }
                case Eval(message) => {
                    Evaluator ! Eval(message)
                }
                case Print(message) => {
                    println(message)
                    //And here's the loop
                    this ! Read
                }
                case Exit => {
                    exit()
                }
                case _ => {
                    println("App: How did we get here")
                }
            }
        }
    }
    this.start
}

It works, but I would really like to have something with history. Tab completion is not necessary.

Any suggestions on a good library? Scala or Java works.

Just to be clear I don't need an REPL to evaluate my code (I get that with scala!), nor am I looking to call or use something from the command line. I'm looking for a prompt that is my user experience when my client app starts up.

+2  A: 

BeanShell does some of what you want: http://www.beanshell.org/

Eric Bowman - abstracto -
+5  A: 

Scala itself, and lots of programs out there, uses a readline-like library for its REPL. Specifically, JLine.

I found another question about this, for which the answers don't seem promising.

Daniel
Yes a readline-like library is exactly what I was looking for. I also found a jni wrap of gnu readline called java-readline, but I think I will be using JLine. Thanks!
Ben Daniels