Home
Categories
Dictionary
Download
Project Details
Changes Log
FAQ
License

ConsoleHelper



The ConsoleHelper class allows to print ANSI escaped text in the Console.

On Windows, the default cmd.exe executable does not show ANSI escaped text. You should use the Windows Terminal instead.

Usage

To use this class: The result of the ConsoleHelper.addText(String text) method is a EscapedText which allows to set the decoration of the text to be shown in the Console.

Supported text decoration

The supported text decoration are:
The foreground and background colors are specified by he values of the EscapedColor interface.

Utility methods

Several utility methods in the ConsoleHelper class allow to print escaped texts without having to create an intermediary EscapedText: For example:
   ConsoleHelper helper = new ConsoleHelper();
   helper.println("The red text", EscapedColor.RED);

Adding serializers

The ConsoleHelper.addConsoleSerializer(ConsoleSerializer serializer) method allows to add a ConsoleSerializer to the console helper.

Default serializers

There are two default serializers:

Example

The following code:
   ConsoleHelper helper = new ConsoleHelper();
   helper.addText("The ");
   EscapedText text = helper.addText("Blue text");
   text.setForeground(EscapedColor.BLUE);
   helper.println();
      
   helper.addText("The ");
   text = helper.addText("Red italic text");
   text.setForeground(EscapedColor.RED);
   text.setItalic(true);
   helper.println();      
will show this result on the console:
console

Notes

  1. ^ [1] [2] The supported color codes are defined by he EscapedColor interface

Categories: Lang | Packages

Copyright 2006-2024 Herve Girod. All Rights Reserved. Documentation and source under the LGPL v2 and Apache 2.0 licences

Project Web Hosted by SourceForge.net Copyright 1999-2010 - Geeknet, Inc., All Rights Reserved About - Legal - Help