Simple table
import Table
let cells:[[Txt]] = [
["123",
Txt("x", alignment: .topLeft),
Txt("x", alignment: .topCenter),
Txt("x", alignment: .topRight)],
["123",
Txt("x", alignment: .middleLeft),
Txt("x", alignment: .middleCenter),
Txt("x", alignment: .middleRight)],
["123",
Txt("x", alignment: .bottomLeft),
Txt("x", alignment: .bottomCenter),
Txt("x", alignment: .bottomRight)],
]
let width:Width = 5
let cols = [
Col("#", width: 1, defaultAlignment: .topLeft),
Col("Col 1", width: width, defaultAlignment: .bottomCenter),
Col("Col 2", width: width, defaultAlignment: .bottomCenter),
Col("Col 3", width: width, defaultAlignment: .bottomCenter),
]
let table = Tbl("Table title",
columns: cols,
cells: cells)
print(table.render(style: .roundedPadded))
// Produces ->
//โญโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
//โ Table title โ
//โโโโโฌโโโโโโโโฌโโโโโโโโฌโโโโโโโโค
//โ # โ Col 1 โ Col 2 โ Col 3 โ
//โโโโโผโโโโโโโโผโโโโโโโโผโโโโโโโโค
//โ 1 โ x โ x โ x โ
//โ 2 โ โ โ โ
//โ 3 โ โ โ โ
//โโโโโผโโโโโโโโผโโโโโโโโผโโโโโโโโค
//โ 1 โ โ โ โ
//โ 2 โ x โ x โ x โ
//โ 3 โ โ โ โ
//โโโโโผโโโโโโโโผโโโโโโโโผโโโโโโโโค
//โ 1 โ โ โ โ
//โ 2 โ โ โ โ
//โ 3 โ x โ x โ x โ
//โฐโโโโดโโโโโโโโดโโโโโโโโดโโโโโโโโฏ
Another simple table using DSL.
import Table
let table = Tbl("Summer Olympics") {
Columns {
Col("Year", width: 4)
Col("Host", width: .in(5...25), defaultWrapping: .word)
Col("Country")
}
Rows {
["1952", "Helsinki", "Finland"]
["1956", "Stockholm", "Sweden"]
["1960", "Rome", "Italy"]
}
}
print(table.render(style: .rounded))
//โญโโโโโโโโโโโโโโโโโโโโโโโฎ
//โ Summer Olympics โ
//โโโโโโฌโโโโโโโโโโฌโโโโโโโโค
//โYearโHost โCountryโ
//โโโโโโผโโโโโโโโโโผโโโโโโโโค
//โ1952โHelsinki โFinlandโ
//โโโโโโผโโโโโโโโโโผโโโโโโโโค
//โ1956โStockholmโSweden โ
//โโโโโโผโโโโโโโโโโผโโโโโโโโค
//โ1960โRome โItaly โ
//โฐโโโโโดโโโโโโโโโโดโโโโโโโโฏ
link |
Stars: 1 |
Last commit: 2 days ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics