org.springframework.shell.core
Class JLineShell

java.lang.Object
  extended by org.springframework.shell.event.AbstractShellStatusPublisher
      extended by org.springframework.shell.core.AbstractShell
          extended by org.springframework.shell.core.JLineShell
All Implemented Interfaces:
Runnable, CommandMarker, Shell, ShellPromptAccessor, ShellStatusProvider
Direct Known Subclasses:
JLineShellComponent

public abstract class JLineShell
extends AbstractShell
implements CommandMarker, Shell, Runnable

Uses the feature-rich JLine library to provide an interactive shell.

Due to Windows' lack of color ANSI services out-of-the-box, this implementation automatically detects the classpath presence of Jansi and uses it if present. This library is not necessary for *nix machines, which support colour ANSI without any special effort. This implementation has been written to use reflection in order to avoid hard dependencies on Jansi.

Since:
1.0

Field Summary
protected  jline.ConsoleReader reader
           
protected  ShellStatusListener statusListener
           
 
Fields inherited from class org.springframework.shell.core.AbstractShell
completionKeys, exitShellRequest, inBlockComment, logger, ROO_PROMPT, shellPrompt
 
Fields inherited from class org.springframework.shell.event.AbstractShellStatusPublisher
shellStatus, shellStatusListeners
 
Fields inherited from interface org.springframework.shell.core.Shell
WINDOW_TITLE_SLOT
 
Constructor Summary
JLineShell()
           
 
Method Summary
protected  void closeShell()
          Should be called by a subclass before deactivating the shell.
protected  jline.ConsoleReader createAnsiWindowsReader()
           
protected  jline.ConsoleReader createConsoleReader()
          Creates new jline ConsoleReader.
 void flash(Level level, String message, String slot)
          Simple implementation of AbstractShell.flash(Level, String, String) that simply displays the message via the logger.
protected abstract  String getHistoryFileName()
          get history file name from provider.
 int getHistorySize()
           
protected  String getHomeAsString()
          Obtains the "roo.home" from the system property, falling back to the current working directory if missing.
protected abstract  String getProductName()
          get product name
protected abstract  String getPromptText()
          get prompt text from provider.
 String getStartupNotifications()
           
protected  String getVersion()
          get version information
 boolean isDevelopmentMode()
           
protected  void logCommandToOutput(String processedLine)
          Allows a subclass to actually write the resulting logged command to some form of output.
 void printBannerAndWelcome()
           
 void promptLoop()
          Presents a console prompt and allows the user to interact with the shell.
 void run()
           
 void setDevelopmentMode(boolean developmentMode)
          Indicates the shell should switch into a lower-level development mode.
 void setHistorySize(int historySize)
           
 void setPromptPath(String path)
          Base implementation of the Shell.setPromptPath(String) method, designed for simple shell implementations.
 void setPromptPath(String path, boolean overrideStyle)
          Default implementation of Shell#setPromptPath(String, boolean)) method to satisfy STS compatibility.
 
Methods inherited from class org.springframework.shell.core.AbstractShell
blockCommentBegin, blockCommentFinish, date, executeCommand, executeScriptLine, findResources, flashCustom, getExecutionStrategy, getExitShellRequest, getHome, getParser, getShellPrompt, handleExecutionResult, inlineComment, logCommandIfRequired, props, script, version, versionInfo
 
Methods inherited from class org.springframework.shell.event.AbstractShellStatusPublisher
addShellStatusListener, getShellStatus, removeShellStatusListener, setShellStatus, setShellStatus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.springframework.shell.core.Shell
executeCommand, getExitShellRequest, getHome
 
Methods inherited from interface org.springframework.shell.event.ShellStatusProvider
addShellStatusListener, getShellStatus, removeShellStatusListener
 
Methods inherited from interface org.springframework.shell.core.ShellPromptAccessor
getShellPrompt
 

Field Detail

reader

protected jline.ConsoleReader reader

statusListener

protected ShellStatusListener statusListener
Constructor Detail

JLineShell

public JLineShell()
Method Detail

run

public void run()
Specified by:
run in interface Runnable

createConsoleReader

