Skip to content

Display Styles

Learn how to display your data in different formats using Show() options.

Default Style

The basic Show() displays data in a formatted table:

go
type Product struct {
    Name  string
    Price float64
    Stock int
}

products := []Product{
    {"Laptop", 999.99, 15},
    {"Mouse", 29.99, 50},
    {"Keyboard", 79.99, 30},
}

plygo.From(products).Show()

Result

+----------+--------+-------+
|     Name |  Price | Stock |
+----------+--------+-------+
| Laptop   | 999.99 |    15 |
| Mouse    |  29.99 |    50 |
| Keyboard |  79.99 |    30 |
+----------+--------+-------+
[3 rows × 3 columns]

Markdown Style

Use WithStyle("markdown") for markdown-formatted tables:

go
products := []Product{
    {"Laptop", 999.99, 15},
    {"Mouse", 29.99, 50},
    {"Keyboard", 79.99, 30},
}

plygo.From(products).Show(plygo.WithStyle("markdown"))

Result

|----------|--------|-------|
|     Name |  Price | Stock |
|----------|--------|-------|
| Laptop   | 999.99 |    15 |
| Mouse    |  29.99 |    50 |
| Keyboard |  79.99 |    30 |
|----------|--------|-------|
[3 rows × 3 columns]

Custom Options

Combine multiple options for customized output:

go
products := []Product{
    {"Laptop", 999.99, 15},
    {"Mouse", 29.99, 50},
    {"Keyboard", 79.99, 30},
}

plygo.From(products).Show(
    plygo.WithTitle("Product Inventory"),
    plygo.WithRowNumbers(true),
    plygo.WithFloatPrecision(2),
)

Result


        Product Inventory
+---+----------+--------+-------+
| # |     Name |  Price | Stock |
+---+----------+--------+-------+
| 1 | Laptop   | 999.99 |    15 |
| 2 | Mouse    |  29.99 |    50 |
| 3 | Keyboard |  79.99 |    30 |
+---+----------+--------+-------+
[3 rows × 4 columns]

Available Options

Here are all available Show() options:

OptionDescriptionExample
WithStyle(style)Set table style"compact", "markdown", "simple", "csv"
WithTitle(title)Add a title above the table"Sales Report"
WithRowNumbers(bool)Show row numberstrue or false
WithOriginalIndices(bool)Show original indicestrue or false
WithFloatPrecision(n)Set decimal places for floats2
WithMaxRows(n)Limit displayed rows100
WithMaxColWidth(n)Limit column width30
WithMaxWidth(n)Limit total table width120

Multiple Options

You can combine multiple options in a single Show() call:

go
.Show(
    plygo.WithTitle("Report"),
    plygo.WithStyle("markdown"),
    plygo.WithFloatPrecision(2),
    plygo.WithRowNumbers(true),
)

Style Examples

Compact Style

go
plygo.From(data).Show(plygo.WithStyle("compact"))

Simple Style

go
plygo.From(data).Show(plygo.WithStyle("simple"))

CSV Style

go
plygo.From(data).Show(plygo.WithStyle("csv"))

Next: Error Handling

Released under the MIT License.