Skip to content

Commit

Permalink
Merge pull request #359 from stalep/2.0
Browse files Browse the repository at this point in the history
Updated to work with latest æsh api changes in version 0.43
  • Loading branch information
lincolnthree committed Nov 15, 2013
2 parents b98fc5f + 1945d00 commit 5e6ff52
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;

import javax.inject.Inject;

Expand All @@ -28,10 +29,14 @@ public class ShellHandle

private Shell shell;

public void initialize(File currentResource, InputStream stdIn, OutputStream stdOut, OutputStream stdErr)
public void initialize(File currentResource, InputStream stdIn, PrintStream stdOut, PrintStream stdErr)
{
Settings settings = new SettingsBuilder().inputStream(stdIn)
.outputStream(stdOut).outputStreamError(stdErr).create();
Settings settings = new SettingsBuilder()
.inputStream(stdIn)
.outputStream(stdOut)
.outputStreamError(stdErr)
.enableMan(true)
.create();
this.shell = shellFactory.createShell(currentResource, settings);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import javax.inject.Inject;

import org.jboss.aesh.console.helper.ManProvider;
import org.jboss.aesh.console.settings.Settings;
import org.jboss.forge.addon.resource.FileResource;
import org.jboss.forge.addon.resource.ResourceFactory;
Expand All @@ -28,22 +29,25 @@ public class ShellFactoryImpl implements ShellFactory
private final ResourceFactory resourceFactory;
private final AddonRegistry addonRegistry;
private final CommandManager commandManager;
private final ManProvider manProvider;

@Inject
public ShellFactoryImpl(AddonRegistry addonRegistry, CommandManager commandManager, ResourceFactory resourceFactory)
public ShellFactoryImpl(AddonRegistry addonRegistry, CommandManager commandManager,
ResourceFactory resourceFactory, ManProvider manProvider)
{
super();
this.addonRegistry = addonRegistry;
this.commandManager = commandManager;
this.resourceFactory = resourceFactory;
this.manProvider = manProvider;
}

@Override
public Shell createShell(File initialSelection, Settings settings)
{
Assert.notNull(settings, "Settings cannot be null");
FileResource<?> initialResource = resourceFactory.create(initialSelection).reify(FileResource.class);
return new ShellImpl(initialResource, settings, commandManager, addonRegistry);
return new ShellImpl(initialResource, settings, commandManager, addonRegistry, manProvider);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.jboss.aesh.console.Console;
import org.jboss.aesh.console.Prompt;
import org.jboss.aesh.console.helper.InterruptHook;
import org.jboss.aesh.console.helper.ManProvider;
import org.jboss.aesh.console.settings.Settings;
import org.jboss.aesh.console.settings.SettingsBuilder;
import org.jboss.aesh.terminal.CharacterType;
Expand Down Expand Up @@ -55,7 +56,7 @@ public class ShellImpl implements Shell
private final UIOutput output;

public ShellImpl(FileResource<?> initialResource, Settings settings, CommandManager commandManager,
AddonRegistry addonRegistry)
AddonRegistry addonRegistry, ManProvider manProvider)
{
this.currentResource = initialResource;
this.addonRegistry = addonRegistry;
Expand All @@ -68,9 +69,12 @@ public void handleInterrupt(Console console)
console.clearBufferAndDisplayPrompt();
}
}).create();
this.console = new AeshConsoleBuilder().prompt(createPrompt()).settings(newSettings)
.commandRegistry(new ForgeCommandRegistry(this, commandManager))
.create();
this.console = new AeshConsoleBuilder()
.prompt(createPrompt())
.settings(newSettings)
.commandRegistry(new ForgeCommandRegistry(this, commandManager))
.manProvider(manProvider)
.create();
this.output = new ShellUIOutputImpl(console);
this.console.start();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@

package org.jboss.forge.addon.shell;

import org.jboss.aesh.console.reader.AeshPrintStream;
import org.jboss.aesh.terminal.Color;
import org.jboss.aesh.terminal.TerminalColor;
import org.jboss.aesh.terminal.TerminalString;

import java.io.PrintStream;

