A library for formatting/serializing text into boxes drawn using UTF-8 characters.
An example of a box produced by PrettyBoxFormatter:
┌─────────────────────────────────────────┐
│ │
│ Number of apples: 5 │
│ Apple seller name: John Johnson │
│ Has green apples: true │
│ │
└─────────────────────────────────────────┘
Another example, screenshot from Android Studio's Logcat:
PrettyBoxFormatter is not a logging library - the input strings/objects are simply converted to a single String containing the "box" with the desired content. You can then output that String to your console, write it to a file, send it over the Internet (don't know why you would do that), etc.
PrettyBoxFormatter can be used both with regular Java and with Android.
To add to your project using gradle, add the following:
dependencies {
...
implementation 'com.bgpixel:prettyboxformatter:1.4.0'
...
}
To use the library, first create an instance of PrettyBoxFormatter
then call one of the
format
methods which accept a List<String>
or an object implementing PrettyBoxable
interface:
PrettyBoxFormatter pbFormatter = new PrettyBoxFormatter();
String result = pbFormatter.format(content);
You can add inner horizontal lines by adding a LineWithLevel
or LineWithType
instance to a
List<CharSequence>
passed to format
method. For details, see
format method.
// Code // Result:
List<CharSequence> contentLines = new ArrayList<>(); // ┌─────────────┐
contentLines.add("First line"); // │ First line │
contentLines.add("Second line"); // │ Second line │
contentLines.add(LineWithLevel.LEVEL_1); // ├┄┄┄┄┄┄┄┄┄┄┄┄┄┤
contentLines.add("Third line"); // │ Third line │
// └─────────────┘
String result = pbFormatter.format(contentLines);
You can use different line types:
For more details, see the following wiki pages:
- Add a horizontal line to content by using LineWithType
- Define a lineset to use and add a horizontal line by referencing a LineType as defined in the lineset (LineWithLevel)
- minor - DOT LineType
- Newline fix for logcat
- minor - STAR LineType
- Set border and inner line type by using LineType.
- Separate settings for left/right/top/bottom padding & margin
- Option not to draw any/all sides of the box
- Add header & footer to each box with predefined metadata (e.g. timestamp, class name)
- Set horizontal/vertical margin/padding through PrettyBoxConfiguration
- Set instance-level and per-call configuration. If both set, values get merged.
- Draw boxes closed on the right side (setting)
- Print warning for invalid configuration
Simple initial version; no configuration, only prints LINE boxes with no padding, margin or border control. No right border.