| 12 | ) |
| 13 | |
| 14 | func ExampleTablePrinter() { |
| 15 | // information about the terminal can be obtained using the [pkg/term] package |
| 16 | isTTY := true |
| 17 | termWidth := 14 |
| 18 | red := func(s string) string { |
| 19 | return "\x1b[31m" + s + "\x1b[m" |
| 20 | } |
| 21 | |
| 22 | t := New(os.Stdout, isTTY, termWidth) |
| 23 | t.AddField("9", WithTruncate(nil)) |
| 24 | t.AddField("hello") |
| 25 | t.EndRow() |
| 26 | t.AddField("10", WithTruncate(nil)) |
| 27 | t.AddField("long description", WithColor(red)) |
| 28 | t.EndRow() |
| 29 | if err := t.Render(); err != nil { |
| 30 | log.Fatal(err) |
| 31 | } |
| 32 | // stdout now contains: |
| 33 | // 9 hello |
| 34 | // 10 long de... |
| 35 | } |
| 36 | |
| 37 | func Test_ttyTablePrinter_autoTruncate(t *testing.T) { |
| 38 | buf := bytes.Buffer{} |