Class JAnsiTextRenderer

  • All Implemented Interfaces:
    TextRenderer

    public final class JAnsiTextRenderer
    extends java.lang.Object
    implements TextRenderer
    Renders an input as ANSI escaped output. Uses the JAnsi rendering syntax as the default to render a message into an ANSI escaped string. The default syntax for embedded ANSI codes is:
       @|code(,code)* text|@
     
    For example, to render the message "Hello" in green, use:
       @|green Hello|@
     
    To render the message "Hello" in bold and red, use:
       @|bold,red Warning!|@
     
    You can also define custom style names in the configuration with the syntax:
     %message{ansi}{StyleName=value(,value)*( StyleName=value(,value)*)*}%n
     
    For example:
     %message{ansi}{WarningStyle=red,bold KeyStyle=white ValueStyle=blue}%n
     
    The call site can look like this:
     logger.info("@|KeyStyle {}|@ = @|ValueStyle {}|@", entry.getKey(), entry.getValue());
     
    Note: This class originally copied and then heavily modified code from JAnsi's AnsiRenderer (which is licensed as Apache 2.0.)
    See Also:
    AnsiRenderer
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.util.Map<java.lang.String,​org.fusesource.jansi.AnsiRenderer.Code[]> DefaultExceptionStyleMap  
    • Constructor Summary

      Constructors 
      Constructor Description
      JAnsiTextRenderer​(java.lang.String[] formats, java.util.Map<java.lang.String,​org.fusesource.jansi.AnsiRenderer.Code[]> defaultStyleMap)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.Map<java.lang.String,​org.fusesource.jansi.AnsiRenderer.Code[]> getStyleMap()  
      void render​(java.lang.StringBuilder input, java.lang.StringBuilder output)
      Renders input text to an output.
      void render​(java.lang.String input, java.lang.StringBuilder output, java.lang.String styleName)
      Renders input text to an output.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • DefaultExceptionStyleMap

        public static final java.util.Map<java.lang.String,​org.fusesource.jansi.AnsiRenderer.Code[]> DefaultExceptionStyleMap
    • Constructor Detail

      • JAnsiTextRenderer

        public JAnsiTextRenderer​(java.lang.String[] formats,
                                 java.util.Map<java.lang.String,​org.fusesource.jansi.AnsiRenderer.Code[]> defaultStyleMap)
    • Method Detail

      • getStyleMap

        public java.util.Map<java.lang.String,​org.fusesource.jansi.AnsiRenderer.Code[]> getStyleMap()
      • render

        public void render​(java.lang.String input,
                           java.lang.StringBuilder output,
                           java.lang.String styleName)
                    throws java.lang.IllegalArgumentException
        Description copied from interface: TextRenderer
        Renders input text to an output.
        Specified by:
        render in interface TextRenderer
        Parameters:
        input - The input
        output - The output
        styleName - The style name to use to render the input on the output.
        Throws:
        java.lang.IllegalArgumentException
      • render

        public void render​(java.lang.StringBuilder input,
                           java.lang.StringBuilder output)
                    throws java.lang.IllegalArgumentException
        Description copied from interface: TextRenderer
        Renders input text to an output.
        Specified by:
        render in interface TextRenderer
        Parameters:
        input - The input
        output - The output
        Throws:
        java.lang.IllegalArgumentException
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object