public class MicronautConsole extends Object implements ConsoleLogger
Modifier and Type | Field and 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 |
Modifier | Constructor and Description |
---|---|
protected |
MicronautConsole()
Default constructor for the Micronaut console.
|
Modifier and Type | Method and Description |
---|---|
void |
addShutdownHook()
Add a shutdown hook.
|
void |
addStatus(String msg)
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.
|
void |
append(String msg)
Append a message.
|
void |
beforeShutdown()
Execute before shutdown the console.
|
protected void |
bindSystemOutAndErr(PrintStream systemOut,
PrintStream systemErr) |
void |
cleanlyExit(int status)
Flush before exit.
|
protected jline.console.ConsoleReader |
createConsoleReader(InputStream systemIn)
Create a console reader.
|
static MicronautConsole |
createInstance()
Create a new Micronaut console instance.
|
protected jline.Terminal |
createTerminal()
Creates the instance of Terminal used directly in MicronautConsole.
|
void |
echoStatus()
Replays the last status message.
|
void |
error(String msg)
Prints an error message.
|
void |
error(String label,
String message)
Log an error with a specific error label.
|
void |
error(String msg,
Throwable error)
Use to log an error.
|
void |
error(Throwable error)
Use to log an error.
|
void |
flush()
Makes sure that the console has been reset to the default state and that the out stream has been flushed.
|
Stack<String> |
getCategory() |
Character |
getDefaultInputMask() |
PrintStream |
getErr() |
InputStream |
getInput() |
static MicronautConsole |
getInstance() |
String |
getLastMessage() |
PrintStream |
getOut() |
jline.console.ConsoleReader |
getReader() |
jline.Terminal |
getTerminal() |
void |
indicateProgress()
Indicates progress with the default progress indicator.
|
void |
indicateProgress(int number)
Indicates progress by number.
|
void |
indicateProgress(int number,
int total)
Indicate progress for a number and total.
|
void |
indicateProgressPercentage(long number,
long total)
Indicates progress as a percentage for the given number and total.
|
void |
info(String msg)
Synonym for #log.
|
protected void |
initialize(InputStream systemIn,
PrintStream systemOut,
PrintStream systemErr) |
boolean |
isAnsiEnabled() |
boolean |
isInteractiveEnabled() |
boolean |
isStacktrace() |
boolean |
isVerbose() |
boolean |
isWindows() |
void |
log(String msg)
Logs a message below the current status message.
|
protected void |
persistHistory()
Persist the history.
|
protected jline.console.history.History |
prepareHistory()
Prepares a history file to be used by the ConsoleReader.
|
protected void |
redirectSystemOutAndErr(boolean force)
Redirect system out and error to the console.
|
void |
reinitialize(InputStream systemIn,
PrintStream systemOut,
PrintStream systemErr)
Use in testing when System.out, System.err or System.in change.
|
static void |
removeInstance()
Remove the Micronaut console.
|
void |
removeShutdownHook()
Remove a shutdown hook.
|
void |
resetCompleters()
Reset the completers.
|
void |
restoreOriginalSystemOutAndErr()
Restore the original system output and error.
|
protected void |
restoreTerminal()
Restore the terminal.
|
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. |
void |
setAnsiEnabled(boolean ansiEnabled) |
void |
setDefaultInputMask(Character defaultInputMask)
Set the default input mask.
|
void |
setErr(PrintStream err)
Sets the err stream.
|
static void |
setInstance(MicronautConsole newConsole) |
void |
setLastMessage(String lastMessage)
Sets the last message logged.
|
void |
setOut(PrintStream out)
Sets the out stream.
|
void |
setStacktrace(boolean stacktrace) |
void |
setVerbose(boolean verbose) |
String |
showPrompt()
Shows the prompt to request user input.
|
void |
updateStatus(String msg)
Updates the current state message.
|
String |
userInput(String msg)
Replacement for AntBuilder.input() to eliminate dependency of GrailsScriptRunner on the Ant libraries.
|
String |
userInput(String message,
List<String> validResponses) |
String |
userInput(String message,
String[] validResponses)
Replacement for AntBuilder.input() to eliminate dependency of GrailsScriptRunner on the Ant libraries.
|
void |
verbose(String msg)
Outputs a verbose message.
|
void |
warn(String msg)
Prints a warn message.
|
void |
warning(String msg)
Prints an error message.
|
public static final String ENABLE_TERMINAL
public static final String ENABLE_INTERACTIVE
public static final String LINE_SEPARATOR
public static final String CATEGORY_SEPARATOR
public static final String PROMPT
public static final String SPACE
public static final String ERROR
public static final String WARNING
public static final String HISTORYFILE
public static final String STACKTRACE_FILTERED_MESSAGE
public static final String STACKTRACE_MESSAGE
public static final Character SECURE_MASK_CHAR
protected MicronautConsole() throws IOException
IOException
- if there is an errorpublic void addShutdownHook()
public void removeShutdownHook()
public void reinitialize(InputStream systemIn, PrintStream systemOut, PrintStream systemErr) throws IOException
systemIn
- The system insystemOut
- The system outsystemErr
- The system errIOException
- if there is an errorprotected void initialize(InputStream systemIn, PrintStream systemOut, PrintStream systemErr) throws IOException
systemIn
- The system insystemOut
- The system outsystemErr
- The system errIOException
- if there is an errorprotected void bindSystemOutAndErr(PrintStream systemOut, PrintStream systemErr)
systemOut
- The system outsystemErr
- The system errorpublic PrintStream getErr()
public void setErr(PrintStream err)
err
- The err print streampublic void setOut(PrintStream out)
out
- The out print streampublic boolean isInteractiveEnabled()
protected jline.console.ConsoleReader createConsoleReader(InputStream systemIn) throws IOException
systemIn
- The input streamIOException
- if there is an errorprotected jline.Terminal createTerminal()
Terminal
public void resetCompleters()
protected jline.console.history.History prepareHistory() throws IOException
History
IOException
- if there is an errorprotected OutputStream ansiWrap(OutputStream out)
out
- The output streamAnsiConsole
public boolean isWindows()
public static MicronautConsole getInstance()
public static void removeInstance()
public void beforeShutdown()
protected void restoreTerminal()
protected void persistHistory()
public static void setInstance(MicronautConsole newConsole)
newConsole
- The new Micronaut consoleprotected void redirectSystemOutAndErr(boolean force)
force
- Whether to force the redirectpublic static MicronautConsole createInstance() throws IOException
IOException
- if there is an errorpublic void setAnsiEnabled(boolean ansiEnabled)
ansiEnabled
- Whether to enable ansi supportpublic void setVerbose(boolean verbose)
verbose
- Sets whether verbose output should be usedpublic void setStacktrace(boolean stacktrace)
stacktrace
- Sets whether to show stack traces on errorspublic boolean isVerbose()
public boolean isStacktrace()
public InputStream getInput()
public String getLastMessage()
public void setLastMessage(String lastMessage)
lastMessage
- The last message loggedpublic jline.console.ConsoleReader getReader()
public jline.Terminal getTerminal()
public PrintStream getOut()
public void indicateProgress()
indicateProgress
in interface ConsoleLogger
public void indicateProgress(int number, int total)
indicateProgress
in interface ConsoleLogger
number
- The current numbertotal
- The total numberpublic void indicateProgressPercentage(long number, long total)
indicateProgressPercentage
in interface ConsoleLogger
number
- The numbertotal
- The totalpublic void indicateProgress(int number)
indicateProgress
in interface ConsoleLogger
number
- The numberpublic void updateStatus(String msg)
updateStatus
in interface ConsoleLogger
msg
- The messagepublic void addStatus(String msg)
addStatus
in interface ConsoleLogger
msg
- The messagepublic void error(String msg)
error
in interface ConsoleLogger
msg
- The error messagepublic void warning(String msg)
warning
in interface ConsoleLogger
msg
- The error messagepublic void warn(String msg)
warn
in interface ConsoleLogger
msg
- The messagepublic boolean isAnsiEnabled()
public void error(String msg, Throwable error)
error
in interface ConsoleLogger
msg
- The messageerror
- The errorpublic void error(Throwable error)
error
in interface ConsoleLogger
error
- The errorpublic void log(String msg)
log
in interface ConsoleLogger
msg
- The message to logpublic void append(String msg)
msg
- The messagepublic void info(String msg)
info
in interface ConsoleLogger
msg
- The message to logpublic void verbose(String msg)
ConsoleLogger
verbose
in interface ConsoleLogger
msg
- The messagepublic void echoStatus()
public String userInput(String msg)
msg
- The message/question to display.public String secureUserInput(String msg)
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.public String showPrompt()
public String userInput(String message, List<String> validResponses)
message
- The messagevalidResponses
- The valid responsepublic String userInput(String message, String[] validResponses)
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.public void error(String label, String message)
ConsoleLogger
error
in interface ConsoleLogger
label
- The labelmessage
- The messagepublic void restoreOriginalSystemOutAndErr()
public void cleanlyExit(int status)
status
- The exit statuspublic void flush()
public Character getDefaultInputMask()
public void setDefaultInputMask(Character defaultInputMask)
defaultInputMask
- The default input mask