https://github.com/marcelmay/kformat
KFormat is a tiny Kotlin library for formatted text output such as printing values in a structured table
https://github.com/marcelmay/kformat
formatted-text formatter kotlin kotlin-dsl kotlin-jvm
Last synced: 9 months ago
JSON representation
KFormat is a tiny Kotlin library for formatted text output such as printing values in a structured table
- Host: GitHub
- URL: https://github.com/marcelmay/kformat
- Owner: marcelmay
- License: apache-2.0
- Created: 2019-12-12T12:51:43.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2025-09-11T04:36:46.000Z (9 months ago)
- Last Synced: 2025-09-11T07:59:36.905Z (9 months ago)
- Topics: formatted-text, formatter, kotlin, kotlin-dsl, kotlin-jvm
- Language: Kotlin
- Size: 282 KB
- Stars: 40
- Watchers: 2
- Forks: 4
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# KFormat
[](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22de.m3y.kformat%22%20AND%20a%3A%22kformat%22)
[](http://www.apache.org/licenses/LICENSE-2.0.html)

[](https://github.com/marcelmay/kformat/actions/workflows/ci.yml)
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](docs/dokka/kformat/de.m3y.kformat/-table/index.md)/[source](src/main/kotlin/de/m3y/kformat/Table.kt))
* Grid-based like an 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:
```kotlin
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](src/test/kotlin/de/m3y/kformat/TableTest.kt)
## Downloading
Download from [Maven Central](https://search.maven.org/search?q=g:de.m3y.kformat%20AND%20a:kformat) or use GAV de.m3y.kformat:kformat:VERSION
```xml
de.m3y.kformat
kformat
VERSION
```
## Building
```bash
mvn install
mvn dokka:dokka -Pgithub-pages # Re-generates docs/dokka/ markdown documentation
```
## Copyright
Copyright 2019-2025 [Marcel May](https://github.com/marcelmay)