Mercurial Hosting > luan
diff src/luan/tools/CmdLine.java @ 104:754e6030c029
remove parboiled and rewrite parser;
add jline;
git-svn-id: https://luan-java.googlecode.com/svn/trunk@105 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Mon, 12 May 2014 05:57:53 +0000 |
parents | 6ca02b188dba |
children | 3c404a296995 |
line wrap: on
line diff
--- a/src/luan/tools/CmdLine.java Mon Mar 17 21:17:31 2014 +0000 +++ b/src/luan/tools/CmdLine.java Mon May 12 05:57:53 2014 +0000 @@ -1,13 +1,13 @@ package luan.tools; -import java.util.Arrays; -import java.util.Scanner; +import java.io.IOException; import luan.lib.BasicLib; import luan.Luan; import luan.LuanState; import luan.LuanFunction; import luan.LuanTable; import luan.LuanException; +import jline.ConsoleReader; public class CmdLine { @@ -101,16 +101,23 @@ } static void interactive(LuanState luan,LuanTable env) { - while( true ) { - System.out.print("> "); - String input = new Scanner(System.in).nextLine(); - try { - Object[] rtn = luan.eval(input,"stdin",env); - if( rtn.length > 0 ) - BasicLib.print(luan,rtn); - } catch(LuanException e) { - System.out.println(e.getMessage()); + try { + ConsoleReader console = new ConsoleReader(); + console.setDefaultPrompt("> "); + while( true ) { + String input = console.readLine(); + if( input==null ) + break; + try { + Object[] rtn = luan.eval(input,"stdin",env); + if( rtn.length > 0 ) + BasicLib.print(luan,rtn); + } catch(LuanException e) { + System.out.println(e.getMessage()); + } } + } catch(IOException e) { + throw new RuntimeException(e); } }