Class WanakuPrinter

java.lang.Object
org.jline.console.impl.AbstractCommandRegistry
org.jline.console.impl.JlineCommandRegistry
org.jline.console.impl.DefaultPrinter
ai.wanaku.cli.main.support.WanakuPrinter
All Implemented Interfaces:
org.jline.console.CommandRegistry, org.jline.console.Printer

public class WanakuPrinter extends org.jline.console.impl.DefaultPrinter
Enhanced printer utility for the Wanaku CLI application that provides formatted output capabilities.

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:
  • DefaultPrinter
  • Terminal
  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.jline.console.CommandRegistry

    org.jline.console.CommandRegistry.CommandSession

    Nested 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_OPTIONS

    Fields 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

    Constructors
    Constructor
    Description
    WanakuPrinter(org.jline.builtins.ConfigurationPath configPath, org.jline.terminal.Terminal terminal)
    Constructs a new WanakuPrinter with the specified configuration and terminal.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    Highlights and prints exception information based on configured display mode.
    <T> void
    printAsMap(T object)
    Prints an object as a map with all available properties.
    <T> void
    printAsMap(T object, String... keys)
    Prints an object as a map with only specified keys.
    void
    Prints an error message with red styling.
    void
    Prints an informational message with blue styling.
    void
    Prints a success message with green styling.
    <T> void
    printTable(List<T> printables)
    Prints a list of objects as a table with all available columns.
    <T> void
    printTable(List<T> printables, String... columns)
    Prints a list of objects as a table with specified columns.
    <T> void
    printTable(Map<String,Object> options, List<T> printables, String... columns)
    Prints a list of objects as a table with custom formatting options and specified columns.
    <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.
    void
    Prints a warning message with yellow styling.
    protected org.jline.terminal.Terminal
    Returns the terminal instance used by this printer.
    static org.jline.terminal.Terminal
    Creates 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, setObjectToString

    Methods inherited from class org.jline.console.impl.JlineCommandRegistry

    commandDescription, commandInfo, commandOptions, compileCommandDescription, compileCommandInfo, compileCommandOptions, defaultCompleter, parseOptions

    Methods inherited from class org.jline.console.impl.AbstractCommandRegistry

    alias, commandAliases, commandNames, compileCompleters, doHelpDesc, getCommandMethods, hasCommand, invoke, registerCommands, registerCommands, registeredCommand, rename, saveException

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods 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 settings
      terminal - the terminal instance to use for output operations
      Throws:
      IllegalArgumentException - if terminal is null
  • Method Details

    • terminalInstance

      public static org.jline.terminal.Terminal terminalInstance() throws IOException
      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:
      terminal in class org.jline.console.impl.DefaultPrinter
      Returns:
      the terminal instance for output operations
    • printTable

      public <T> void printTable(List<T> printables)
      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

      public <T> void printTable(List<T> printables, String... columns)
      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 table
      columns - the column names to include in the table output
    • printTable

      public <T> void printTable(Map<String,Object> options, List<T> printables, String... columns)
      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 display
      printables - the list of objects to display as a table
      columns - 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 display
      objectsToPrint - the list of objects to display as a table
      toMap - function to convert objects to map representation
      columns - 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

      public <T> void printAsMap(T object, String... keys)
      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 map
      keys - the specific keys to include in the output
    • printErrorMessage

      public void printErrorMessage(String message)
      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

      public void printWarningMessage(String message)
      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

      public void printInfoMessage(String message)
      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

      public void printSuccessMessage(String message)
      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

      protected void highlightAndPrint(Map<String,Object> options, Throwable exception)
      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:
      highlightAndPrint in class org.jline.console.impl.DefaultPrinter
      Parameters:
      options - configuration options including exception display mode
      exception - the exception to display, null exceptions are silently ignored