aboutsummaryrefslogtreecommitdiff
path: root/juick-console/src/main/java/com/juick
diff options
context:
space:
mode:
Diffstat (limited to 'juick-console/src/main/java/com/juick')
-rw-r--r--juick-console/src/main/java/com/juick/console/Console.java5
-rw-r--r--juick-console/src/main/java/com/juick/console/ConsoleApp.java53
2 files changed, 37 insertions, 21 deletions
diff --git a/juick-console/src/main/java/com/juick/console/Console.java b/juick-console/src/main/java/com/juick/console/Console.java
index 9fff298f..ad858c56 100644
--- a/juick-console/src/main/java/com/juick/console/Console.java
+++ b/juick-console/src/main/java/com/juick/console/Console.java
@@ -1,16 +1,17 @@
package com.juick.console;
-import ch.vorburger.exec.ManagedProcessException;
import com.juick.console.configuration.ConsoleAppConfiguration;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.core.env.SimpleCommandLinePropertySource;
+import java.io.IOException;
+
/**
* Created by vitalyster on 30.08.2016.
*/
public class Console {
- public static void main(String ...args) throws ManagedProcessException {
+ public static void main(String ...args) throws IOException {
final AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
// setup configuration
diff --git a/juick-console/src/main/java/com/juick/console/ConsoleApp.java b/juick-console/src/main/java/com/juick/console/ConsoleApp.java
index 9a061bb6..22a26609 100644
--- a/juick-console/src/main/java/com/juick/console/ConsoleApp.java
+++ b/juick-console/src/main/java/com/juick/console/ConsoleApp.java
@@ -4,7 +4,12 @@ import com.juick.User;
import com.juick.server.protocol.JuickProtocol;
import com.juick.server.protocol.ProtocolReply;
import com.juick.service.UserService;
-import jline.console.ConsoleReader;
+import org.jline.reader.EndOfFileException;
+import org.jline.reader.LineReader;
+import org.jline.reader.LineReaderBuilder;
+import org.jline.reader.UserInterruptException;
+import org.jline.terminal.Terminal;
+import org.jline.terminal.TerminalBuilder;
import org.springframework.context.ApplicationContext;
import org.springframework.core.env.Environment;
@@ -27,30 +32,40 @@ public class ConsoleApp {
public ConsoleApp(ApplicationContext context) {
juickProtocol = context.getBean(JuickProtocol.class);
}
- public void start() {
- //jline.TerminalFactory.registerFlavor(jline.TerminalFactory.Flavor.WINDOWS, UnsupportedTerminal.class);
- try (ConsoleReader reader = new ConsoleReader()) {
- PrintWriter out = new PrintWriter(reader.getOutput());
- String uname = env.getProperty("uname", "ugnich");
- User user = userService.getUserByName(uname);
- if (user != null) {
- reader.setPrompt(String.format("%s>", user.getName()));
- out.println(String.format("logged in as @%s", user.getName()));
- out.flush();
- String input;
- while ((input = reader.readLine()) != null) {
+ public void start() throws IOException {
+ Terminal terminal = TerminalBuilder.builder()
+ .system(true)
+ .nativeSignals(true)
+ .jna(true)
+ .build();
+ LineReader reader = LineReaderBuilder.builder()
+ .terminal(terminal)
+ .build();
+ PrintWriter out = terminal.writer();
+ String uname = env.getProperty("uname", "ugnich");
+ User user = userService.getUserByName(uname);
+ if (user != null) {
+ String prompt = String.format("@%s>", user.getName());
+ while (true) {
+ try {
+ String input = reader.readLine(prompt, null, null);
ProtocolReply reply = juickProtocol.getReply(user, input);
out.println(reply.getResult());
out.flush();
+ } catch (UserInterruptException e) {
+
+ } catch (EndOfFileException e) {
+ break;
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ } catch (InvocationTargetException e) {
+ e.printStackTrace();
+ } catch (NoSuchMethodException e) {
+ e.printStackTrace();
}
}
+ } else {
out.println("uname missing or invalid");
- } catch (IOException | NoSuchMethodException e) {
- e.printStackTrace();
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- } catch (InvocationTargetException e) {
- e.printStackTrace();
}
}
}