FELIX-1818: Ctrl-C kills the karaf-client instead of being sent to the server
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@830725 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/karaf/client/pom.xml b/karaf/client/pom.xml
index 558f6dd..829d15a 100644
--- a/karaf/client/pom.xml
+++ b/karaf/client/pom.xml
@@ -46,6 +46,10 @@
<artifactId>sshd-core</artifactId>
</dependency>
<dependency>
+ <groupId>org.apache.felix.karaf.shell</groupId>
+ <artifactId>org.apache.felix.karaf.shell.console</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
diff --git a/karaf/client/src/main/java/org/apache/felix/karaf/client/Main.java b/karaf/client/src/main/java/org/apache/felix/karaf/client/Main.java
index 8784337..1fcfca0 100644
--- a/karaf/client/src/main/java/org/apache/felix/karaf/client/Main.java
+++ b/karaf/client/src/main/java/org/apache/felix/karaf/client/Main.java
@@ -17,7 +17,10 @@
package org.apache.felix.karaf.client;
import java.io.ByteArrayInputStream;
+import java.io.PrintWriter;
+import jline.Terminal;
+import org.apache.felix.karaf.shell.console.jline.TerminalFactory;
import org.apache.sshd.ClientChannel;
import org.apache.sshd.ClientSession;
import org.apache.sshd.SshClient;
@@ -71,6 +74,7 @@
// TODO: implement sending a direct command
SshClient client = null;
+ Terminal terminal = null;
try {
client = SshClient.setUpDefaultClient();
client.start();
@@ -83,8 +87,12 @@
channel = session.createChannel("exec");
channel.setIn(new ByteArrayInputStream(sb.append("\n").toString().getBytes()));
} else {
+ terminal = new TerminalFactory().getTerminal();
channel = session.createChannel("shell");
- channel.setIn(new ConsoleReader().getInput());
+ ConsoleReader reader = new ConsoleReader(System.in, new PrintWriter(System.out),
+ TerminalFactory.class.getResourceAsStream("keybinding.properties"),
+ terminal);
+ channel.setIn(reader.getInput());
}
channel.setOut(System.out);
channel.setErr(System.err);
@@ -97,6 +105,11 @@
try {
client.stop();
} catch (Throwable t) { }
+ try {
+ if (terminal != null) {
+ terminal.restoreTerminal();
+ }
+ } catch (Throwable t) { }
}
System.exit(0);
}
diff --git a/karaf/shell/ssh/src/main/java/org/apache/felix/karaf/shell/ssh/ShellFactoryImpl.java b/karaf/shell/ssh/src/main/java/org/apache/felix/karaf/shell/ssh/ShellFactoryImpl.java
index 0be73f3..3fc44ee 100644
--- a/karaf/shell/ssh/src/main/java/org/apache/felix/karaf/shell/ssh/ShellFactoryImpl.java
+++ b/karaf/shell/ssh/src/main/java/org/apache/felix/karaf/shell/ssh/ShellFactoryImpl.java
@@ -94,8 +94,8 @@
};
Console console = new Console(commandProcessor,
in,
- new PrintStream(out),
- new PrintStream(err),
+ new PrintStream(out, true),
+ new PrintStream(err, true),
new SshTerminal(env),
new AggregateCompleter(completers),
new Runnable() {