Copyright (c) 2021, 2023, Geert JM Vanderkelen
Draw boxes around your data and display tables/listings on your favorite TTY.
Originally part of a (private) project conceived in the summer of 2021.
- Define headers and rows displaying the typical tables as seen in popular RDBMS client tools.
- Define your own boxing styles if stock owns are not enough.
package boxed_test
import (
"github.com/golistic/boxed"
)
func ExampleBasic() {
box := boxed.New()
_ = box.AddHeader("id", "user", "host", "locked")
_ = box.Append(
boxed.NewRow("1", "alice", "%", false),
boxed.NewRow("2", "bob", "127.0.0.1", false),
boxed.NewRow("3", "trudy", "%", true),
)
_ = box.Render()
// Output:
// ┌────┬───────┬───────────┬────────┐
// │ id │ user │ host │ locked │
// ├────┼───────┼───────────┼────────┤
// │ 1 │ alice │ % │ false │
// │ 2 │ bob │ 127.0.0.1 │ false │
// │ 3 │ trudy │ % │ true │
// └────┴───────┴───────────┴────────┘
}
package boxed_test
import (
"fmt"
"strings"
"github.com/golistic/boxed"
)
func ExampleSettings() {
box := boxed.New(boxed.WithStyle(boxed.Record))
_ = box.Append(
boxed.NewRow("username", "alice"),
boxed.NewRow("host", "%"),
boxed.NewRow("locked", true),
boxed.NewRow("max_questions", 2000),
)
// testable example trims spaces
for _, l := range strings.Split(box.RenderAsString(), "\n") {
fmt.Println(strings.TrimRight(l, " "))
}
// Output:
// username : alice
// host : %
// locked : true
// max_questions : 2000
}
box := boxed.New(boxed.WithStyle(boxed.Basic))
┌────┬───────┬───────────┬────────┐
│ id │ user │ host │ locked │
├────┼───────┼───────────┼────────┤
│ 1 │ alice │ % │ false │
│ 2 │ bob │ 127.0.0.1 │ false │
│ 3 │ trudy │ % │ true │
└────┴───────┴───────────┴────────┘
box := boxed.New(boxed.WithStyle(boxed.BasicNoOuter))
id │ user │ host │ locked
════╪═══════╪═══════════╪════════
1 │ alice │ % │ false
2 │ bob │ 127.0.0.1 │ false
3 │ trudy │ % │ true
This mimics the MySQL CLI output.
box := boxed.New(boxed.WithStyle(boxed.ANSI))
+----+-------+-----------+--------+
| id | user | host | locked |
+----+-------+-----------+--------+
| 1 | alice | % | false |
| 2 | bob | 127.0.0.1 | false |
| 3 | trudy | % | true |
+----+-------+-----------+--------+
box := boxed.New(boxed.WithStyle(boxed.ANSINoOuter))
This mimics the PostgreSQL CLI output.
id | user | host | locked
----+-------+-----------+--------
1 | alice | % | false
2 | bob | 127.0.0.1 | false
3 | trudy | % | true
box := boxed.New(boxed.WithStyle(boxed.Record))
No boxes here: we are showing a "record" which is actually a table with only 2 columns.
username : alice
host : %
locked : true
max_questions : 2000
Distributed under the MIT license. See LICENSE.txt
for more information.