Permalink
Browse files

replace jline with jreadline for jboss-cli

  • Loading branch information...
1 parent 7dfed92 commit 2f5f62686d9edb77f5d3ecc39531546d1d1f27b1 @stalep stalep committed with bstansberry Jun 13, 2012
View
@@ -475,8 +475,12 @@
<maven-resource group="org.jboss.spec.javax.xml.ws" artifact="jboss-jaxws-api_2.2_spec"/>
</module-def>
- <module-def name="jline">
- <maven-resource group="jline" artifact="jline"/>
+ <module-def name="org.jboss.jreadline">
+ <maven-resource group="org.jboss.jreadline" artifact="jreadline"/>
+ </module-def>
+
+ <module-def name="org.fusesource.jansi">
+ <maven-resource group="org.fusesource.jansi" artifact="jansi"/>
</module-def>
<module-def name="net.jcip">
View
@@ -353,8 +353,13 @@
</dependency>
<dependency>
- <groupId>jline</groupId>
- <artifactId>jline</artifactId>
+ <groupId>org.jboss.jreadline</groupId>
+ <artifactId>jreadline</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.fusesource.jansi</groupId>
+ <artifactId>jansi</artifactId>
</dependency>
<dependency>
@@ -22,7 +22,7 @@
~ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-->
-<module xmlns="urn:jboss:module:1.1" name="jline">
+<module xmlns="urn:jboss:module:1.1" name="org.fusesource.jansi">
<properties>
<property name="jboss.api" value="private"/>
</properties>
@@ -34,7 +34,7 @@
</resources>
<dependencies>
- <module name="jline"/>
+ <module name="org.jboss.jreadline"/>
<module name="org.jboss.logmanager" services="import"/>
<module name="org.jboss.as.controller-client"/>
<module name="org.jboss.logging"/>
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ ~ JBoss, Home of Professional Open Source.
+ ~ Copyright 2010, Red Hat, Inc., and individual contributors
+ ~ as indicated by the @author tags. See the copyright.txt file in the
+ ~ distribution for a full listing of individual contributors.
+ ~
+ ~ This is free software; you can redistribute it and/or modify it
+ ~ under the terms of the GNU Lesser General Public License as
+ ~ published by the Free Software Foundation; either version 2.1 of
+ ~ the License, or (at your option) any later version.
+ ~
+ ~ This software is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ ~ Lesser General Public License for more details.
+ ~
+ ~ You should have received a copy of the GNU Lesser General Public
+ ~ License along with this software; if not, write to the Free
+ ~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ ~ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ -->
+
+<module xmlns="urn:jboss:module:1.1" name="org.jboss.jreadline">
+ <properties>
+ <property name="jboss.api" value="private"/>
+ </properties>
+
+ <resources>
+ <!-- Insert resources here -->
+ </resources>
+
+ <dependencies>
+ <module name="org.fusesource.jansi" />
+ </dependencies>
+</module>
View
@@ -63,8 +63,8 @@
<dependencies>
<dependency>
- <groupId>jline</groupId>
- <artifactId>jline</artifactId>
+ <groupId>org.jboss.jreadline</groupId>
+ <artifactId>jreadline</artifactId>
</dependency>
<dependency>
@@ -132,6 +132,7 @@
import org.jboss.as.controller.client.ModelControllerClient;
import org.jboss.as.protocol.StreamUtils;
import org.jboss.dmr.ModelNode;
+import org.jboss.jreadline.console.settings.Settings;
import org.jboss.sasl.callback.DigestHashCallback;
import org.jboss.sasl.util.HexConverter;
@@ -292,10 +293,19 @@
}
protected void initBasicConsole(InputStream consoleInput, OutputStream consoleOutput) throws CliInitializationException {
- this.console = Console.Factory.getConsole(this, consoleInput, consoleOutput);
- console.setUseHistory(config.isHistoryEnabled());
- console.setHistoryFile(new File(config.getHistoryFileDir(), config.getHistoryFileName()));
- console.getHistory().setMaxSize(config.getHistoryMaxSize());
+ copyConfigSettingsToConsole(consoleInput, consoleOutput);
+ this.console = Console.Factory.getConsole(this);
+ }
+
+ private void copyConfigSettingsToConsole(InputStream consoleInput, OutputStream consoleOutput) {
+ if(consoleInput != null)
+ Settings.getInstance().setInputStream(consoleInput);
+ if(consoleOutput != null)
+ Settings.getInstance().setOutputStream(consoleOutput);
+
+ Settings.getInstance().setHistoryDisabled(!config.isHistoryEnabled());
+ Settings.getInstance().setHistoryFile(new File(config.getHistoryFileDir(), config.getHistoryFileName()));
+ Settings.getInstance().setHistorySize(config.getHistoryMaxSize());
}
private void initCommands() {
@@ -22,26 +22,21 @@
package org.jboss.as.cli.impl;
import java.io.File;
-import java.io.FileDescriptor;
-import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
-import java.io.UnsupportedEncodingException;
-import java.io.Writer;
import java.util.Collection;
import java.util.List;
-import java.util.Locale;
-
-import jline.Completor;
import org.jboss.as.cli.CliInitializationException;
import org.jboss.as.cli.CommandContext;
import org.jboss.as.cli.CommandHistory;
import org.jboss.as.cli.CommandLineCompleter;
-import org.jboss.as.protocol.StreamUtils;
+
+import org.jboss.jreadline.complete.CompleteOperation;
+import org.jboss.jreadline.complete.Completion;
+import org.jboss.jreadline.console.Config;
+import org.jboss.jreadline.console.settings.Settings;
/**
*
@@ -79,77 +74,40 @@ public static Console getConsole(CommandContext ctx) throws CliInitializationExc
public static Console getConsole(final CommandContext ctx, InputStream is, OutputStream os) throws CliInitializationException {
- final String bindingsName;
- final String osName = SecurityActions.getSystemProperty("os.name").toLowerCase(Locale.ENGLISH);
- if(osName.indexOf("windows") >= 0) {
- bindingsName = "keybindings/jline-windows-bindings.properties";
- } else if(osName.startsWith("mac")) {
- bindingsName = "keybindings/jline-mac-bindings.properties";
- } else {
- bindingsName = "keybindings/jline-default-bindings.properties";
- }
-
- if(is == null) {
- is = new FileInputStream(FileDescriptor.in);
- }
- if(os == null) {
- os = System.out;
- }
- final Writer writer;
+ org.jboss.jreadline.console.Console jReadlineConsole = null;
try {
- String encoding = SecurityActions.getSystemProperty("jline.WindowsTerminal.output.encoding");
- if(encoding == null) {
- encoding = SecurityActions.getSystemProperty("file.encoding");
- }
- writer = new PrintWriter(new OutputStreamWriter(os, encoding));
- } catch (UnsupportedEncodingException e) {
- throw new CliInitializationException("Failed to initialize console writer.", e);
- }
-
- ClassLoader cl = SecurityActions.getClassLoader(Factory.class);
- InputStream bindingsIs = cl.getResourceAsStream(bindingsName);
- final jline.ConsoleReader jlineConsole;
- if(bindingsIs == null) {
- System.err.println("Failed to locate key bindings for OS '" + osName +"': " + bindingsName);
- try {
- jlineConsole = new jline.ConsoleReader(is, writer);
- } catch (IOException e) {
- throw new IllegalStateException("Failed to initialize console reader", e);
- }
- } else {
- try {
- jlineConsole = new jline.ConsoleReader(is, writer, bindingsIs);
- } catch(Exception e) {
- throw new IllegalStateException("Failed to initialize console reader", e);
- } finally {
- StreamUtils.safeClose(bindingsIs);
- }
+ jReadlineConsole = new org.jboss.jreadline.console.Console();
+ } catch (IOException e) {
+ e.printStackTrace();
}
+ final org.jboss.jreadline.console.Console finalJReadlineConsole = jReadlineConsole;
return new Console() {
private CommandContext cmdCtx = ctx;
- private jline.ConsoleReader console = jlineConsole;
+ private org.jboss.jreadline.console.Console console = finalJReadlineConsole;
private CommandHistory history = new HistoryImpl();
@Override
public void addCompleter(final CommandLineCompleter completer) {
- console.addCompletor(new Completor(){
- @SuppressWarnings({ "rawtypes", "unchecked" })
+ console.addCompletion(new Completion() {
@Override
- public int complete(String buffer, int cursor, List candidates) {
- return completer.complete(cmdCtx, buffer, cursor, candidates);
- }});
+ public void complete(CompleteOperation co) {
+ int offset = completer.complete(cmdCtx,
+ co.getBuffer(), co.getCursor(), co.getCompletionCandidates());
+ co.setOffset(offset);
+ }
+ });
}
@Override
public boolean isUseHistory() {
- return jlineConsole.getUseHistory();
+ return !Settings.getInstance().isHistoryDisabled();
}
@Override
public void setUseHistory(boolean useHistory) {
- jlineConsole.setUseHistory(useHistory);
+ Settings.getInstance().setHistoryDisabled(!useHistory);
}
@Override
@@ -159,30 +117,26 @@ public CommandHistory getHistory() {
@Override
public void setHistoryFile(File f) {
- try {
- console.getHistory().setHistoryFile(f);
- } catch (IOException e) {
- System.err.println("Failed to setup the history file: " + f.getAbsolutePath());
- e.printStackTrace();
- }
+ Settings.getInstance().setHistoryFile(f);
}
@Override
public void clearScreen() {
try {
- console.setDefaultPrompt("");// it has to be reset apparently
- // because otherwise it'll be printed
- // twice
- console.clearScreen();
+ console.clear();
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void printColumns(Collection<String> list) {
+ String[] newList = new String[list.size()];
+ list.toArray(newList);
try {
- console.printColumns(list);
+ console.pushToConsole(
+ org.jboss.jreadline.util.Parser.formatCompletions(newList,
+ console.getTerminalHeight(), console.getTerminalWidth()));
} catch (IOException e) {
e.printStackTrace();
}
@@ -191,7 +145,7 @@ public void printColumns(Collection<String> list) {
@Override
public void print(String line) {
try {
- console.printString(line);
+ console.pushToConsole(line);
} catch (IOException e) {
e.printStackTrace();
}
@@ -200,7 +154,7 @@ public void print(String line) {
@Override
public void printNewLine() {
try {
- console.printNewline();
+ console.pushToConsole(Config.getLineSeparator());
} catch (IOException e) {
e.printStackTrace();
}
@@ -209,7 +163,7 @@ public void printNewLine() {
@Override
public String readLine(String prompt) {
try {
- return console.readLine(prompt);
+ return console.read(prompt);
} catch (IOException e) {
e.printStackTrace();
return null;
@@ -219,7 +173,7 @@ public String readLine(String prompt) {
@Override
public String readLine(String prompt, Character mask) {
try {
- return console.readLine(prompt, mask);
+ return console.read(prompt, mask);
} catch (IOException e) {
e.printStackTrace();
return null;
@@ -231,17 +185,17 @@ public String readLine(String prompt, Character mask) {
@SuppressWarnings("unchecked")
@Override
public List<String> asList() {
- return console.getHistory().getHistoryList();
+ return console.getHistory().getAll();
}
@Override
public boolean isUseHistory() {
- return console.getUseHistory();
+ return !Settings.getInstance().isHistoryDisabled();
}
@Override
public void setUseHistory(boolean useHistory) {
- console.setUseHistory(useHistory);
+ Settings.getInstance().setHistoryDisabled(!useHistory);
}
@Override
@@ -251,12 +205,12 @@ public void clear() {
@Override
public void setMaxSize(int maxSize) {
- console.getHistory().setMaxSize(maxSize);
+ Settings.getInstance().setHistorySize(maxSize);
}
@Override
public int getMaxSize() {
- return console.getHistory().getMaxSize();
+ return Settings.getInstance().getHistorySize();
}
}};
}
Oops, something went wrong.

0 comments on commit 2f5f626

Please sign in to comment.