KFormat is a tiny Kotlin library for formatted text output such as printing values in a structured table. Typical use cases include CLI tool development.
- Table (doc/source)
- Grid-based like a HTML table
- Auto-sizing of cell widths
- Formatting hints, such as for alignment, floating precision rendering or border rendering
Format a table including cell resizing:
table {
header("A", "B", "C", "Long_Header")
row(10, "b...1", 2.1f, "foo")
row(20, "b2", 1/3f, "bar")
hints {
alignment("A", Hints.Alignment.LEFT)
precision("C", 2)
postfix("C", "%")
borderStyle = Table.BorderStyle.SINGLE_LINE // or NONE
}
}.render(StringBuilder())
Generated output:
A | B | C | Long_Header
---|-------|-------|------------
10 | b...1 | 2.10% | foo
20 | b2 | 0.33% | bar
For further examples, see test cases
Download from Maven Central or use GAV de.m3y.kformat:kformat:VERSION
<dependency>
<groupId>de.m3y.kformat</groupId>
<artifactId>kformat</artifactId>
<version>VERSION</version>
</dependency>
mvn install
mvn dokka:dokka -Pgithub-pages
Copyright 2019-2024 Marcel May