Class WanakuPrinter
- All Implemented Interfaces:
org.jline.console.CommandRegistry,org.jline.console.Printer
This class extends JLine's DefaultPrinter to provide a rich set of printing methods
with consistent styling and formatting for terminal output. It supports various output formats
including styled messages, tables, and object representations.
Key features include:
- Styled message printing (error, warning, info, success)
- Table printing with customizable options and column selection
- Object-to-map conversion and printing
- Exception highlighting with configurable display modes
- Terminal color and ANSI support
Example usage:
WanakuPrinter printer = new WanakuPrinter(configPath, terminal);
printer.printSuccessMessage("Operation completed successfully");
printer.printTable(dataList, "name", "status", "timestamp");
printer.printAsMap(configuration, "host", "port", "enabled");
- Since:
- 1.0
- Version:
- 1.0
- Author:
- Wanaku CLI Team
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.jline.console.CommandRegistry
org.jline.console.CommandRegistry.CommandSessionNested classes/interfaces inherited from interface org.jline.console.Printer
org.jline.console.Printer.TableRows -
Field Summary
Fields inherited from class org.jline.console.impl.DefaultPrinter
PRNT_INDENTION, PRNT_MAX_DEPTH, PRNT_MAX_ROWS, VAR_PRNT_OPTIONSFields inherited from interface org.jline.console.Printer
ALL, BOOLEAN_KEYS, BORDER, COLUMNS, COLUMNS_IN, COLUMNS_OUT, EXCLUDE, HIGHLIGHT_VALUE, INCLUDE, INDENTION, MAP_SIMILARITY, MAX_COLUMN_WIDTH, MAX_DEPTH, MAXROWS, MULTI_COLUMNS, OBJECT_TO_MAP, OBJECT_TO_STRING, ONE_ROW_TABLE, ROW_HIGHLIGHT, ROWNUM, SHORT_NAMES, SKIP_DEFAULT_OPTIONS, STRUCT_ON_TABLE, STYLE, TO_STRING, VALUE_STYLE, VALUE_STYLE_ALL, WIDTH -
Constructor Summary
ConstructorsConstructorDescriptionWanakuPrinter(org.jline.builtins.ConfigurationPath configPath, org.jline.terminal.Terminal terminal) Constructs a new WanakuPrinter with the specified configuration and terminal. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidhighlightAndPrint(Map<String, Object> options, Throwable exception) Highlights and prints exception information based on configured display mode.<T> voidprintAsMap(T object) Prints an object as a map with all available properties.<T> voidprintAsMap(T object, String... keys) Prints an object as a map with only specified keys.voidprintErrorMessage(String message) Prints an error message with red styling.voidprintInfoMessage(String message) Prints an informational message with blue styling.voidprintSuccessMessage(String message) Prints a success message with green styling.<T> voidprintTable(List<T> printables) Prints a list of objects as a table with all available columns.<T> voidprintTable(List<T> printables, String... columns) Prints a list of objects as a table with specified columns.<T> voidPrints a list of objects as a table with custom formatting options and specified columns.<T> voidprintTable(Map<String, Object> options, List<T> objectsToPrint, Function<T, Map<String, Object>> toMap, String... columns) Prints a list of objects as a table with full customization options.voidprintWarningMessage(String message) Prints a warning message with yellow styling.protected org.jline.terminal.Terminalterminal()Returns the terminal instance used by this printer.static org.jline.terminal.TerminalCreates a new terminal instance with system integration, Jansi support, and color support enabled.Methods inherited from class org.jline.console.impl.DefaultPrinter
appendUsage, compileOptions, defaultPrntOptions, manageBooleanOptions, println, println, prntCommand, refresh, setHighlightValue, setObjectToMap, setObjectToStringMethods inherited from class org.jline.console.impl.JlineCommandRegistry
commandDescription, commandInfo, commandOptions, compileCommandDescription, compileCommandInfo, compileCommandOptions, defaultCompleter, parseOptionsMethods inherited from class org.jline.console.impl.AbstractCommandRegistry
alias, commandAliases, commandNames, compileCompleters, doHelpDesc, getCommandMethods, hasCommand, invoke, registerCommands, registerCommands, registeredCommand, rename, saveExceptionMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.jline.console.CommandRegistry
name
-
Constructor Details
-
WanakuPrinter
public WanakuPrinter(org.jline.builtins.ConfigurationPath configPath, org.jline.terminal.Terminal terminal) Constructs a new WanakuPrinter with the specified configuration and terminal.- Parameters:
configPath- the configuration path for printer settingsterminal- the terminal instance to use for output operations- Throws:
IllegalArgumentException- if terminal is null
-
-
Method Details
-
terminalInstance
Creates a new terminal instance with system integration, Jansi support, and color support enabled.This factory method provides a pre-configured terminal suitable for CLI applications that require color output and system integration.
- Returns:
- a new terminal instance with standard CLI configuration
- Throws:
IOException- if the terminal cannot be created due to I/O issues
-
terminal
protected org.jline.terminal.Terminal terminal()Returns the terminal instance used by this printer.- Overrides:
terminalin classorg.jline.console.impl.DefaultPrinter- Returns:
- the terminal instance for output operations
-
printTable
Prints a list of objects as a table with all available columns.This is a convenience method that displays all properties of the objects in the list as table columns using default table formatting options.
- Type Parameters:
T- the type of objects in the list- Parameters:
printables- the list of objects to display as a table
-
printTable
Prints a list of objects as a table with specified columns.Displays only the specified columns from the objects in the list. Uses default table formatting options.
- Type Parameters:
T- the type of objects in the list- Parameters:
printables- the list of objects to display as a tablecolumns- the column names to include in the table output
-
printTable
Prints a list of objects as a table with custom formatting options and specified columns.Provides full control over table appearance through custom options while using the default object-to-map conversion strategy.
- Type Parameters:
T- the type of objects in the list- Parameters:
options- custom formatting options for table displayprintables- the list of objects to display as a tablecolumns- the column names to include in the table output
-
printTable
public <T> void printTable(Map<String, Object> options, List<T> objectsToPrint, Function<T, Map<String, Object>> toMap, String... columns) Prints a list of objects as a table with full customization options.This is the most flexible table printing method, allowing custom formatting options, custom object-to-map conversion logic, and column selection. Handles empty or null input gracefully and provides error handling for conversion failures.
- Type Parameters:
T- the type of objects in the list- Parameters:
options- custom formatting options for table displayobjectsToPrint- the list of objects to display as a tabletoMap- function to convert objects to map representationcolumns- the column names to include in the table output
-
printAsMap
public <T> void printAsMap(T object) Prints an object as a map with all available properties.Converts the object to a map representation and displays all key-value pairs using default map formatting options.
- Type Parameters:
T- the type of the object to print- Parameters:
object- the object to display as a map
-
printAsMap
Prints an object as a map with only specified keys.Converts the object to a map representation and displays only the key-value pairs for the specified keys. Keys not present in the object are silently ignored.
- Type Parameters:
T- the type of the object to print- Parameters:
object- the object to display as a mapkeys- the specific keys to include in the output
-
printErrorMessage
Prints an error message with red styling.Uses bold red text to display error messages. Null messages are silently ignored.
- Parameters:
message- the error message to display, null values are ignored
-
printWarningMessage
Prints a warning message with yellow styling.Uses yellow text to display warning messages. Null messages are silently ignored.
- Parameters:
message- the warning message to display, null values are ignored
-
printInfoMessage
Prints an informational message with blue styling.Uses blue text to display informational messages. Null messages are silently ignored.
- Parameters:
message- the informational message to display, null values are ignored
-
printSuccessMessage
Prints a success message with green styling.Uses bold green text to display success messages. Null messages are silently ignored.
- Parameters:
message- the success message to display, null values are ignored
-
highlightAndPrint
Highlights and prints exception information based on configured display mode.Supports two display modes:
- stack (default): Prints full stack trace to stderr
- message: Prints only the exception message with emphasis styling
The display mode is controlled by the "exception" option in the provided options map.
- Overrides:
highlightAndPrintin classorg.jline.console.impl.DefaultPrinter- Parameters:
options- configuration options including exception display modeexception- the exception to display, null exceptions are silently ignored
-