From b2a004398ce7c42e9a8c6810b46fe9a4f59de6f7 Mon Sep 17 00:00:00 2001 From: mpollack Date: Wed, 2 Apr 2014 00:45:46 -0400 Subject: [PATCH] SHL-107 - Prompt not re-evaluated if the user input is just an enter command Thanks to the PR 7bf8be15bf8f7082e022a990680da7c818f572cf for the fix --- .../shell/core/JLineShell.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/springframework/shell/core/JLineShell.java b/src/main/java/org/springframework/shell/core/JLineShell.java index 023b842a..6e0f74eb 100644 --- a/src/main/java/org/springframework/shell/core/JLineShell.java +++ b/src/main/java/org/springframework/shell/core/JLineShell.java @@ -520,18 +520,18 @@ public abstract class JLineShell extends AbstractShell implements Shell, Runnabl JLineLogHandler.resetMessageTracking(); setShellStatus(Status.USER_INPUT); - if ("".equals(line)) { + 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. + generatePromptUpdate(prompt); continue; } 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. + generatePromptUpdate(prompt); - String newPrmpt = getPromptText(); - if (!ObjectUtils.nullSafeEquals(prompt, newPrmpt)) { - prompt = newPrmpt; - setPromptPath(null); - } - // System.out.println("executed command:" + line); } } catch (IOException ioe) { @@ -540,6 +540,13 @@ public abstract class JLineShell extends AbstractShell implements Shell, Runnabl setShellStatus(Status.SHUTTING_DOWN); } + public void generatePromptUpdate(String existingPrompt) { + String newPrompt = getPromptText(); + if (!ObjectUtils.nullSafeEquals(existingPrompt, newPrompt)) { + setPromptPath(null); + } + } + public void setDevelopmentMode(final boolean developmentMode) { JLineLogHandler.setIncludeThreadName(developmentMode); JLineLogHandler.setSuppressDuplicateMessages(!developmentMode); // We want to see duplicate messages during