protected jline.ConsoleReader createConsoleReader()
Creates new jline ConsoleReader. On Windows if jansi is available, uses createAnsiWindowsReader(). Otherwise, always creates a default ConsoleReader. Sub-classes of this class can plug in their version of ConsoleReader by overriding this method, if required.

Returns:
a jline ConsoleReader instance

printBannerAndWelcome

public void printBannerAndWelcome()

getStartupNotifications

public String getStartupNotifications()

setPromptPath

public void setPromptPath(String path)
Description copied from class: AbstractShell
Base implementation of the Shell.setPromptPath(String) method, designed for simple shell implementations. Advanced implementations (eg those that support ANSI codes etc) will likely want to override this method and set the AbstractShell.shellPrompt variable directly.

Specified by:
setPromptPath in interface Shell
Overrides:
setPromptPath in class AbstractShell
Parameters:
path - to set (can be null or empty; must NOT be formatted in any special way eg ANSI codes)

setPromptPath

public void setPromptPath(String path,
                          boolean overrideStyle)
Description copied from class: AbstractShell
Default implementation of Shell#setPromptPath(String, boolean)) method to satisfy STS compatibility.

Specified by:
setPromptPath in interface Shell
Overrides:
setPromptPath in class AbstractShell
Parameters:
path - to set (can be null or empty)

createAnsiWindowsReader

protected jline.ConsoleReader createAnsiWindowsReader()
                                               throws Exception
Throws:
Exception

flash

public void flash(Level level,
                  String message,
                  String slot)
Description copied from class: AbstractShell
Simple implementation of AbstractShell.flash(Level, String, String) that simply displays the message via the logger. It is strongly recommended shell implementations override this method with a more effective approach.

Specified by:
flash in interface Shell
Overrides:
flash in class AbstractShell
Parameters:
level - the importance of the message (cannot be null)
message - to display (cannot be null, but may be empty)
slot - the identification slot for the message (cannot be null or empty)

promptLoop

public void promptLoop()
Description copied from interface: Shell
Presents a console prompt and allows the user to interact with the shell. The shell should not return to the caller until the user has finished their session (by way of a "quit" or similar command).

Specified by:
promptLoop in interface Shell

setDevelopmentMode

public void setDevelopmentMode(boolean developmentMode)
Description copied from interface: Shell
Indicates the shell should switch into a lower-level development mode. The exact meaning varies by shell implementation.

Specified by:
setDevelopmentMode in interface Shell
Parameters:
developmentMode - true if development mode should be enabled, false otherwise

isDevelopmentMode

public boolean isDevelopmentMode()
Specified by:
isDevelopmentMode in interface Shell

logCommandToOutput

protected void logCommandToOutput(String processedLine)
Description copied from class: AbstractShell
Allows a subclass to actually write the resulting logged command to some form of output. This frees subclasses from needing to implement the logic within AbstractShell.logCommandIfRequired(String, boolean).

Implementations should invoke AbstractShell.getExitShellRequest() to monitor any attempts to exit the shell and release resources such as output log files.

Overrides:
logCommandToOutput in class AbstractShell
Parameters:
processedLine - the line that should be appended to some type of output (excluding the \n character)

getHomeAsString

protected String getHomeAsString()
Obtains the "roo.home" from the system property, falling back to the current working directory if missing.

Specified by:
getHomeAsString in class AbstractShell
Returns:
the 'roo.home' system property

closeShell

protected void closeShell()
Should be called by a subclass before deactivating the shell.


getHistoryFileName

protected abstract String getHistoryFileName()
get history file name from provider. The provider has highest order org.springframework.core.Ordered.getOder will win.

Returns:
history file name

getPromptText

protected abstract String getPromptText()
get prompt text from provider. The provider has highest order org.springframework.core.Ordered.getOder will win.

Returns:
prompt text

getProductName

protected abstract String getProductName()
get product name

Returns:
Product Name

getVersion

protected String getVersion()
get version information

Returns:
Version

getHistorySize

public int getHistorySize()
Returns:
the historySize

setHistorySize

public void setHistorySize(int historySize)
Parameters:
historySize - the historySize to set