Forge - Shell API 1.2.0.Final

org.jboss.forge.shell
Interface Shell

All Superinterfaces:
ShellHistory, ShellPrintWriter, ShellPrompt

public interface Shell
extends ShellPrintWriter, ShellPrompt, ShellHistory

Author:
Lincoln Baxter, III, Mike Brock

Method Summary
 void bufferingMode()
          Place the shell output into buffering mode.
 void clear()
          Clear the console.
 void clearLine()
          Clear the current line of any text.
 void cursorLeft(int x)
          Move the cursor x the specified number of positions.
 void directWriteMode()
          Place the shell output in direct-write mode.
 void execute(File file)
          Execute a shell script from the specified file.
 void execute(File file, String... args)
          Execute a shell script from the specified file, passing the given arguments as input.
 void execute(String command)
          Execute a shell command.
 int getAbsoluteHeight()
          Return the absolute height of the console.
 BufferManager getBufferManager()
          Get buffer manager based on typed
 DirectoryResource getConfigDir()
          Return the file-system directory currently in use as the configuration directory.
 DirectoryResource getCurrentDirectory()
          Return the current working directory resource of the shell.
 Project getCurrentProject()
          Return the Project on which this shell instance is currently operating.
 Resource<?> getCurrentResource()
          Return the current working Resource of the shell.
 Class<? extends Resource<?>> getCurrentResourceScope()
          Return the type of the Resource on which the Shell is currently operating.
 ForgeEnvironment getEnvironment()
          Get the current Forge environment.
 int getHeight()
          Return the current height, in characters, of the current shell console.
 String getPrompt()
          Return the current shell prompt;
 int getWidth()
          Return the current width, in characters, of the current shell console.
 boolean isAcceptDefaults()
          Return true if this Shell is currently set to accept prompt defaults automatically.
 boolean isAnsiSupported()
          Returns whether or not this shell supports ANSI escape codes.
 boolean isExceptionHandlingEnabled()
          Return true if this shell is currently set to handle exceptions.
 boolean isExecuting()
          Return true if the Shell is currently executing a plugin; otherwise, return false.
 boolean isHistoryEnabled()
          Return true if this shell is currently keeping a record of command history.
 boolean isPretend()
          Return true if this shell is currently running in pretend mode.
 boolean isVerbose()
          Return true if this shell is currently running in verbose mode.
 void printlnVerbose(ShellColor color, String output)
          Write color output to the console, only if isVerbose() == true.
 void printlnVerbose(String output)
          Write output to the console, only if isVerbose() == true.
 String readLine()
          Ask the current InputStream for data.
 String readLine(Character mask)
          Ask the current InputStream for input, masking keystrokes in the console with the given mask.
 void registerBufferManager(BufferManager manager)
          Register the buffer manager for the shell system
 void registerKeyListener(KeyListener keyListener)
          Register a KeyListener object that will defined behavior when a given key is received from the Shell
 int scan()
          Wait for input.
 void setAcceptDefaults(boolean accept)
          Set this Shell to accept prompt defaults automatically.
 void setAnsiSupported(boolean value)
          Controls the shell's usage of ANSI escape code support.
 void setCurrentResource(Resource<?> resource)
          Set the Resource on which the shell should operate.
 void setDefaultPrompt()
          Reset the shell prompt to default.
 void setExceptionHandlingEnabled(boolean enabled)
          Toggle exception handling.
 void setHistoryEnabled(boolean history)
          Toggle whether or not this shell should keep a record of command history.
 void setInputStream(InputStream inputStream)
          Set the stream from which the shell should read input.
 void setOutputStream(OutputStream stream)
          Set the stream to which the shell should print output.
 void setPrompt(String string)
          Set the current shell prompt, followed by '> '.
 void setVerbose(boolean verbose)
          Toggle verbose mode.
 
Methods inherited from interface org.jboss.forge.shell.ShellPrintWriter
flush, print, print, println, println, println, renderColor, write, write, write, write
 
Methods inherited from interface org.jboss.forge.shell.ShellPrompt
prompt, prompt, prompt, prompt, prompt, promptAndSwallowCR, promptBoolean, promptBoolean, promptChoice, promptChoice, promptChoice, promptChoiceTyped, promptChoiceTyped, promptCommon, promptCommon, promptCompleter, promptEnum, promptEnum, promptFile, promptFile, promptRegex, promptRegex, promptSecret, promptSecret
 
Methods inherited from interface org.jboss.forge.shell.ShellHistory
setHistory, setHistoryOutputStream, writeToHistory
 

Method Detail

getCurrentDirectory

DirectoryResource getCurrentDirectory()
Return the current working directory resource of the shell. Start with getCurrentResource() and move up the hierarchy until a DirectoryResource is found. (This value may change through execution of plug-ins or other operations.)


getCurrentResource

Resource<?> getCurrentResource()
Return the current working Resource of the shell. (This value may change through execution of plug-ins or other operations.) TODO implement ResourceBag for multiple resources


getCurrentResourceScope

Class<? extends Resource<?>> getCurrentResourceScope()
Return the type of the Resource on which the Shell is currently operating.

See Also:
RequiresResource}

setCurrentResource

void setCurrentResource(Resource<?> resource)
Set the Resource on which the shell should operate.

Note: This may change the current getCurrentDirectory()


