Skip to content

Commit

Permalink
[FORGE-1591]
Browse files Browse the repository at this point in the history
forge should exit when the ignoreeof threshold is exceeded
  • Loading branch information
stalep committed Feb 22, 2014
1 parent 5b11faa commit 60943d6
Showing 1 changed file with 45 additions and 25 deletions.
70 changes: 45 additions & 25 deletions shell/impl/src/main/java/org/jboss/forge/addon/shell/ShellImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package org.jboss.forge.addon.shell;

import java.io.File;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
Expand All @@ -17,8 +18,12 @@
import org.jboss.aesh.console.AeshConsoleBuilder;
import org.jboss.aesh.console.Console;
import org.jboss.aesh.console.Prompt;
import org.jboss.aesh.console.command.CommandNotFoundException;
import org.jboss.aesh.console.command.container.CommandContainer;
import org.jboss.aesh.console.command.invocation.AeshCommandInvocation;
import org.jboss.aesh.console.export.ExportManager;
import org.jboss.aesh.console.helper.InterruptHook;
import org.jboss.aesh.console.operator.ControlOperator;
import org.jboss.aesh.console.settings.Settings;
import org.jboss.aesh.console.settings.SettingsBuilder;
import org.jboss.aesh.edit.actions.Action;
Expand Down Expand Up @@ -61,7 +66,7 @@ public class ShellImpl implements Shell, UIRuntime
private Resource<?> currentResource;

private final AddonRegistry addonRegistry;
private final AeshConsole console;
private AeshConsole console;

This comment has been minimized.

Copy link
@gastaldi

gastaldi Feb 22, 2014

Member

Why not final anymore?

private final UIOutput output;
private final List<CommandExecutionListener> executionListeners = new LinkedList<>();

Expand All @@ -75,34 +80,13 @@ public ShellImpl(FileResource<?> initialResource, Settings settings,
File history = new File(forgeHome, "history");
File alias = new File(forgeHome, "alias");
File export = new File(forgeHome, "export");
final ForgeCommandRegistry registry =
new ForgeCommandRegistry(this, commandManager, commandFactory, commandManager .getConverterFactory());
Settings newSettings = new SettingsBuilder(settings)
.historyFile(history)
.aliasFile(alias)
.exportFile(export)
.interruptHook(new InterruptHook() {
@Override
public void handleInterrupt(Console console, Action action) {
if (action == Action.INTERRUPT)
{
console.getShell().out().println("^C");
console.clearBufferAndDisplayPrompt();
}
else if (action == Action.IGNOREEOF)
{
console.getShell().out().println("Use \"exit\" to leave the shell.");
console.clearBufferAndDisplayPrompt();
}
else
{
//we should quit here
//console.getShell().out().println();
//console.stop();
}
}
}).create();
final ForgeCommandRegistry registry = new ForgeCommandRegistry(this, commandManager, commandFactory,
commandManager
.getConverterFactory());
.interruptHook(new ForgeInterruptHook(registry, this.console)).create();

This comment has been minimized.

Copy link
@gastaldi

gastaldi Feb 22, 2014

Member

Looks like console is null in here?

this.console = new AeshConsoleBuilder()
.prompt(createPrompt())
.settings(newSettings)
Expand Down Expand Up @@ -251,4 +235,40 @@ public UIPrompt createPrompt(UIContext context)
{
return new ShellUIPromptImpl(context, console);
}

private static class ForgeInterruptHook implements InterruptHook {

private final ForgeCommandRegistry registry;
private final AeshConsole aeshConsole;

ForgeInterruptHook(ForgeCommandRegistry registry, AeshConsole aeshConsole) {
this.registry = registry;
this.aeshConsole = aeshConsole;
}
@Override
public void handleInterrupt(Console console, Action action) {
if (action == Action.INTERRUPT)
{
console.getShell().out().println("^C");
console.clearBufferAndDisplayPrompt();
}
else if (action == Action.IGNOREEOF)
{
console.getShell().out().println("Use \"exit\" to leave the shell.");
console.clearBufferAndDisplayPrompt();
}
else
{
try {
CommandContainer exitCommand = registry.getCommand("exit","");
//print a new line so we exit nicely
console.getShell().out().println();
exitCommand.getCommand().execute(new AeshCommandInvocation(aeshConsole, ControlOperator.NONE, null));
}
catch (CommandNotFoundException | IOException ignored) {
}
}

}
}
}

0 comments on commit 60943d6

Please sign in to comment.