public class GrailsConsole extends Object implements ConsoleLogger
Utility class for delivering console output in a nicely formatted way.
Modifiers | Name | Description |
---|---|---|
static String |
CATEGORY_SEPARATOR |
|
static String |
ENABLE_INTERACTIVE |
|
static String |
ENABLE_TERMINAL |
|
static String |
ERROR |
|
static String |
HISTORYFILE |
|
static String |
LINE_SEPARATOR |
|
static String |
PROMPT |
|
static Character |
SECURE_MASK_CHAR |
|
static String |
SPACE |
|
static String |
STACKTRACE_FILTERED_MESSAGE |
|
static String |
STACKTRACE_MESSAGE |
|
static String |
WARNING |
Constructor and description |
---|
protected GrailsConsole() |
Type Params | Return Type | Name and description |
---|---|---|
|
public void |
addShutdownHook() |
|
public void |
addStatus(String msg) Keeps doesn't replace the status message |
|
public void |
addStatus(String category, String msg) Keeps doesn't replace the status message |
|
public void |
addStatus(String category, String msg, String color) Keeps doesn't replace the status message |
|
protected OutputStream |
ansiWrap(OutputStream out) Hook method that allows controlling whether or not output streams should be wrapped by AnsiConsole.wrapOutputStream. |
|
public void |
append(String msg) |
|
public void |
beforeShutdown() |
|
protected void |
bindSystemOutAndErr(PrintStream systemOut, PrintStream systemErr) |
|
public void |
cleanlyExit(int status) |
|
protected jline.console.ConsoleReader |
createConsoleReader(InputStream systemIn) |
|
public static GrailsConsole |
createInstance() |
|
protected jline.Terminal |
createTerminal() Creates the instance of Terminal used directly in GrailsConsole. |
|
public void |
echoStatus() Replays the last status message |
|
public void |
error(String msg) Prints an error message |
|
public void |
error(String msg, Throwable error) Use to log an error |
|
public void |
error(Throwable error) Use to log an error |
|
public void |
error(String label, String message) |
|
public void |
flush() Makes sure that the console has been reset to the default state and that the out stream has been flushed. |
|
public Stack<String> |
getCategory() |
|
public Character |
getDefaultInputMask() |
|
public PrintStream |
getErr() |
|
public InputStream |
getInput()
|
|
public static GrailsConsole |
getInstance() |
|
public String |
getLastMessage()
|
|
public PrintStream |
getOut() |
|
public jline.console.ConsoleReader |
getReader() |
|
public jline.Terminal |
getTerminal() |
|
public void |
indicateProgress() Indicates progress with the default progress indicator |
|
public void |
indicateProgress(int number, int total) Indicate progress for a number and total |
|
public void |
indicateProgress(int number) Indicates progress by number |
|
public void |
indicateProgressPercentage(long number, long total) Indicates progress as a percentage for the given number and total |
|
public void |
info(String msg) Synonym for #log |
|
protected void |
initialize(InputStream systemIn, PrintStream systemOut, PrintStream systemErr) |
|
public boolean |
isAnsiEnabled() |
|
public boolean |
isInteractiveEnabled() |
|
public boolean |
isStacktrace()
|
|
public boolean |
isVerbose()
|
|
public boolean |
isWindows() |
|
public void |
log(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) |
|
public void |
reinitialize(InputStream systemIn, PrintStream systemOut, PrintStream systemErr) Use in testing when System.out, System.err or System.in change |
|
public static void |
removeInstance() |
|
public void |
removeShutdownHook() |
|
public void |
resetCompleters() |
|
public void |
restoreOriginalSystemOutAndErr() |
|
protected void |
restoreTerminal() |
|
public String |
secureUserInput(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.). |
|
public void |
setAnsiEnabled(boolean ansiEnabled) |
|
public void |
setDefaultInputMask(Character defaultInputMask) |
|
public void |
setErr(PrintStream err) |
|
public static void |
setInstance(GrailsConsole newConsole) |
|
public void |
setLastMessage(String lastMessage) |
|
public void |
setOut(PrintStream out) |
|
public void |
setStacktrace(boolean stacktrace)
|
|
public void |
setVerbose(boolean verbose)
|
|
public String |
showPrompt() Shows the prompt to request user input |
|
public String |
toString() |
|
public void |
updateStatus(String msg) Updates the current state message |
|
public String |
userInput(String msg) Replacement for AntBuilder.input() to eliminate dependency of GrailsScriptRunner on the Ant libraries. |
|
public String |
userInput(String message, List<String> validResponses) |
|
public String |
userInput(String message, String[] validResponses) Replacement for AntBuilder.input() to eliminate dependency of GrailsScriptRunner on the Ant libraries. |
|
public void |
verbose(String msg) |
|
public void |
warn(String msg) Prints a warn message |
|
public void |
warning(String msg) Prints an error message |
Keeps doesn't replace the status message
msg
- The messageKeeps doesn't replace the status message
category
- The categorymsg
- The messageKeeps doesn't replace the status message
category
- The categorymsg
- The messagecolor
- The colorHook 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
Use to log an error
msg
- The messageerror
- 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 total
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.