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)
- Markdown rendering with terminal styling
- 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.printMarkdown("# Heading\n\nThis is **bold** text.");
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.voidpageMarkdown(String markdown) Displays Markdown text in an interactive pager (similar to Unix 'less').<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.voidprintMarkdown(String markdown) Prints Markdown text with terminal styling and formatting.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 resilient fallback handling.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 resilient fallback handling.This factory method attempts to create a terminal in the following order:
- System terminal with Jansi and color support (best experience)
- System terminal without Jansi if native libraries fail
- Dumb terminal if system terminal is unavailable (fallback)
This approach ensures the CLI works in various environments including: standard terminals, CI/CD pipelines, Docker containers, and IDEs.
- Returns:
- a new terminal instance, guaranteed to be non-null
- Throws:
IOException- if terminal creation fails catastrophically
-
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
-
printMarkdown
Prints Markdown text with terminal styling and formatting.Parses and renders Markdown text with ANSI color codes and text formatting for rich terminal output. Supports headings, bold, italic, code blocks, lists, and links.
Example Markdown features:
- Headings:
# Heading- rendered in bold cyan - Bold:
**text**- rendered in bold - Italic:
*text*- rendered in italic - Code:
`code`- rendered in yellow - Lists:
- item- rendered with bullets - Links:
[text](url)- rendered in blue underlined - Tables: GitHub Flavored Markdown tables with borders
- Parameters:
markdown- the Markdown text to render and display- Throws:
IllegalArgumentException- if markdown is null
- Headings:
-
pageMarkdown
Displays Markdown text in an interactive pager (similar to Unix 'less').This method renders Markdown text with terminal styling and displays it in an interactive pager that allows users to navigate through the content. The pager supports keyboard navigation:
- Space/f: Forward one page
- b: Backward one page
- j/↓: Forward one line
- k/↑: Backward one line
- g/Home: Go to first line
- G/End: Go to last line
- /pattern: Search forward for pattern
- ?pattern: Search backward for pattern
- n: Repeat previous search
- N: Repeat previous search in reverse direction
- q: Quit the pager
- h: Display help
This is useful for displaying long documentation or help text that doesn't fit on one screen.
- Parameters:
markdown- the Markdown text to render and display in the pager- Throws:
IllegalArgumentException- if markdown is nullIOException- if there's an error displaying the pagerInterruptedException- if the pager is interrupted
-
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
-