getConfigDir

DirectoryResource getConfigDir()
Return the file-system directory currently in use as the configuration directory. (Usually "~/.forge/")


getCurrentProject

Project getCurrentProject()
Return the Project on which this shell instance is currently operating.


isExceptionHandlingEnabled

boolean isExceptionHandlingEnabled()
Return true if this shell is currently set to handle exceptions. If exception handling is enabled, this shell will capture all exceptions thrown during command execution; if disabled, exceptions will not be caught, and must be caught outside of the shell to avoid termination.


setExceptionHandlingEnabled

void setExceptionHandlingEnabled(boolean enabled)
Toggle exception handling.

See Also:
#isExceptionHandlingEnabled()}

isAcceptDefaults

boolean isAcceptDefaults()
Return true if this Shell is currently set to accept prompt defaults automatically.


setAcceptDefaults

void setAcceptDefaults(boolean accept)
Set this Shell to accept prompt defaults automatically.


isPretend

boolean isPretend()
Return true if this shell is currently running in pretend mode.

Modifications to files made while running in pretend mode are made in a temporary directory, and the output is produced as a Diff that can then be applied to the project.


isVerbose

boolean isVerbose()
Return true if this shell is currently running in verbose mode.


setVerbose

void setVerbose(boolean verbose)
Toggle verbose mode.


isHistoryEnabled

boolean isHistoryEnabled()
Return true if this shell is currently keeping a record of command history.


setHistoryEnabled

void setHistoryEnabled(boolean history)
Toggle whether or not this shell should keep a record of command history.


printlnVerbose

void printlnVerbose(String output)
Write output to the console, only if isVerbose() == true.


printlnVerbose

void printlnVerbose(ShellColor color,
                    String output)
Write color output to the console, only if isVerbose() == true.


clear

void clear()
Clear the console.


execute

void execute(String command)
             throws Exception
Execute a shell command.

Throws:
Throwable - if an exception is encountered an isExceptionHandlingEnabled() is not enabled.
Exception

execute

void execute(File file)
             throws IOException,
                    Exception
Execute a shell script from the specified file.

Throws:
IOException
Exception
See Also:
#execute(String)}

execute

void execute(File file,
             String... args)
             throws IOException,
                    Exception
Execute a shell script from the specified file, passing the given arguments as input.

Throws:
IOException
Exception
See Also:
#execute(File)}

isExecuting

boolean isExecuting()
Return true if the Shell is currently executing a plugin; otherwise, return false.


scan

int scan()
Wait for input. Return as soon as any key is pressed and return the scancode.


clearLine

void clearLine()
Clear the current line of any text.


cursorLeft

void cursorLeft(int x)
Move the cursor x the specified number of positions.


setDefaultPrompt

void setDefaultPrompt()
Reset the shell prompt to default.


setPrompt

void setPrompt(String string)
Set the current shell prompt, followed by '> '.


getPrompt

String getPrompt()
Return the current shell prompt;


setInputStream

void setInputStream(InputStream inputStream)
                    throws IOException
Set the stream from which the shell should read input.

Throws:
IOException

setOutputStream

void setOutputStream(OutputStream stream)
                     throws IOException
Set the stream to which the shell should print output.

Throws:
IOException

getHeight

int getHeight()
Return the current height, in characters, of the current shell console. (Warning: This may change in the time between when the method is called and when the result is used. Be sure to call the method as close to its actual use as possible.)


getAbsoluteHeight

int getAbsoluteHeight()
Return the absolute height of the console. This may be different than getHeight() depending on how many lines are available in a display buffer.

Returns:

getWidth

int getWidth()
Return the current width, in characters, of the current shell console. (Warning: This may change in the time between when the method is called and when the result is used. Be sure to call the method as close to its actual use as possible.)


readLine

String readLine()
                throws IOException
Ask the current InputStream for data.

Returns:
any read data as a string, or null if none available.
Throws:
IOException - on error

readLine

String readLine(Character mask)
                throws IOException
Ask the current InputStream for input, masking keystrokes in the console with the given mask.

Parameters:
mask - The character to use for masking input
Returns:
any read data as a string, or null if none available.
Throws:
IOException - on error

setAnsiSupported

void setAnsiSupported(boolean value)
Controls the shell's usage of ANSI escape code support. This method does not guarantee ANSI will function properly, as the underlying Terminal must also support it.


isAnsiSupported

boolean isAnsiSupported()
Returns whether or not this shell supports ANSI escape codes.


registerBufferManager

void registerBufferManager(BufferManager manager)
Register the buffer manager for the shell system

Parameters:
manager -

getBufferManager

BufferManager getBufferManager()
Get buffer manager based on typed

Returns:

registerKeyListener

void registerKeyListener(KeyListener keyListener)
Register a KeyListener object that will defined behavior when a given key is received from the Shell


bufferingMode

void bufferingMode()
Place the shell output into buffering mode. Do not automatically render changes to the screen unless changed back to directWriteMode() or by calling ShellPrintWriter.flush()


directWriteMode

void directWriteMode()
Place the shell output in direct-write mode. All data printed to buffer will be immediately rendered.


getEnvironment

ForgeEnvironment getEnvironment()
Get the current Forge environment.


Forge - Shell API 1.2.0.Final

Copyright © 2013 JBoss by Red Hat. All Rights Reserved.