Author: gnodet
Date: Thu Sep 23 09:07:42 2010
New Revision: 1000362
URL: http://svn.apache.org/viewvc?rev=1000362&view=rev
Log:
[KARAF-215] Upgrade to latest jline2 / jansi
Removed:
karaf/trunk/shell/console/src/main/java/jline/AnsiWindowsTerminal.java
karaf/trunk/shell/console/src/main/java/jline/NoInterruptUnixTerminal.java
Modified:
karaf/trunk/assembly/pom.xml
karaf/trunk/client/src/main/java/org/apache/karaf/client/Main.java
karaf/trunk/pom.xml
karaf/trunk/shell/commands/src/main/java/org/apache/karaf/shell/commands/HistoryAction.java
karaf/trunk/shell/console/pom.xml
karaf/trunk/shell/console/src/main/java/org/apache/felix/gogo/commands/basic/DefaultActionPreparator.java
karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/HelpAction.java
karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/Main.java
karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/completer/CommandsCompleter.java
karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/completer/FileCompleter.java
karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/jline/CompleterAsCompletor.java
karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/jline/Console.java
karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/jline/ConsoleFactory.java
karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/jline/TerminalFactory.java
karaf/trunk/shell/osgi/src/main/java/org/apache/karaf/shell/osgi/Headers.java
karaf/trunk/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/ShellFactoryImpl.java
karaf/trunk/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/SshTerminal.java
karaf/trunk/webconsole/gogo/src/main/java/org/apache/karaf/webconsole/gogo/WebTerminal.java
Modified: karaf/trunk/assembly/pom.xml
URL:
http://svn.apache.org/viewvc/karaf/trunk/assembly/pom.xml?rev=1000362&r1=1000361&r2=1000362&view=diff
==============================================================================
--- karaf/trunk/assembly/pom.xml (original)
+++ karaf/trunk/assembly/pom.xml Thu Sep 23 09:07:42 2010
@@ -217,10 +217,6 @@
<artifactId>mina-core</artifactId>
</dependency>
<dependency>
- <groupId>jline</groupId>
- <artifactId>jline</artifactId>
- </dependency>
- <dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.osgi.compendium</artifactId>
</dependency>
Modified: karaf/trunk/client/src/main/java/org/apache/karaf/client/Main.java
URL:
http://svn.apache.org/viewvc/karaf/trunk/client/src/main/java/org/apache/karaf/client/Main.java?rev=1000362&r1=1000361&r2=1000362&view=diff
==============================================================================
--- karaf/trunk/client/src/main/java/org/apache/karaf/client/Main.java
(original)
+++ karaf/trunk/client/src/main/java/org/apache/karaf/client/Main.java Thu Sep
23 09:07:42 2010
@@ -139,7 +139,7 @@ public class Main {
} catch (Throwable t) { }
try {
if (terminal != null) {
- terminal.restoreTerminal();
+ terminal.restore();
}
} catch (Throwable t) { }
}
Modified: karaf/trunk/pom.xml
URL:
http://svn.apache.org/viewvc/karaf/trunk/pom.xml?rev=1000362&r1=1000361&r2=1000362&view=diff
==============================================================================
--- karaf/trunk/pom.xml (original)
+++ karaf/trunk/pom.xml Thu Sep 23 09:07:42 2010
@@ -129,7 +129,7 @@
<aries.jmx.version>0.2-incubating</aries.jmx.version>
<geronimo.servlet.version>1.1.2</geronimo.servlet.version>
<jansi.version>1.2</jansi.version>
- <jline.version>0.9.95.20100209</jline.version>
+ <jline.version>2.4-SNAPSHOT</jline.version>
<jsw.version>3.2.3</jsw.version>
<log4j.version>1.2.16</log4j.version>
<maven.version>2.0.9</maven.version>
@@ -595,7 +595,7 @@
<version>${log4j.version}</version>
</dependency>
<dependency>
- <groupId>jline</groupId>
+ <groupId>org.sonatype.jline</groupId>
<artifactId>jline</artifactId>
<version>${jline.version}</version>
</dependency>
Modified:
karaf/trunk/shell/commands/src/main/java/org/apache/karaf/shell/commands/HistoryAction.java
URL:
http://svn.apache.org/viewvc/karaf/trunk/shell/commands/src/main/java/org/apache/karaf/shell/commands/HistoryAction.java?rev=1000362&r1=1000361&r2=1000362&view=diff
==============================================================================
---
karaf/trunk/shell/commands/src/main/java/org/apache/karaf/shell/commands/HistoryAction.java
(original)
+++
karaf/trunk/shell/commands/src/main/java/org/apache/karaf/shell/commands/HistoryAction.java
Thu Sep 23 09:07:42 2010
@@ -16,12 +16,9 @@
*/
package org.apache.karaf.shell.commands;
-import java.util.List;
-
-import jline.History;
+import jline.console.history.History;
import org.apache.felix.gogo.commands.Command;
import org.apache.karaf.shell.console.AbstractAction;
-import org.apache.karaf.shell.console.OsgiCommandSupport;
import org.fusesource.jansi.Ansi;
/**
@@ -33,18 +30,15 @@ public class HistoryAction extends Abstr
@Override
protected Object doExecute() throws Exception {
History history = (History) session.get(".jline.history");
- List<String> elements = history.getHistoryList();
- int i = 0;
- for (String element : elements) {
+ for (History.Entry element : history) {
System.out.println(
Ansi.ansi()
.a(" ")
- .a(Ansi.Attribute.INTENSITY_BOLD).render("%3d",
i).a(Ansi.Attribute.INTENSITY_BOLD_OFF)
+ .a(Ansi.Attribute.INTENSITY_BOLD).render("%3d",
element.index()).a(Ansi.Attribute.INTENSITY_BOLD_OFF)
.a(" ")
- .a(element)
+ .a(element.value())
.toString());
- i++;
}
return null;
}
Modified: karaf/trunk/shell/console/pom.xml
URL:
http://svn.apache.org/viewvc/karaf/trunk/shell/console/pom.xml?rev=1000362&r1=1000361&r2=1000362&view=diff
==============================================================================
--- karaf/trunk/shell/console/pom.xml (original)
+++ karaf/trunk/shell/console/pom.xml Thu Sep 23 09:07:42 2010
@@ -47,7 +47,7 @@
<optional>true</optional>
</dependency>
<dependency>
- <groupId>jline</groupId>
+ <groupId>org.sonatype.jline</groupId>
<artifactId>jline</artifactId>
</dependency>
<dependency>
@@ -120,19 +120,18 @@
org.osgi.service.threadio;version=${felix.gogo.version},
org.apache.karaf.shell.console*;version=${project.version},
org.fusesource.jansi;version=${jansi.version},
- jline;version=${jline.version}
+ jline*;version=${jline.version},
+ org.fusesource.hawtjni*;version=1.0
</Export-Package>
<Private-Package>
org.fusesource.jansi.internal,
- org.apache.felix.gogo.runtime*
+ org.apache.felix.gogo.runtime*,
+ META-INF.native.*
</Private-Package>
- <Bundle-NativeCode>jline/jline32.dll;
- osname=Win32;
- processor=x86,
- jline/jline64.dll;
- osname=Win32;
- processor=x86-64,
- *
+ <Bundle-NativeCode>
+
META-INF/native/windows32/jansi.dll;osname=Win32;processor=x86,
+
META-INF/native/windows64/jansi.dll;osname=Win32;processor=x86-64,
+ *
</Bundle-NativeCode>
<Bundle-Activator>
org.apache.felix.gogo.runtime.Activator
Modified:
karaf/trunk/shell/console/src/main/java/org/apache/felix/gogo/commands/basic/DefaultActionPreparator.java
URL:
http://svn.apache.org/viewvc/karaf/trunk/shell/console/src/main/java/org/apache/felix/gogo/commands/basic/DefaultActionPreparator.java?rev=1000362&r1=1000361&r2=1000362&view=diff
==============================================================================
---
karaf/trunk/shell/console/src/main/java/org/apache/felix/gogo/commands/basic/DefaultActionPreparator.java
(original)
+++
karaf/trunk/shell/console/src/main/java/org/apache/felix/gogo/commands/basic/DefaultActionPreparator.java
Thu Sep 23 09:07:42 2010
@@ -442,7 +442,7 @@ public class DefaultActionPreparator imp
{
out.print(" ");
out.println(Ansi.ansi().a(Ansi.Attribute.INTENSITY_BOLD).a(argument.name()).a(Ansi.Attribute.RESET));
- printFormatted(" ", argument.description(),
term != null ? term.getTerminalWidth() : 80, out);
+ printFormatted(" ", argument.description(),
term != null ? term.getWidth() : 80, out);
if (!argument.required()) {
try {
argsMap.get(argument).setAccessible(true);
@@ -473,7 +473,7 @@ public class DefaultActionPreparator imp
}
out.print(" ");
out.println(Ansi.ansi().a(Ansi.Attribute.INTENSITY_BOLD).a(opt).a(Ansi.Attribute.RESET));
- printFormatted(" ", option.description(), term
!= null ? term.getTerminalWidth() : 80, out);
+ printFormatted(" ", option.description(), term
!= null ? term.getWidth() : 80, out);
try {
optionsMap.get(option).setAccessible(true);
Object o = optionsMap.get(option).get(action);
@@ -493,7 +493,7 @@ public class DefaultActionPreparator imp
if (command.detailedDescription().length() > 0) {
out.println(Ansi.ansi().a(Ansi.Attribute.INTENSITY_BOLD).a("DETAILS").a(Ansi.Attribute.RESET));
String desc = loadDescription(action.getClass(),
command.detailedDescription());
- printFormatted(" ", desc, term != null ?
term.getTerminalWidth() : 80, out);
+ printFormatted(" ", desc, term != null ? term.getWidth() :
80, out);
}
}
Modified:
karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/HelpAction.java
URL:
http://svn.apache.org/viewvc/karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/HelpAction.java?rev=1000362&r1=1000361&r2=1000362&view=diff
==============================================================================
---
karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/HelpAction.java
(original)
+++
karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/HelpAction.java
Thu Sep 23 09:07:42 2010
@@ -80,7 +80,7 @@ public class HelpAction extends Abstract
String key =
NameScoping.getCommandNameWithoutGlobalPrefix(session, entry.getKey());
out.println(Ansi.ansi().a(Ansi.Attribute.INTENSITY_BOLD).a(key).a(Ansi.Attribute.RESET));
if (entry.getValue() != null) {
- DefaultActionPreparator.printFormatted("
", entry.getValue(), term != null ? term.getTerminalWidth() : 80, out);
+ DefaultActionPreparator.printFormatted("
", entry.getValue(), term != null ? term.getWidth() : 80, out);
}
}
out.println();
Modified:
karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/Main.java
URL:
http://svn.apache.org/viewvc/karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/Main.java?rev=1000362&r1=1000361&r2=1000362&view=diff
==============================================================================
---
karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/Main.java
(original)
+++
karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/Main.java
Thu Sep 23 09:07:42 2010
@@ -139,8 +139,8 @@ public class Main {
CommandSession session = console.getSession();
session.put("USER", user);
session.put("APPLICATION", application);
- session.put("LINES", Integer.toString(terminal.getTerminalHeight()));
- session.put("COLUMNS", Integer.toString(terminal.getTerminalWidth()));
+ session.put("LINES", Integer.toString(terminal.getHeight()));
+ session.put("COLUMNS", Integer.toString(terminal.getWidth()));
session.put(".jline.terminal", terminal);
session.put(NameScoping.MULTI_SCOPE_MODE_KEY,
Boolean.toString(isMultiScopeMode()));
Modified:
karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/completer/CommandsCompleter.java
URL:
http://svn.apache.org/viewvc/karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/completer/CommandsCompleter.java?rev=1000362&r1=1000361&r2=1000362&view=diff
==============================================================================
---
karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/completer/CommandsCompleter.java
(original)
+++
karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/completer/CommandsCompleter.java
Thu Sep 23 09:07:42 2010
@@ -58,7 +58,9 @@ public class CommandsCompleter implement
}
protected synchronized void checkData() {
- Set<String> names = (Set<String>)
session.get(CommandSessionImpl.COMMANDS);
+ // Copy the set to avoid concurrent modification exceptions
+ // TODO: fix that in gogo instead
+ Set<String> names = new HashSet<String>((Set<String>)
session.get(CommandSessionImpl.COMMANDS));
if (!names.equals(commands)) {
commands.clear();
completers.clear();
Modified:
karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/completer/FileCompleter.java
URL:
http://svn.apache.org/viewvc/karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/completer/FileCompleter.java?rev=1000362&r1=1000361&r2=1000362&view=diff
==============================================================================
---
karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/completer/FileCompleter.java
(original)
+++
karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/completer/FileCompleter.java
Thu Sep 23 09:07:42 2010
@@ -17,7 +17,7 @@
*/
package org.apache.karaf.shell.console.completer;
-import jline.FileNameCompletor;
+import jline.console.completer.FileNameCompleter;
import org.apache.karaf.shell.console.Completer;
import org.osgi.service.command.CommandSession;
@@ -29,13 +29,13 @@ import java.util.List;
*/
public class FileCompleter implements Completer {
private final CommandSession session;
- private FileNameCompletor completor = new FileNameCompletor();
+ private FileNameCompleter completor = new FileNameCompleter();
public FileCompleter(CommandSession session) {
this.session = session;
}
- public int complete(String buffer, int cursor, List<String> candidates) {
+ public int complete(String buffer, int cursor, List candidates) {
return completor.complete(buffer, cursor, candidates);
}
}
Modified:
karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/jline/CompleterAsCompletor.java
URL:
http://svn.apache.org/viewvc/karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/jline/CompleterAsCompletor.java?rev=1000362&r1=1000361&r2=1000362&view=diff
==============================================================================
---
karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/jline/CompleterAsCompletor.java
(original)
+++
karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/jline/CompleterAsCompletor.java
Thu Sep 23 09:07:42 2010
@@ -20,14 +20,11 @@ package org.apache.karaf.shell.console.j
import java.util.List;
-import jline.Completor;
-import org.apache.karaf.shell.console.Completer;
+public class CompleterAsCompletor implements jline.console.completer.Completer
{
-public class CompleterAsCompletor implements Completor {
+ private final org.apache.karaf.shell.console.Completer completer;
- private final Completer completer;
-
- public CompleterAsCompletor(Completer completer) {
+ public CompleterAsCompletor(org.apache.karaf.shell.console.Completer
completer) {
this.completer = completer;
}
Modified:
karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/jline/Console.java
URL:
http://svn.apache.org/viewvc/karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/jline/Console.java?rev=1000362&r1=1000361&r2=1000362&view=diff
==============================================================================
---
karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/jline/Console.java
(original)
+++
karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/jline/Console.java
Thu Sep 23 09:07:42 2010
@@ -36,9 +36,11 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import jline.AnsiWindowsTerminal;
-import jline.ConsoleReader;
+import jline.console.ConsoleReader;
import jline.Terminal;
import jline.UnsupportedTerminal;
+import jline.console.history.FileHistory;
+import jline.console.history.PersistentHistory;
import org.apache.felix.gogo.commands.CommandException;
import org.apache.karaf.shell.console.CloseShellException;
import org.apache.karaf.shell.console.Completer;
@@ -100,11 +102,11 @@ public class Console implements Runnable
File file = new File(System.getProperty("karaf.history",
new File(System.getProperty("user.home"),
".karaf/karaf.history").toString()));
file.getParentFile().mkdirs();
- reader.getHistory().setHistoryFile(file);
+ reader.setHistory(new FileHistory(file));
session.put(".jline.history", reader.getHistory());
Completer completer = createCompleter();
if (completer != null) {
- reader.addCompletor(new CompleterAsCompletor(completer));
+ reader.addCompleter(new CompleterAsCompletor(completer));
}
if (Boolean.getBoolean("jline.nobell")) {
reader.setBellEnabled(false);
@@ -120,6 +122,13 @@ public class Console implements Runnable
public void close() {
//System.err.println("Closing");
+ if (reader.getHistory() instanceof PersistentHistory) {
+ try {
+ ((PersistentHistory) reader.getHistory()).flush();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
running = false;
pipe.interrupt();
}
@@ -380,12 +389,7 @@ public class Console implements Runnable
{
try
{
- int c;
- if (terminal instanceof AnsiWindowsTerminal) {
- c = ((AnsiWindowsTerminal)
terminal).readDirectChar(in);
- } else {
- c = terminal.readCharacter(in);
- }
+ int c = terminal.readCharacter(in);
if (c == -1)
{
queue.put(c);
@@ -398,7 +402,7 @@ public class Console implements Runnable
else if (c == 3)
{
err.println("^C");
- reader.getCursorBuffer().clearBuffer();
+ reader.getCursorBuffer().clear();
interrupt();
}
queue.put(c);
Modified:
karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/jline/ConsoleFactory.java
URL:
http://svn.apache.org/viewvc/karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/jline/ConsoleFactory.java?rev=1000362&r1=1000361&r2=1000362&view=diff
==============================================================================
---
karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/jline/ConsoleFactory.java
(original)
+++
karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/jline/ConsoleFactory.java
Thu Sep 23 09:07:42 2010
@@ -87,8 +87,8 @@ public class ConsoleFactory {
CommandSession session = console.getSession();
session.put("USER", "karaf");
session.put("APPLICATION", System.getProperty("karaf.name",
"root"));
- session.put("LINES",
Integer.toString(terminal.getTerminalHeight()));
- session.put("COLUMNS",
Integer.toString(terminal.getTerminalWidth()));
+ session.put("LINES", Integer.toString(terminal.getHeight()));
+ session.put("COLUMNS", Integer.toString(terminal.getWidth()));
session.put(".jline.terminal", terminal);
new Thread(console, "Karaf Shell Console Thread").start();
}
Modified:
karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/jline/TerminalFactory.java
URL:
http://svn.apache.org/viewvc/karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/jline/TerminalFactory.java?rev=1000362&r1=1000361&r2=1000362&view=diff
==============================================================================
---
karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/jline/TerminalFactory.java
(original)
+++
karaf/trunk/shell/console/src/main/java/org/apache/karaf/shell/console/jline/TerminalFactory.java
Thu Sep 23 09:07:42 2010
@@ -45,11 +45,11 @@ public class TerminalFactory {
if (windows) {
AnsiWindowsTerminal t = new AnsiWindowsTerminal();
t.setDirectConsole(true);
- t.initializeTerminal();
+ t.init();
term = t;
} else {
NoInterruptUnixTerminal t = new NoInterruptUnixTerminal();
- t.initializeTerminal();
+ t.init();
term = t;
}
} catch (Throwable e) {
@@ -60,7 +60,7 @@ public class TerminalFactory {
public synchronized void destroy() throws Exception {
if (term != null) {
- term.restoreTerminal();
+ term.restore();
term = null;
}
}
Modified:
karaf/trunk/shell/osgi/src/main/java/org/apache/karaf/shell/osgi/Headers.java
URL:
http://svn.apache.org/viewvc/karaf/trunk/shell/osgi/src/main/java/org/apache/karaf/shell/osgi/Headers.java?rev=1000362&r1=1000361&r2=1000362&view=diff
==============================================================================
---
karaf/trunk/shell/osgi/src/main/java/org/apache/karaf/shell/osgi/Headers.java
(original)
+++
karaf/trunk/shell/osgi/src/main/java/org/apache/karaf/shell/osgi/Headers.java
Thu Sep 23 09:07:42 2010
@@ -257,7 +257,7 @@ public class Headers extends OsgiCommand
protected int getTermWidth() {
Terminal term = (Terminal) session.get(".jline.terminal");
- return term != null ? term.getTerminalWidth() : 80;
+ return term != null ? term.getWidth() : 80;
}
Modified:
karaf/trunk/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/ShellFactoryImpl.java
URL:
http://svn.apache.org/viewvc/karaf/trunk/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/ShellFactoryImpl.java?rev=1000362&r1=1000361&r2=1000362&view=diff
==============================================================================
---
karaf/trunk/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/ShellFactoryImpl.java
(original)
+++
karaf/trunk/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/ShellFactoryImpl.java
Thu Sep 23 09:07:42 2010
@@ -107,12 +107,12 @@ public class ShellFactoryImpl implements
for (Map.Entry<String,String> e : env.getEnv().entrySet()) {
session.put(e.getKey(), e.getValue());
}
- session.put("LINES",
Integer.toString(terminal.getTerminalHeight()));
- session.put("COLUMNS",
Integer.toString(terminal.getTerminalWidth()));
+ session.put("LINES", Integer.toString(terminal.getHeight()));
+ session.put("COLUMNS", Integer.toString(terminal.getWidth()));
env.addSignalListener(new SignalListener() {
public void signal(Signal signal) {
- session.put("LINES",
Integer.toString(terminal.getTerminalHeight()));
- session.put("COLUMNS",
Integer.toString(terminal.getTerminalWidth()));
+ session.put("LINES",
Integer.toString(terminal.getHeight()));
+ session.put("COLUMNS",
Integer.toString(terminal.getWidth()));
}
}, Signal.WINCH);
session.put(".jline.terminal", terminal);
Modified:
karaf/trunk/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/SshTerminal.java
URL:
http://svn.apache.org/viewvc/karaf/trunk/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/SshTerminal.java?rev=1000362&r1=1000361&r2=1000362&view=diff
==============================================================================
---
karaf/trunk/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/SshTerminal.java
(original)
+++
karaf/trunk/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/SshTerminal.java
Thu Sep 23 09:07:42 2010
@@ -18,39 +18,34 @@
*/
package org.apache.karaf.shell.ssh;
-import java.io.InputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.io.InputStreamReader;
+import java.util.HashMap;
+import java.util.Map;
-import jline.Terminal;
+import jline.TerminalSupport;
+import jline.console.Key;
+import jline.internal.ReplayPrefixOneCharInputStream;
import org.apache.sshd.common.PtyMode;
import org.apache.sshd.server.Environment;
-import org.apache.sshd.server.Signal;
-import org.apache.sshd.server.SignalListener;
-
-public class SshTerminal extends Terminal {
- public static final short ARROW_START = 27;
- public static final short ARROW_PREFIX = 91;
- public static final short ARROW_LEFT = 68;
- public static final short ARROW_RIGHT = 67;
- public static final short ARROW_UP = 65;
- public static final short ARROW_DOWN = 66;
- public static final short O_PREFIX = 79;
- public static final short HOME_CODE = 72;
- public static final short END_CODE = 70;
+import static jline.console.Key.*;
+import static org.apache.karaf.shell.ssh.SshTerminal.UnixKey.*;
- public static final short DEL_THIRD = 51;
- public static final short DEL_SECOND = 126;
+public class SshTerminal extends TerminalSupport {
private Environment environment;
- private boolean backspaceDeleteSwitched = false;
private String encoding = System.getProperty("input.encoding", "UTF-8");
private ReplayPrefixOneCharInputStream replayStream = new
ReplayPrefixOneCharInputStream(encoding);
private InputStreamReader replayReader;
- private boolean isWindowsTerminal;
+ private boolean deleteSendsBackspace = false;
+ private boolean backspaceSendsDelete = false;
+
public SshTerminal(Environment environment) {
+ super(true);
+ setAnsiSupported(true);
this.environment = environment;
try {
replayReader = new InputStreamReader(replayStream, encoding);
@@ -58,169 +53,134 @@ public class SshTerminal extends Termina
throw new RuntimeException(e);
}
Integer verase = this.environment.getPtyModes().get(PtyMode.VERASE);
- backspaceDeleteSwitched = verase != null && verase == DELETE;
- this.isWindowsTerminal =
"windows".equals(environment.getEnv().get("TERM"));
+ deleteSendsBackspace = verase != null && verase == Key.DELETE.code;
}
- public void initializeTerminal() throws Exception {
+ public void init() throws Exception {
}
- public void restoreTerminal() throws Exception {
+ public void restore() throws Exception {
}
@Override
- public boolean isANSISupported() {
- return !isWindowsTerminal;
- }
-
- public int getTerminalWidth() {
+ public int getWidth() {
return
Integer.valueOf(this.environment.getEnv().get(Environment.ENV_COLUMNS));
}
- public int getTerminalHeight() {
+ @Override
+ public int getHeight() {
return
Integer.valueOf(this.environment.getEnv().get(Environment.ENV_LINES));
}
- public boolean isSupported() {
- return true;
- }
-
- public boolean getEcho() {
- return false;
- }
-
- public boolean isEchoEnabled() {
- return false;
- }
-
- public void enableEcho() {
- }
+ @Override
+ public int readVirtualKey(final InputStream in) throws IOException {
+ int c = readCharacter(in);
- public void disableEcho() {
- }
+ if (Key.valueOf(c) == DELETE && deleteSendsBackspace) {
+ c = BACKSPACE.code;
+ } else if (Key.valueOf(c) == BACKSPACE && backspaceSendsDelete) {
+ c = DELETE.code;
+ }
- public int readVirtualKey(InputStream in) throws IOException {
- int c = readCharacter(in);
+ UnixKey key = UnixKey.valueOf(c);
+
+ // in Unix terminals, arrow keys are represented by a sequence of 3
characters. E.g., the up arrow key yields 27, 91, 68
+ if (key == ARROW_START) {
+ // also the escape key is 27 thats why we read until we have
something different than 27
+ // this is a bugfix, because otherwise pressing escape and than an
arrow key was an undefined state
+ while (key == ARROW_START) {
+ c = readCharacter(in);
+ key = UnixKey.valueOf(c);
+ }
- if (backspaceDeleteSwitched)
- if (c == DELETE)
- c = BACKSPACE;
- else if (c == BACKSPACE)
- c = DELETE;
-
- // in Unix terminals, arrow keys are represented by
- // a sequence of 3 characters. E.g., the up arrow
- // key yields 27, 91, 68
- if (c == ARROW_START) {
- //also the escape key is 27
- //thats why we read until we
- //have something different than 27
- //this is a bugfix, because otherwise
- //pressing escape and than an arrow key
- //was an undefined state
- while (c == ARROW_START)
- c = readCharacter(in);
- if (c == ARROW_PREFIX || c == O_PREFIX) {
+ if (key == ARROW_PREFIX || key == O_PREFIX) {
c = readCharacter(in);
- if (c == ARROW_UP) {
- return CTRL_P;
- } else if (c == ARROW_DOWN) {
- return CTRL_N;
- } else if (c == ARROW_LEFT) {
- return CTRL_B;
- } else if (c == ARROW_RIGHT) {
- return CTRL_F;
- } else if (c == HOME_CODE) {
- return CTRL_A;
- } else if (c == END_CODE) {
- return CTRL_E;
- } else if (c == DEL_THIRD) {
- c = readCharacter(in); // read 4th
- return DELETE;
+ key = UnixKey.valueOf(c);
+
+ if (key == ARROW_UP) {
+ return CTRL_P.code;
+ }
+ else if (key == ARROW_DOWN) {
+ return CTRL_N.code;
+ }
+ else if (key == ARROW_LEFT) {
+ return CTRL_B.code;
+ }
+ else if (key == ARROW_RIGHT) {
+ return CTRL_F.code;
+ }
+ else if (key == HOME_CODE) {
+ return CTRL_A.code;
+ }
+ else if (key == END_CODE) {
+ return CTRL_E.code;
+ }
+ else if (key == DEL_THIRD) {
+ readCharacter(in); // read 4th & ignore
+ return DELETE.code;
}
}
}
+
// handle unicode characters, thanks for a patch from [email protected]
if (c > 128) {
- // handle unicode characters longer than 2 bytes,
- // thanks to [email protected]
+ // handle unicode characters longer than 2 bytes,
+ // thanks to [email protected]
replayStream.setInput(c, in);
-// replayReader = new InputStreamReader(replayStream, encoding);
+ // replayReader = new InputStreamReader(replayStream, encoding);
c = replayReader.read();
-
}
return c;
}
/**
- * This is awkward and inefficient, but probably the minimal way to add
- * UTF-8 support to JLine
- *
- * @author <a href="mailto:[email protected]">Marc Herbert</a>
+ * Unix keys.
*/
- static class ReplayPrefixOneCharInputStream extends InputStream {
- byte firstByte;
- int byteLength;
- InputStream wrappedStream;
- int byteRead;
+ public static enum UnixKey
+ {
+ ARROW_START(27),
- final String encoding;
+ ARROW_PREFIX(91),
- public ReplayPrefixOneCharInputStream(String encoding) {
- this.encoding = encoding;
- }
+ ARROW_LEFT(68),
- public void setInput(int recorded, InputStream wrapped) throws
IOException {
- this.byteRead = 0;
- this.firstByte = (byte) recorded;
- this.wrappedStream = wrapped;
+ ARROW_RIGHT(67),
- byteLength = 1;
- if (encoding.equalsIgnoreCase("UTF-8"))
- setInputUTF8(recorded, wrapped);
- else if (encoding.equalsIgnoreCase("UTF-16"))
- byteLength = 2;
- else if (encoding.equalsIgnoreCase("UTF-32"))
- byteLength = 4;
- }
+ ARROW_UP(65),
+
+ ARROW_DOWN(66),
+
+ O_PREFIX(79),
+
+ HOME_CODE(72),
+ END_CODE(70),
- public void setInputUTF8(int recorded, InputStream wrapped) throws
IOException {
- // 110yyyyy 10zzzzzz
- if ((firstByte & (byte) 0xE0) == (byte) 0xC0)
- this.byteLength = 2;
- // 1110xxxx 10yyyyyy 10zzzzzz
- else if ((firstByte & (byte) 0xF0) == (byte) 0xE0)
- this.byteLength = 3;
- // 11110www 10xxxxxx 10yyyyyy 10zzzzzz
- else if ((firstByte & (byte) 0xF8) == (byte) 0xF0)
- this.byteLength = 4;
- else
- throw new IOException("invalid UTF-8 first byte: " +
firstByte);
+ DEL_THIRD(51),
+
+ DEL_SECOND(126),;
+
+ public final short code;
+
+ UnixKey(final int code) {
+ this.code = (short) code;
}
- public int read() throws IOException {
- if (available() == 0)
- return -1;
+ private static final Map<Short, UnixKey> codes;
- byteRead++;
+ static {
+ Map<Short, UnixKey> map = new HashMap<Short, UnixKey>();
- if (byteRead == 1)
- return firstByte;
+ for (UnixKey key : UnixKey.values()) {
+ map.put(key.code, key);
+ }
- return wrappedStream.read();
+ codes = map;
}
- /**
- * InputStreamReader is greedy and will try to read bytes in advance. We
- * do NOT want this to happen since we use a temporary/"losing bytes"
- * InputStreamReader above, that's why we hide the real
- * wrappedStream.available() here.
- */
- public int available() {
- return byteLength - byteRead;
+ public static UnixKey valueOf(final int code) {
+ return codes.get((short) code);
}
}
-
}
Modified:
karaf/trunk/webconsole/gogo/src/main/java/org/apache/karaf/webconsole/gogo/WebTerminal.java
URL:
http://svn.apache.org/viewvc/karaf/trunk/webconsole/gogo/src/main/java/org/apache/karaf/webconsole/gogo/WebTerminal.java?rev=1000362&r1=1000361&r2=1000362&view=diff
==============================================================================
---
karaf/trunk/webconsole/gogo/src/main/java/org/apache/karaf/webconsole/gogo/WebTerminal.java
(original)
+++
karaf/trunk/webconsole/gogo/src/main/java/org/apache/karaf/webconsole/gogo/WebTerminal.java
Thu Sep 23 09:07:42 2010
@@ -16,33 +16,31 @@
*/
package org.apache.karaf.webconsole.gogo;
-import java.io.InputStreamReader;
-import java.io.InputStream;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.HashMap;
+import java.util.Map;
-public class WebTerminal extends jline.Terminal {
+import jline.TerminalSupport;
+import jline.console.Key;
+import jline.internal.ReplayPrefixOneCharInputStream;
- public static final short ARROW_START = 27;
- public static final short ARROW_PREFIX = 91;
- public static final short ARROW_LEFT = 68;
- public static final short ARROW_RIGHT = 67;
- public static final short ARROW_UP = 65;
- public static final short ARROW_DOWN = 66;
- public static final short O_PREFIX = 79;
- public static final short HOME_CODE = 72;
- public static final short END_CODE = 70;
+import static jline.console.Key.*;
+import static org.apache.karaf.webconsole.gogo.WebTerminal.UnixKey.*;
- public static final short DEL_THIRD = 51;
- public static final short DEL_SECOND = 126;
+public class WebTerminal extends TerminalSupport {
private int width;
private int height;
- private boolean backspaceDeleteSwitched = false;
private String encoding = System.getProperty("input.encoding", "UTF-8");
private ReplayPrefixOneCharInputStream replayStream = new
ReplayPrefixOneCharInputStream(encoding);
private InputStreamReader replayReader;
+ private boolean deleteSendsBackspace = false;
+ private boolean backspaceSendsDelete = false;
public WebTerminal(int width, int height) {
+ super(true);
this.width = width;
this.height = height;
try {
@@ -52,87 +50,76 @@ public class WebTerminal extends jline.T
}
}
- public void initializeTerminal() throws Exception {
+ public void init() throws Exception {
}
- public void restoreTerminal() throws Exception {
+ public void restore() throws Exception {
}
- public int getTerminalWidth() {
+ public int getWidth() {
return width;
}
- public int getTerminalHeight() {
+ public int getHeight() {
return height;
}
- public boolean isSupported() {
- return true;
- }
-
- public boolean getEcho() {
- return false;
- }
-
- public boolean isEchoEnabled() {
- return false;
- }
-
- public void enableEcho() {
- }
-
- public void disableEcho() {
- }
-
- public int readVirtualKey(InputStream in) throws IOException {
+ @Override
+ public int readVirtualKey(final InputStream in) throws IOException {
int c = readCharacter(in);
- if (backspaceDeleteSwitched) {
- if (c == DELETE) {
- c = '\b';
- } else if (c == '\b') {
- c = DELETE;
- }
+ if (Key.valueOf(c) == DELETE && deleteSendsBackspace) {
+ c = BACKSPACE.code;
+ } else if (Key.valueOf(c) == BACKSPACE && backspaceSendsDelete) {
+ c = DELETE.code;
}
- // in Unix terminals, arrow keys are represented by
- // a sequence of 3 characters. E.g., the up arrow
- // key yields 27, 91, 68
- if (c == ARROW_START) {
- //also the escape key is 27
- //thats why we read until we
- //have something different than 27
- //this is a bugfix, because otherwise
- //pressing escape and than an arrow key
- //was an undefined state
- while (c == ARROW_START) {
+ UnixKey key = UnixKey.valueOf(c);
+
+ // in Unix terminals, arrow keys are represented by a sequence of 3
characters. E.g., the up arrow key yields 27, 91, 68
+ if (key == ARROW_START) {
+ // also the escape key is 27 thats why we read until we have
something different than 27
+ // this is a bugfix, because otherwise pressing escape and than an
arrow key was an undefined state
+ while (key == ARROW_START) {
c = readCharacter(in);
+ key = UnixKey.valueOf(c);
}
- if (c == ARROW_PREFIX || c == O_PREFIX) {
+
+ if (key == ARROW_PREFIX || key == O_PREFIX) {
c = readCharacter(in);
- if (c == ARROW_UP) {
- return CTRL_P;
- } else if (c == ARROW_DOWN) {
- return CTRL_N;
- } else if (c == ARROW_LEFT) {
- return CTRL_B;
- } else if (c == ARROW_RIGHT) {
- return CTRL_F;
- } else if (c == HOME_CODE) {
- return CTRL_A;
- } else if (c == END_CODE) {
- return CTRL_E;
- } else if (c == DEL_THIRD) {
- c = readCharacter(in); // read 4th
- return DELETE;
+ key = UnixKey.valueOf(c);
+
+ if (key == ARROW_UP) {
+ return CTRL_P.code;
+ }
+ else if (key == ARROW_DOWN) {
+ return CTRL_N.code;
+ }
+ else if (key == ARROW_LEFT) {
+ return CTRL_B.code;
+ }
+ else if (key == ARROW_RIGHT) {
+ return CTRL_F.code;
+ }
+ else if (key == HOME_CODE) {
+ return CTRL_A.code;
+ }
+ else if (key == END_CODE) {
+ return CTRL_E.code;
+ }
+ else if (key == DEL_THIRD) {
+ readCharacter(in); // read 4th & ignore
+ return DELETE.code;
}
}
}
+
// handle unicode characters, thanks for a patch from [email protected]
if (c > 128) {
- // handle unicode characters longer than 2 bytes,
- // thanks to [email protected]
+ // handle unicode characters longer than 2 bytes,
+ // thanks to [email protected]
replayStream.setInput(c, in);
+ // replayReader = new InputStreamReader(replayStream, encoding);
c = replayReader.read();
}
@@ -140,78 +127,52 @@ public class WebTerminal extends jline.T
}
/**
- * This is awkward and inefficient, but probably the minimal way to add
- * UTF-8 support to JLine
- *
- * @author <a href="mailto:[email protected]">Marc Herbert</a>
+ * Unix keys.
*/
- static class ReplayPrefixOneCharInputStream extends InputStream {
+ public static enum UnixKey
+ {
+ ARROW_START(27),
- byte firstByte;
- int byteLength;
- InputStream wrappedStream;
- int byteRead;
-
- final String encoding;
-
- public ReplayPrefixOneCharInputStream(String encoding) {
- this.encoding = encoding;
- }
-
- public void setInput(int recorded, InputStream wrapped) throws
IOException {
- this.byteRead = 0;
- this.firstByte = (byte) recorded;
- this.wrappedStream = wrapped;
-
- byteLength = 1;
- if (encoding.equalsIgnoreCase("UTF-8")) {
- setInputUTF8(recorded, wrapped);
- } else if (encoding.equalsIgnoreCase("UTF-16")) {
- byteLength = 2;
- } else if (encoding.equalsIgnoreCase("UTF-32")) {
- byteLength = 4;
- }
- }
+ ARROW_PREFIX(91),
+ ARROW_LEFT(68),
- public void setInputUTF8(int recorded, InputStream wrapped) throws
IOException {
- // 110yyyyy 10zzzzzz
- if ((firstByte & (byte) 0xE0) == (byte) 0xC0) {
- this.byteLength = 2;
- // 1110xxxx 10yyyyyy 10zzzzzz
- } else if ((firstByte & (byte) 0xF0) == (byte) 0xE0) {
- this.byteLength = 3;
- // 11110www 10xxxxxx 10yyyyyy 10zzzzzz
- } else if ((firstByte & (byte) 0xF8) == (byte) 0xF0) {
- this.byteLength = 4;
- } else {
- throw new IOException("invalid UTF-8 first byte: " +
firstByte);
- }
+ ARROW_RIGHT(67),
+
+ ARROW_UP(65),
+
+ ARROW_DOWN(66),
+
+ O_PREFIX(79),
+
+ HOME_CODE(72),
+
+ END_CODE(70),
+
+ DEL_THIRD(51),
+
+ DEL_SECOND(126),;
+
+ public final short code;
+
+ UnixKey(final int code) {
+ this.code = (short) code;
}
- public int read() throws IOException {
- if (available() == 0) {
- return -1;
- }
+ private static final Map<Short, UnixKey> codes;
- byteRead++;
+ static {
+ Map<Short, UnixKey> map = new HashMap<Short, UnixKey>();
- if (byteRead == 1) {
- return firstByte;
+ for (UnixKey key : UnixKey.values()) {
+ map.put(key.code, key);
}
- return wrappedStream.read();
+ codes = map;
}
- /**
- * InputStreamReader is greedy and will try to read bytes in advance. We
- * do NOT want this to happen since we use a temporary/"losing bytes"
- * InputStreamReader above, that's why we hide the real
- * wrappedStream.available() here.
- */
- public int available() {
- return byteLength - byteRead;
+ public static UnixKey valueOf(final int code) {
+ return codes.get((short) code);
}
}
-
}