From c8c9a7d92e055ec7bcd9954c546ed7a30fd093d2 Mon Sep 17 00:00:00 2001 From: Thamme Gowda Date: Sun, 25 Sep 2016 02:47:21 -0700 Subject: [PATCH] Added JLine prompt JLine provides convenient CLI functionality like history (UP arrow), edit the input characters (Left arrow) that can be seen in modern shells like bash --- pull-dependencies | 9 ++++++- src/edu/stanford/nlp/sempre/Master.java | 33 +++++++++++-------------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/pull-dependencies b/pull-dependencies index edcd808..cb49970 100755 --- a/pull-dependencies +++ b/pull-dependencies @@ -28,7 +28,11 @@ def pull(sourcePath, dir=nil, opts={}) if $isPublic # Download url => localPath - url = 'http://nlp.stanford.edu/software/sempre/dependencies-' + $version + sourcePath + ext + if sourcePath.start_with?('http://') || sourcePath.start_with?('https://') + url = sourcePath + else + url = 'http://nlp.stanford.edu/software/sempre/dependencies-' + $version + sourcePath + ext + end localPath = destDir + '/' + name + ext system "mkdir -p #{File.dirname(localPath)}" or exit 1 system "wget -c '#{url}' -O #{localPath}" or exit 1 @@ -86,6 +90,9 @@ addModule('core', 'Core utilities (need to compile)', lambda { pull('/u/nlp/data/semparse/resources/jackson-core-2.2.0.jar') pull('/u/nlp/data/semparse/resources/jackson-annotations-2.2.0.jar') pull('/u/nlp/data/semparse/resources/jackson-databind-2.2.0.jar') + + # jLine from maven central + pull('http://central.maven.org/maven2/jline/jline/2.14.2/jline-2.14.2.jar') }) addModule('corenlp', 'Stanford CoreNLP (code and modules)', lambda { diff --git a/src/edu/stanford/nlp/sempre/Master.java b/src/edu/stanford/nlp/sempre/Master.java index 9151e58..1d6520c 100644 --- a/src/edu/stanford/nlp/sempre/Master.java +++ b/src/edu/stanford/nlp/sempre/Master.java @@ -4,6 +4,7 @@ import com.google.common.base.Joiner; import com.google.common.base.Strings; import com.google.common.collect.Lists; import fig.basic.*; +import jline.console.ConsoleReader; import java.io.IOException; import java.io.PrintWriter; @@ -131,26 +132,22 @@ public class Master { if (opts.printHelp) printHelp(); - - while (true) { - LogInfo.stdout.print("> "); - LogInfo.stdout.flush(); + try { + ConsoleReader reader = new ConsoleReader(); + reader.setPrompt("> "); String line; - try { - line = LogInfo.stdin.readLine(); - } catch (IOException e) { - throw new RuntimeException(e); - } - if (line == null) break; - - int indent = LogInfo.getIndLevel(); - try { - processQuery(session, line); - } catch (Throwable t) { - while (LogInfo.getIndLevel() > indent) - LogInfo.end_track(); - t.printStackTrace(); + while ((line = reader.readLine()) != null) { + int indent = LogInfo.getIndLevel(); + try { + processQuery(session, line); + } catch (Throwable t) { + while (LogInfo.getIndLevel() > indent) + LogInfo.end_track(); + t.printStackTrace(); + } } + } catch (IOException e) { + throw new RuntimeException(e); } }