public class GrailsConsole extends java.lang.Object
Utility class for delivering console output in a nicely formatted way.
Modifiers | Name | Description |
---|---|---|
static java.lang.String |
CATEGORY_SEPARATOR |
|
static java.lang.String |
ENABLE_INTERACTIVE |
|
static java.lang.String |
ENABLE_TERMINAL |
|
static java.lang.String |
ERROR |
|
static java.lang.String |
HISTORYFILE |
|
static java.lang.String |
LINE_SEPARATOR |
|
static java.lang.String |
PROMPT |
|
static java.lang.Character |
SECURE_MASK_CHAR |
|
static java.lang.String |
SPACE |
|
static java.lang.String |
STACKTRACE_FILTERED_MESSAGE |
|
static java.lang.String |
STACKTRACE_MESSAGE |
|
static java.lang.String |
WARNING |
Type | Name and description |
---|---|
boolean |
ansiEnabled |
java.lang.Character |
defaultInputMask |
java.io.PrintStream |
err |
GrailsConsole |
instance |
java.lang.String |
lastMessage |
java.io.PrintStream |
out |
boolean |
stacktrace |
boolean |
verbose |
Constructor and description |
---|
protected GrailsConsole
() |
Type Params | Return Type | Name and description |
---|---|---|
|
void |
addShutdownHook() |
|
void |
addStatus(java.lang.String msg) Keeps doesn't replace the status message |
|
protected java.io.OutputStream |
ansiWrap(java.io.OutputStream out) Hook method that allows controlling whether or not output streams should be wrapped by AnsiConsole.wrapOutputStream. |
|
void |
append(java.lang.String msg) |
|
void |
beforeShutdown() |
|
protected void |
bindSystemOutAndErr(java.io.PrintStream systemOut, java.io.PrintStream systemErr) |
|
void |
cleanlyExit(int status) |
|
protected jline.console.ConsoleReader |
createConsoleReader(java.io.InputStream systemIn) |
|
static GrailsConsole |
createInstance() |
|
protected jline.Terminal |
createTerminal() Creates the instance of Terminal used directly in GrailsConsole. |
|
void |
echoStatus() Replays the last status message |
|
void |
error(java.lang.String msg) Prints an error message |
|
void |
error(java.lang.String msg, java.lang.Throwable error) Use to log an error |
|
void |
error(java.lang.Throwable error) Use to log an error |
|
void |
error(java.lang.String label, java.lang.String message) |
|
void |
flush() Makes sure that the console has been reset to the default state and that the out stream has been flushed. |
|
java.util.Stack<java.lang.String> |
getCategory() |
|
java.lang.Character |
getDefaultInputMask() |
|
java.io.PrintStream |
getErr() |
|
java.io.InputStream |
getInput() @return The input stream being read from |
|
static GrailsConsole |
getInstance() |
|
java.lang.String |
getLastMessage() @return The last message logged |
|
java.io.PrintStream |
getOut() |
|
jline.console.ConsoleReader |
getReader() |
|
jline.Terminal |
getTerminal() |
|
void |
indicateProgress() Indicates progress with the default progress indicator |
|
void |
indicateProgress(int number, int total) Indicate progress for a number and total |
|
void |
indicateProgress(int number) Indicates progress by number |
|
void |
indicateProgressPercentage(long number, long total) Indicates progress as a percentage for the given number and total |
|
void |
info(java.lang.String msg) Synonym for #log |
|
protected void |
initialize(java.io.InputStream systemIn, java.io.PrintStream systemOut, java.io.PrintStream systemErr) |
|
boolean |
isAnsiEnabled() |
|
boolean |
isInteractiveEnabled() |
|
boolean |
isStacktrace() @return Whether to show stack traces |
|
boolean |
isVerbose() @return Whether verbose output is being used |
|
boolean |
isWindows() |
|
void |
log(java.lang.String msg) Logs a message below the current status message |
|
protected void |
persistHistory() |
|
protected jline.console.history.History |
prepareHistory() Prepares a history file to be used by the ConsoleReader. |
|
protected void |
redirectSystemOutAndErr(boolean force) |
|
void |
reinitialize(java.io.InputStream systemIn, java.io.PrintStream systemOut, java.io.PrintStream systemErr) Use in testing when System.out, System.err or System.in change |
|
static void |
removeInstance() |
|
void |
removeShutdownHook() |
|
void |
resetCompleters() |
|
void |
restoreOriginalSystemOutAndErr() |
|
protected void |
restoreTerminal() |
|
java.lang.String |
secureUserInput(java.lang.String msg) Like userInput(String) except that the user's entered characters will be replaced with '*' on the CLI, masking the input (i.e. suitable for capturing passwords etc.). |
|
void |
setAnsiEnabled(boolean ansiEnabled) |
|
void |
setDefaultInputMask(java.lang.Character defaultInputMask) |
|
void |
setErr(java.io.PrintStream err) |
|
static void |
setInstance(GrailsConsole newConsole) |
|
void |
setLastMessage(java.lang.String lastMessage) |
|
void |
setOut(java.io.PrintStream out) |
|
void |
setStacktrace(boolean stacktrace) @param stacktrace Sets whether to show stack traces on errors |
|
void |
setVerbose(boolean verbose) @param verbose Sets whether verbose output should be used |
|
java.lang.String |
showPrompt() Shows the prompt to request user input |
|
void |
updateStatus(java.lang.String msg) Updates the current state message |
|
java.lang.String |
userInput(java.lang.String msg) Replacement for AntBuilder.input() to eliminate dependency of GrailsScriptRunner on the Ant libraries. |
|
java.lang.String |
userInput(java.lang.String message, java.util.List<java.lang.String> validResponses) |
|
java.lang.String |
userInput(java.lang.String message, java.lang.String[] validResponses) Replacement for AntBuilder.input() to eliminate dependency of GrailsScriptRunner on the Ant libraries. |
|
void |
verbose(java.lang.String msg) |
|
void |
warn(java.lang.String msg) Prints a warn message |
|
void |
warning(java.lang.String msg) Prints an error message |
Methods inherited from class | Name |
---|---|
class java.lang.Object |
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
Keeps doesn't replace the status message
msg
- The messageHook method that allows controlling whether or not output streams should be wrapped by AnsiConsole.wrapOutputStream. Unfortunately, Eclipse consoles will look to the AnsiWrap like they do not understand ansi, even if we were to implement support in Eclipse to' handle it and the wrapped stream will not pass the ansi chars on to Eclipse).
Creates the instance of Terminal used directly in GrailsConsole. Note that there is also another terminal instance created implicitly inside of ConsoleReader. That instance is controlled by the jline.terminal system property.
Replays the last status message
Prints an error message
msg
- The error messageUse to log an error
msg
- The messageerror
- The errorUse to log an error
error
- The errorMakes sure that the console has been reset to the default state and that the out stream has been flushed.
Indicates progress with the default progress indicator
Indicate progress for a number and total
number
- The current numbertotal
- The total numberIndicates progress by number
number
- The numberIndicates progress as a percentage for the given number and total
number
- The numbertotal
- The totalSynonym for #log
msg
- The message to log
Logs a message below the current status message
msg
- The message to logPrepares a history file to be used by the ConsoleReader. This file will live in the home directory of the user.
Use in testing when System.out, System.err or System.in change
Like userInput(String) except that the user's entered characters will be replaced with '*' on the CLI, masking the input (i.e. suitable for capturing passwords etc.).
msg
- The message/question to display.
stacktrace
- Sets whether to show stack traces on errors
verbose
- Sets whether verbose output should be usedShows the prompt to request user input
Updates the current state message
msg
- The messageReplacement for AntBuilder.input() to eliminate dependency of GrailsScriptRunner on the Ant libraries. Prints a message and returns whatever the user enters (once they press <return>).
msg
- The message/question to display. Replacement for AntBuilder.input() to eliminate dependency of
GrailsScriptRunner on the Ant libraries. Prints a message and
list of valid responses, then returns whatever the user enters
(once they press <return>). If the user enters something
that is not in the array of valid responses, the message is
displayed again and the method waits for more input. It will
display the message a maximum of three times before it gives up
and returns null
.
message
- The message/question to display.validResponses
- An array of responses that the user is
allowed to enter. Displayed after the message.null
if the user never entered a valid string.Prints a warn message
msg
- The messagePrints an error message
msg
- The error message