Class PrettyPrinter

java.lang.Object
org.spongepowered.asm.util.PrettyPrinter

public class PrettyPrinter extends Object
Prints information in a pretty box
  • Field Details

    • width

      protected int width
      Box with (adapts to contents)
    • wrapWidth

      protected int wrapWidth
      Wrap width used when an explicit wrap width is not specified
    • kvKeyWidth

      protected int kvKeyWidth
      Key/value key width
    • kvFormat

      protected String kvFormat
  • Constructor Details

    • PrettyPrinter

      public PrettyPrinter()
    • PrettyPrinter

      public PrettyPrinter(int width)
  • Method Details

    • wrapTo

      public PrettyPrinter wrapTo(int wrapWidth)
      Set the wrap width (default 80 columns)
      Parameters:
      wrapWidth - new width (in characters) to wrap to
      Returns:
      fluent interface
    • wrapTo

      public int wrapTo()
      Get the current wrap width
      Returns:
      the current wrap width
    • table

      public PrettyPrinter table()
      Begin a new table with no header and adaptive column widths
      Returns:
      fluent interface
    • table

      public PrettyPrinter table(String... titles)
      Begin a new table with the specified headers and adaptive column widths
      Parameters:
      titles - Column titles
      Returns:
      fluent interface
    • table

      public PrettyPrinter table(Object... format)
      Begin a new table with the specified format. The format is specified as a sequence of values with Strings defining column titles, Integers defining column widths, and PrettyPrinter.Alignments defining column alignments. Widths and alignment specifiers should follow the relevant column title. Specify a negative value to specify the maximum width for a column (values will be truncated).

      For example, to specify a table with two columns of width 10:

      printer.table("Column 1", 10, "Column 2", 10);

      A table with a column 30 characters wide and a right-aligned column 20 characters wide:

      printer.table("Column 1", 30, "Column 2", 20, Alignment.RIGHT);
      Parameters:
      format - format string, see description
      Returns:
      fluent interface
    • spacing

      public PrettyPrinter spacing(int spacing)
      Set the column spacing for the current table. Default = 2
      Parameters:
      spacing - Column spacing in characters
      Returns:
      fluent interface
    • th

      public PrettyPrinter th()
      Print the current table header. The table header is automatically printed before the first row if not explicitly specified by calling this method.
      Returns:
      fluent interface
    • tr

      public PrettyPrinter tr(Object... args)
      Print a table row with the specified values. If more columns are specified than exist in the table, then the table is automatically expanded.
      Parameters:
      args - column values
      Returns:
      fluent interface
    • add

      public PrettyPrinter add()
      Adds a blank line to the output
      Returns:
      fluent interface
    • add

      public PrettyPrinter add(String string)
      Adds a string line to the output
      Parameters:
      string - format string
      Returns:
      fluent interface
    • add

      public PrettyPrinter add(String format, Object... args)
      Adds a formatted line to the output
      Parameters:
      format - format string
      args - arguments
      Returns:
      fluent interface
    • add

      public PrettyPrinter add(Object[] array)
      Add elements of the array to the output, one per line
      Parameters:
      array - Array of objects to print
      Returns:
      fluent interface
    • add

      public PrettyPrinter add(Object[] array, String format)
      Add elements of the array to the output, one per line
      Parameters:
      array - Array of objects to print
      format - Format for each row
      Returns:
      fluent interface
    • addIndexed

      public PrettyPrinter addIndexed(Object[] array)
      Add elements of the array to the output, one per line, with array indices
      Parameters:
      array - Array of objects to print
      Returns:
      fluent interface
    • addWithIndices

      public PrettyPrinter addWithIndices(Collection<?> c)
      Add elements of the collection to the output, one per line, with indices
      Parameters:
      c - Collection of objects to print
      Returns:
      fluent interface
    • add

      Adds a pretty-printable object to the output, the object is responsible for adding its own representation to this printer
      Parameters:
      printable - object to add
      Returns:
      fluent interface
    • add

      public PrettyPrinter add(Throwable th)
      Print a formatted representation of the specified throwable with the default indent (4)
      Parameters:
      th - Throwable to print
      Returns:
      fluent interface
    • add

      public PrettyPrinter add(Throwable th, int indent)
      Print a formatted representation of the specified throwable with the specified indent
      Parameters:
      th - Throwable to print
      indent - Indent size for stacktrace lines
      Returns:
      fluent interface
    • add

      public PrettyPrinter add(StackTraceElement[] stackTrace, int indent)
      Print a formatted representation of the specified stack trace with the specified indent
      Parameters:
      stackTrace - stack trace to print
      indent - Indent size for stacktrace lines
      Returns:
      fluent interface
    • add

      public PrettyPrinter add(Object object)
      Adds the specified object to the output
      Parameters:
      object - object to add
      Returns:
      fluent interface
    • add

      public PrettyPrinter add(Object object, int indent)
      Adds the specified object to the output
      Parameters:
      object - object to add
      indent - indent amount
      Returns:
      fluent interface
    • addWrapped

      public PrettyPrinter addWrapped(String format, Object... args)
      Adds a formatted line to the output, and attempts to wrap the line content to the current wrap width
      Parameters:
      format - format string
      args - arguments
      Returns:
      fluent interface
    • addWrapped

      public PrettyPrinter addWrapped(int width, String format, Object... args)
      Adds a formatted line to the output, and attempts to wrap the line content to the specified width
      Parameters:
      width - wrap width to use for this content
      format - format string
      args - arguments
      Returns:
      fluent interface
    • kv

      public PrettyPrinter kv(String key, String format, Object... args)
      Add a formatted key/value pair to the output
      Parameters:
      key - Key
      format - Value format
      args - Value args
      Returns:
      fluent interface
    • kv

      public PrettyPrinter kv(String key, Object value)
      Add a key/value pair to the output
      Parameters:
      key - Key
      value - Value
      Returns:
      fluent interface
    • kvWidth

      public PrettyPrinter kvWidth(int width)
      Set the minimum key display width
      Parameters:
      width - width to set
      Returns:
      fluent
    • add

      public PrettyPrinter add(Map<?,?> map)
      Add all values of the specified map to this printer as key/value pairs
      Parameters:
      map - Map with entries to add
      Returns:
      fluent
    • hr

      public PrettyPrinter hr()
      Adds a horizontal rule to the output
      Returns:
      fluent interface
    • hr

      public PrettyPrinter hr(char ruleChar)
      Adds a horizontal rule of the specified char to the output
      Parameters:
      ruleChar - character to use for the horizontal rule
      Returns:
      fluent interface
    • centre

      public PrettyPrinter centre()
      Centre the last line added
      Returns:
      fluent interface
    • trace

      public PrettyPrinter trace()
      Outputs this printer to stderr and to a logger decorated with the calling class name with level Level.DEBUG
      Returns:
      fluent interface
    • trace

      public PrettyPrinter trace(Level level)
      Outputs this printer to stderr and to a logger decorated with the calling class name at the specified level
      Parameters:
      level - Log level to write messages
      Returns:
      fluent interface
    • trace

      public PrettyPrinter trace(String logger)
      Outputs this printer to stderr and to a logger decorated with specified name with level Level.DEBUG
      Parameters:
      logger - Logger name to write to
      Returns:
      fluent interface
    • trace

      public PrettyPrinter trace(String logger, Level level)
      Outputs this printer to stderr and to a logger decorated with specified name with the specified level
      Parameters:
      logger - Logger name to write to
      level - Log level to write messages
      Returns:
      fluent interface
    • trace

      public PrettyPrinter trace(ILogger logger)
      Outputs this printer to stderr and to the supplied logger with level Level.DEBUG
      Parameters:
      logger - Logger to write to
      Returns:
      fluent interface
    • trace

      public PrettyPrinter trace(ILogger logger, Level level)
      Outputs this printer to stderr and to the supplied logger with the specified level
      Parameters:
      logger - Logger to write to
      level - Log level to write messages
      Returns:
      fluent interface
    • trace

      public PrettyPrinter trace(PrintStream stream)
      Outputs this printer to the specified stream and to a logger decorated with the calling class name with level Level.DEBUG
      Parameters:
      stream - Output stream to print to
      Returns:
      fluent interface
    • trace

      public PrettyPrinter trace(PrintStream stream, Level level)
      Outputs this printer to the specified stream and to a logger decorated with the calling class name with the specified level
      Parameters:
      stream - Output stream to print to
      level - Log level to write messages
      Returns:
      fluent interface
    • trace

      public PrettyPrinter trace(PrintStream stream, String logger)
      Outputs this printer to the specified stream and to a logger with the specified name with level Level.DEBUG
      Parameters:
      stream - Output stream to print to
      logger - Logger name to write to
      Returns:
      fluent interface
    • trace

      public PrettyPrinter trace(PrintStream stream, String logger, Level level)
      Outputs this printer to the specified stream and to a logger with the specified name at the specified level
      Parameters:
      stream - Output stream to print to
      logger - Logger name to write to
      level - Log level to write messages
      Returns:
      fluent interface
    • trace

      public PrettyPrinter trace(PrintStream stream, ILogger logger)
      Outputs this printer to the specified stream and to the supplied logger with level Level.DEBUG
      Parameters:
      stream - Output stream to print to
      logger - Logger to write to
      Returns:
      fluent interface
    • trace

      public PrettyPrinter trace(PrintStream stream, ILogger logger, Level level)
      Outputs this printer to the specified stream and to the supplied logger with at the specified level
      Parameters:
      stream - Output stream to print to
      logger - Logger to write to
      level - Log level to write messages
      Returns:
      fluent interface
    • print

      public PrettyPrinter print()
      Print this printer to stderr
      Returns:
      fluent interface
    • print

      public PrettyPrinter print(PrintStream stream)
      Print this printer to the specified output
      Parameters:
      stream - stream to print to
      Returns:
      fluent interface
    • log

      public PrettyPrinter log(ILogger logger)
      Write this printer to the specified logger at Level.INFO
      Parameters:
      logger - logger to log to
      Returns:
      fluent interface
    • log

      public PrettyPrinter log(Level level)
      Write this printer to the specified logger at Level.INFO
      Parameters:
      level - log level
      Returns:
      fluent interface
    • log

      public PrettyPrinter log(ILogger logger, Level level)
      Write this printer to the specified logger
      Parameters:
      logger - logger to log to
      level - log level
      Returns:
      fluent interface
    • dumpStack

      public static void dumpStack()
      Convenience method, alternative to using Thread.dumpStack which prints to stderr in pretty-printed format.
    • print

      public static void print(Throwable th)
      Convenience methods, pretty-prints the specified throwable to stderr
      Parameters:
      th - Throwable to log