
Lightweight DSL creating beautiful text tables for CLIs and logs with adjustable padding, colspan, cell alignment, multiple border styles, and graceful empty-table handling.
A lightweight, intuitive DSL for creating beautiful text-based tables in Kotlin/Native. Perfect for CLI applications, logs, and terminal UIs.
Create a simple table using the DSL:
val table = buildTable {
row {
cell { +"ID" }
cell { +"Name" }
cell { +"Age" }
}
row {
cell { +"1" }
cell { +"John" }
cell { +"20" }
}
row {
cell { +"2" }
cell { +"Jane" }
cell { +"22" }
}
}
println(table)Output:
┌────┬──────┬─────┐
│ ID │ Name │ Age │
├────┼──────┼─────┤
│ 1 │ John │ 20 │
├────┼──────┼─────┤
│ 2 │ Jane │ 22 │
└────┴──────┴─────┘
Add the library to your project using Gradle:
repositories {
mavenCentral()
}
dependencies {
implementation("io.github.julius-babies:table-tui:v0.0.9")
}[versions]
table-tui = "v0.0.9"
[libraries]
table-tui = { module = "io.github.julius-babies:table-tui", version.ref = "table-tui" }dependencies {
implementation(libs.table.tui)
}Import the buildTable function and start creating tables:
val table = buildTable {
row {
cell { +"Hello" }
cell { +"World" }
}
}Create simple tables with rows and cells using the intuitive DSL.
val table = buildTable {
row {
cell { +"ID" }
cell { +"Name" }
cell { +"Age" }
}
people.forEach { person ->
row {
cell { +person.id }
cell { +person.name }
cell { +person.age.toString() }
}
}
}
println(table)Output:
┌────┬──────┬─────┐
│ ID │ Name │ Age │
├────┼──────┼─────┤
│ 1 │ John │ 20 │
├────┼──────┼─────┤
│ 2 │ Jane │ 22 │
└────┴──────┴─────┘
Adjust the spacing around cell content to improve readability.
val table = buildTable {
cellPadding = 2 // Default is 1
row {
cell { +"ID" }
cell { +"Name" }
cell { +"Age" }
}
row {
cell { +"1" }
cell { +"John" }
cell { +"20" }
}
}
println(table)Output:
┌──────┬────────┬───────┐
│ ID │ Name │ Age │
├──────┼────────┼───────┤
│ 1 │ John │ 20 │
└──────┴────────┴───────┘
Merge multiple columns into a single cell using colspan.
val table = buildTable {
row {
cell { +"ID" }
cell { +"Name" }
cell { +"Age" }
cell { +"Address" }
}
row {
cell { +"1" }
cell {
colspan = 2 // This cell spans 2 columns
+"John Doe"
}
cell { +"New York" }
}
}
println(table)Output:
┌────┬───────┬─────┬──────────┐
│ ID │ Name │ Age │ Address │
├────┼───────┴─────┼──────────┤
│ 1 │ John Doe │ New York │
└────┴─────────────┴──────────┘
Center content within cells using the centered property.
val table = buildTable {
row {
cell { +"ID" }
cell { +"Name" }
cell { +"Status" }
}
row {
cell { +"1" }
cell { +"John" }
cell {
centered = true
+"Active"
}
}
}
println(table)Output:
┌────┬──────┬────────┐
│ ID │ Name │ Status │
├────┼──────┼────────┤
│ 1 │ John │ Active │
└────┴──────┴────────┘
Choose from predefined border styles: Default, Double, or Borderless.
val table = buildTable {
// Use a predefined style
border = BorderStyle.Double
row {
cell { +"ID" }
cell { +"Name" }
}
row {
cell { +"1" }
cell { +"John" }
}
}
println(table)Output:
╔════╦══════╗
║ ID ║ Name ║
╠════╬══════╣
║ 1 ║ John ║
╚════╩══════╝
You can also hide all borders:
val table = buildTable {
border = BorderStyle.Borderless
row { cell { +"Hello" }; cell { +"World" } }
}
println(table) // prints just the cell contents separated by spacesMix and match features for complex table layouts.
val table = buildTable {
cellPadding = 2
row {
cell { +"ID" }
cell { +"Details" }
cell { +"Status" }
}
row {
cell { +"1" }
cell {
colspan = 2
centered = true
+"No data available"
}
}
row {
cell { +"2" }
cell { +"Item A" }
cell {
centered = true
+"✓"
}
}
}
println(table)Output:
┌──────┬───────────────┬──────────┐
│ ID │ Details │ Status │
├──────┼───────────────┴──────────┤
│ 1 │ No data available │
├──────┼───────────────┬──────────┤
│ 2 │ Item A │ ✓ │
└──────┴───────────────┴──────────┘
Empty tables are handled gracefully and return an empty string.
val table = buildTable {
// No rows added
}
println(table) // Prints nothing
println(table == "") // trueThis library supports the following Kotlin/Native targets:
buildTable { ... } - Creates a table and returns its string representationcellPadding: Int - Sets the padding around cell content (default: 1)border: BorderStyle - Selects the border style (Default, Double, Borderless)row { ... } - Adds a new row to the tablecell { ... } - Adds a new cell to the current row+"content" - Adds content to the cell using the unary plus operatorcolspan: Int - Number of columns the cell should span (default: 1)centered: Boolean - Centers the content within the cell (default: false)This project is licensed under the MIT License.
A lightweight, intuitive DSL for creating beautiful text-based tables in Kotlin/Native. Perfect for CLI applications, logs, and terminal UIs.
Create a simple table using the DSL:
val table = buildTable {
row {
cell { +"ID" }
cell { +"Name" }
cell { +"Age" }
}
row {
cell { +"1" }
cell { +"John" }
cell { +"20" }
}
row {
cell { +"2" }
cell { +"Jane" }
cell { +"22" }
}
}
println(table)Output:
┌────┬──────┬─────┐
│ ID │ Name │ Age │
├────┼──────┼─────┤
│ 1 │ John │ 20 │
├────┼──────┼─────┤
│ 2 │ Jane │ 22 │
└────┴──────┴─────┘
Add the library to your project using Gradle:
repositories {
mavenCentral()
}
dependencies {
implementation("io.github.julius-babies:table-tui:v0.0.9")
}[versions]
table-tui = "v0.0.9"
[libraries]
table-tui = { module = "io.github.julius-babies:table-tui", version.ref = "table-tui" }dependencies {
implementation(libs.table.tui)
}Import the buildTable function and start creating tables:
val table = buildTable {
row {
cell { +"Hello" }
cell { +"World" }
}
}Create simple tables with rows and cells using the intuitive DSL.
val table = buildTable {
row {
cell { +"ID" }
cell { +"Name" }
cell { +"Age" }
}
people.forEach { person ->
row {
cell { +person.id }
cell { +person.name }
cell { +person.age.toString() }
}
}
}
println(table)Output:
┌────┬──────┬─────┐
│ ID │ Name │ Age │
├────┼──────┼─────┤
│ 1 │ John │ 20 │
├────┼──────┼─────┤
│ 2 │ Jane │ 22 │
└────┴──────┴─────┘
Adjust the spacing around cell content to improve readability.
val table = buildTable {
cellPadding = 2 // Default is 1
row {
cell { +"ID" }
cell { +"Name" }
cell { +"Age" }
}
row {
cell { +"1" }
cell { +"John" }
cell { +"20" }
}
}
println(table)Output:
┌──────┬────────┬───────┐
│ ID │ Name │ Age │
├──────┼────────┼───────┤
│ 1 │ John │ 20 │
└──────┴────────┴───────┘
Merge multiple columns into a single cell using colspan.
val table = buildTable {
row {
cell { +"ID" }
cell { +"Name" }
cell { +"Age" }
cell { +"Address" }
}
row {
cell { +"1" }
cell {
colspan = 2 // This cell spans 2 columns
+"John Doe"
}
cell { +"New York" }
}
}
println(table)Output:
┌────┬───────┬─────┬──────────┐
│ ID │ Name │ Age │ Address │
├────┼───────┴─────┼──────────┤
│ 1 │ John Doe │ New York │
└────┴─────────────┴──────────┘
Center content within cells using the centered property.
val table = buildTable {
row {
cell { +"ID" }
cell { +"Name" }
cell { +"Status" }
}
row {
cell { +"1" }
cell { +"John" }
cell {
centered = true
+"Active"
}
}
}
println(table)Output:
┌────┬──────┬────────┐
│ ID │ Name │ Status │
├────┼──────┼────────┤
│ 1 │ John │ Active │
└────┴──────┴────────┘
Choose from predefined border styles: Default, Double, or Borderless.
val table = buildTable {
// Use a predefined style
border = BorderStyle.Double
row {
cell { +"ID" }
cell { +"Name" }
}
row {
cell { +"1" }
cell { +"John" }
}
}
println(table)Output:
╔════╦══════╗
║ ID ║ Name ║
╠════╬══════╣
║ 1 ║ John ║
╚════╩══════╝
You can also hide all borders:
val table = buildTable {
border = BorderStyle.Borderless
row { cell { +"Hello" }; cell { +"World" } }
}
println(table) // prints just the cell contents separated by spacesMix and match features for complex table layouts.
val table = buildTable {
cellPadding = 2
row {
cell { +"ID" }
cell { +"Details" }
cell { +"Status" }
}
row {
cell { +"1" }
cell {
colspan = 2
centered = true
+"No data available"
}
}
row {
cell { +"2" }
cell { +"Item A" }
cell {
centered = true
+"✓"
}
}
}
println(table)Output:
┌──────┬───────────────┬──────────┐
│ ID │ Details │ Status │
├──────┼───────────────┴──────────┤
│ 1 │ No data available │
├──────┼───────────────┬──────────┤
│ 2 │ Item A │ ✓ │
└──────┴───────────────┴──────────┘
Empty tables are handled gracefully and return an empty string.
val table = buildTable {
// No rows added
}
println(table) // Prints nothing
println(table == "") // trueThis library supports the following Kotlin/Native targets:
buildTable { ... } - Creates a table and returns its string representationcellPadding: Int - Sets the padding around cell content (default: 1)border: BorderStyle - Selects the border style (Default, Double, Borderless)row { ... } - Adds a new row to the tablecell { ... } - Adds a new cell to the current row+"content" - Adds content to the cell using the unary plus operatorcolspan: Int - Number of columns the cell should span (default: 1)centered: Boolean - Centers the content within the cell (default: false)This project is licensed under the MIT License.