Awesome
V Terminal Tables
Simple and highly customizable library to display tables in the terminal.
Features
- Choose from seven predefined styles
- Or create any custom style you want
- Tab support
- Unicode support
Installation
v install serkonda7.termtable
Usage
import serkonda7.termtable as tt
fn main() {
data := [
['Name', 'Age', 'Sex'],
['Max', '13', 'male'],
['Moritz', '12', 'male'],
['Lisa', '42', 'female'],
]
t := tt.Table{
data: data
// The following settings are optional and have these defaults:
style: .grid
header_style: .bold
align: .left
orientation: .row
padding: 1
tabsize: 4
}
println(t)
}
Predefined Styles
Supported values for style: ...
are:
- .grid
- .pretty
- .plain
- .simple
- .fancy_grid
- .md
- .rst
.grid
(default):
.pretty
:
.plain
:
.simple
:
.fancy_grid
:
.md
follows the conventions of Markdown. It does not add alignment colons though:
.rst
behaves like the reStructuredText simple table format:
Header Style
// header_style: ...
.bold (default) | .plain |
---|---|
Alignment
// align: ...
| Max | 13 | male | // .left (default)
| Max | 13 | male | // .center
| Max | 13 | male | // .right
Orientation
t := tt.Table{
data: [
['Name', 'Age'],
['Max', '13'],
['Moritz', '12'],
]
// orientation: ...
}
println(t)
.row (default) | .column |
---|---|
Padding
Control the count of spaces between the cell border and the item.
// padding: ...
| Lisa | 42 | female | // 3
| Lisa | 42 | female | // 1 (default)
|Lisa|42|female| // 0
Tabsize
t := tt.Table{
data: [
['\tName', 'Sex'],
['1.\tMax', 'male\t'],
['2. \tMoritz', '\tmale'],
]
// tabsize: ...
}
println(t)
4 (default) | 2 | 8 |
---|---|---|
Creating Custom Styles
To create a custom style set the tables style property to style: .custom
and specify custom_style: tt.StyleConfig{...}
.
StyleConfig
Struct
topline tt.Sepline{...}
headerline tt.Sepline{...}
middleline tt.Sepline{...}
bottomline tt.Sepline{...}
colsep string
fill_padding bool = true
Sepline
Struct
left string
right string
cross string
sep string
Acknowledgements
- Images were made with carbon and optimized with image-actions
License
Licensed under the MIT License
<!-- Links -->