diff --git a/src/main/java/org/springframework/shell/Bootstrap.java b/src/main/java/org/springframework/shell/Bootstrap.java index 3e4cf343..f948d6cb 100644 --- a/src/main/java/org/springframework/shell/Bootstrap.java +++ b/src/main/java/org/springframework/shell/Bootstrap.java @@ -105,10 +105,6 @@ public class Bootstrap { annctx.getBeanFactory().registerSingleton("commandLine", commandLine); } - protected void createAndRegisterBeanDefinition(GenericApplicationContext annctx, Class clazz) { - createAndRegisterBeanDefinition(annctx, clazz, null); - } - protected void createAndRegisterBeanDefinition(GenericApplicationContext annctx, Class clazz, String name) { RootBeanDefinition rbd = new RootBeanDefinition(); rbd.setBeanClass(clazz); @@ -146,7 +142,6 @@ public class Bootstrap { } else { shell.start(); - shell.promptLoop(); exitShellRequest = shell.getExitShellRequest(); if (exitShellRequest == null) { // shouldn't really happen, but we'll fallback to this anyway diff --git a/src/main/java/org/springframework/shell/core/JLineShell.java b/src/main/java/org/springframework/shell/core/JLineShell.java index b7f647bf..402322d7 100644 --- a/src/main/java/org/springframework/shell/core/JLineShell.java +++ b/src/main/java/org/springframework/shell/core/JLineShell.java @@ -40,6 +40,7 @@ import java.util.logging.Logger; import jline.WindowsTerminal; import jline.console.ConsoleReader; +import jline.console.UserInterruptException; import jline.console.history.History; import jline.console.history.MemoryHistory; @@ -88,7 +89,7 @@ public abstract class JLineShell extends AbstractShell implements Shell, Runnabl private static final String BEL = "\007"; // Fields - protected ConsoleReader reader; + protected volatile ConsoleReader reader; private boolean developmentMode = false; @@ -254,6 +255,7 @@ public abstract class JLineShell extends AbstractShell implements Shell, Runnabl throw new IllegalStateException("Cannot start console class", ioe); } consoleReader.setExpandEvents(false); + consoleReader.setHandleUserInterrupt(true); return consoleReader; } @@ -515,22 +517,25 @@ public abstract class JLineShell extends AbstractShell implements Shell, Runnabl */ public void promptLoop() { setShellStatus(Status.USER_INPUT); - String line; + String line = null; String prompt = getPromptText(); try { - while (exitShellRequest == null && (reader != null && ((line = reader.readLine()) != null))) { + while (exitShellRequest == null) { + try { + line = reader.readLine(); + } + catch (UserInterruptException e) { + if (e.getPartialLine().length() == 0) { + exitShellRequest = ExitShellRequest.FATAL_EXIT; + } + } JLineLogHandler.resetMessageTracking(); setShellStatus(Status.USER_INPUT); - if (!StringUtils.hasText(line)) { - //generate prompt if empty line, the prompt maybe showing the time or something else that updates - //independent of the lack of a command to execute. - prompt = generatePromptUpdate(prompt); - continue; + if (StringUtils.hasText(line)) { + executeCommand(line); } - - executeCommand(line); //update the prompt after the command has been executed in case an application event listener in the //command changes state in the prompt provider. prompt = generatePromptUpdate(prompt);