/**
* Used to generate properly formatted status messages.
*
Expand All @@ -20,25 +21,25 @@
*/
public abstract class ShellMessages
{
public static void success(final AeshPrintStream writer, final String message)
public static void success(final PrintStream writer, final String message)
{
writer.print(new TerminalString("***SUCCESS*** ", new TerminalColor(Color.GREEN, Color.DEFAULT)));
writer.println(message);
}

public static void error(final AeshPrintStream writer, final String message)
public static void error(final PrintStream writer, final String message)
{
writer.print(new TerminalString("***ERROR*** ", new TerminalColor(Color.RED, Color.DEFAULT)));
writer.println(message);
}

public static void info(final AeshPrintStream writer, final String message)
public static void info(final PrintStream writer, final String message)
{
writer.print(new TerminalString("***INFO*** ", new TerminalColor(Color.BLUE, Color.DEFAULT)));
writer.println(message);
}

public static void warn(final AeshPrintStream writer, final String message)
public static void warn(final PrintStream writer, final String message)
{
writer.print(new TerminalString("***WARNING*** ", new TerminalColor(Color.YELLOW, Color.DEFAULT)));
writer.println(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import java.util.List;

import org.jboss.aesh.console.command.Command;
import org.jboss.aesh.console.command.CommandInvocation;
import org.jboss.aesh.console.command.CommandResult;
import org.jboss.aesh.console.command.invocation.CommandInvocation;
import org.jboss.aesh.extensions.manual.ManCommand;
import org.jboss.forge.addon.resource.FileResource;
import org.jboss.forge.addon.shell.ShellImpl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@
import java.util.TreeSet;

import org.jboss.aesh.cl.parser.CommandLineParser;
import org.jboss.aesh.console.command.AeshCommandContainer;
import org.jboss.aesh.console.command.AeshCommandRegistryBuilder;
import org.jboss.aesh.console.command.CommandContainer;
import org.jboss.aesh.console.command.CommandNotFoundException;
import org.jboss.aesh.console.command.CommandRegistry;
import org.jboss.aesh.console.command.container.AeshCommandContainer;
import org.jboss.aesh.console.command.container.CommandContainer;
import org.jboss.aesh.console.command.registry.AeshCommandRegistryBuilder;
import org.jboss.aesh.console.command.registry.CommandRegistry;
import org.jboss.aesh.extensions.grep.Grep;
import org.jboss.aesh.extensions.less.aesh.Less;
import org.jboss.aesh.extensions.manual.aesh.Man;
import org.jboss.aesh.extensions.more.aesh.More;
import org.jboss.forge.addon.shell.CommandManager;
import org.jboss.forge.addon.shell.ShellImpl;
Expand All @@ -42,14 +41,11 @@ public ForgeCommandRegistry(ShellImpl shell, CommandManager commandManager)
this.shell = shell;
this.commandManager = commandManager;

Man manCommand = new Man();
manCommand.setRegistry(this);
// Use Aesh commands
this.aeshCommandRegistry = new AeshCommandRegistryBuilder()
.command(Grep.class)
.command(Less.class)
.command(More.class)
.command(manCommand)
.create();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2012 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Eclipse Public License version 1.0, available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.jboss.forge.addon.shell.aesh;

import org.jboss.aesh.console.helper.ManProvider;

import java.io.InputStream;

/**
* @author <a href="mailto:stale.pedersen@jboss.org">Ståle W. Pedersen</a>
*/
public class ForgeManProvider implements ManProvider {
@Override
public InputStream getManualDocument(String command) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.io.OutputStream;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.io.PrintStream;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
Expand Down Expand Up @@ -338,8 +339,8 @@ public Settings getSettings()
inputStream = new PipedInputStream(stdin);
settings = new SettingsBuilder()
.inputStream(inputStream)
.outputStream(stdout)
.outputStreamError(stderr)
.outputStream(new PrintStream(stdout))
.outputStreamError(new PrintStream(stderr))
.name("test")
.logging(true)
.terminal(new TestTerminal())
Expand Down

0 comments on commit 5e6ff52

Please sign in to comment.