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
This commit is contained in:
Thamme Gowda 2016-09-25 02:47:21 -07:00
parent d3a1395481
commit c8c9a7d92e
2 changed files with 23 additions and 19 deletions

View File

@ -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 {

View File

@ -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);
}
}