Skip to content

KFormat is a tiny Kotlin library for formatted text output such as printing values in a structured table

License

Notifications You must be signed in to change notification settings

marcelmay/kformat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

KFormat

Maven Central License Pure Java + Kotlin CI

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

Examples

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

Downloading

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>

Building

mvn install
mvn dokka:dokka -Pgithub-pages

Copyright

Copyright 2019-2024 Marcel May