update jline to 2.14

This commit is contained in:
Peter Hormanns 2016-08-31 18:18:06 +02:00
parent ff67ca8c96
commit b0896912a1
4 changed files with 22 additions and 14 deletions

View File

@ -58,7 +58,7 @@
<dependency>
<groupId>jline</groupId>
<artifactId>jline</artifactId>
<version>1.0</version>
<version>2.14.2</version>
</dependency>
<dependency>
<groupId>commons-cli</groupId>

View File

@ -26,7 +26,10 @@ public class Main {
if (file != null && file.length() > 0) {
if ("-".equals(file)) {
scriptClient.execute(new InputStreamReader(System.in));
console.println(formatter.format(scriptClient.getLastRpcResult()));
final String[] lines = formatter.format(scriptClient.getLastRpcResult()).split("\n");
for (String ll : lines) {
console.println(ll);
}
} else {
BufferedReader bufferedReader = null;
try {
@ -58,14 +61,20 @@ public class Main {
final String expr = cmdParser.getExpression();
if (expr != null && expr.length() > 0) {
scriptClient.execute(expr);
console.println(formatter.format(scriptClient.getLastRpcResult()));
final String[] lines = formatter.format(scriptClient.getLastRpcResult()).split("\n");
for (String ll : lines) {
console.println(ll);
}
}
if (cmdParser.isInteractive()) {
String command = console.readInput();
while (!isExitCommand(command)) {
try {
scriptClient.execute(command);
console.println(formatter.format(scriptClient.getLastRpcResult()));
final String[] lines = formatter.format(scriptClient.getLastRpcResult()).split("\n");
for (String ll : lines) {
console.println(ll);
}
} catch (JSCliException e) {
console.println(findRootException(e) + "\n");
}

View File

@ -3,10 +3,10 @@ package de.hsadmin.jscli.console;
import java.io.File;
import java.io.IOException;
import jline.ConsoleReader;
import jline.History;
import jline.SimpleCompletor;
import de.hsadmin.jscli.exception.JSCliException;
import jline.console.ConsoleReader;
import jline.console.completer.StringsCompleter;
import jline.console.history.FileHistory;
public class ConsoleWrapper implements PasswordReader {
@ -17,9 +17,9 @@ public class ConsoleWrapper implements PasswordReader {
this.prompt = prompt;
try {
cons = new ConsoleReader();
cons.setDefaultPrompt(prompt);
cons.setPrompt(prompt);
final String userHome = System.getProperty("user.home");
cons.setHistory(new History(new File(userHome + "/.hsscript_history")));
cons.setHistory(new FileHistory(new File(userHome + "/.hsscript_history")));
} catch (IOException e) {
throw new JSCliException(e);
}
@ -40,8 +40,7 @@ public class ConsoleWrapper implements PasswordReader {
public void println(final String text) throws JSCliException {
try {
if (cons != null) {
cons.printString(text);
cons.printNewline();
cons.println(text);
} else {
throw new JSCliException("cannot write console");
}
@ -53,7 +52,7 @@ public class ConsoleWrapper implements PasswordReader {
public String readPassword() throws JSCliException {
try {
final String pw = cons.readLine("Password: ", new Character('*'));
cons.setDefaultPrompt(prompt);
cons.setPrompt(prompt);
return pw;
} catch (IOException e) {
throw new JSCliException(e);
@ -61,7 +60,7 @@ public class ConsoleWrapper implements PasswordReader {
}
public void codeCompletion(final String[] candidateStrings) {
cons.addCompletor(new SimpleCompletor(candidateStrings));
cons.addCompleter(new StringsCompleter(candidateStrings));
}
}

View File

@ -98,7 +98,7 @@ public class JSONFormatter {
if (ind > 52) {
ind = 52;
}
return "\n ".substring(0, indent);
return "\n ".substring(0, ind);
}
}