Print tabular data to a terminal or in machine-readable format for scripts.
()
| 279 | |
| 280 | // Print tabular data to a terminal or in machine-readable format for scripts. |
| 281 | func ExampleTablePrinter() { |
| 282 | terminal := term.FromEnv() |
| 283 | termWidth, _, _ := terminal.Size() |
| 284 | t := tableprinter.New(terminal.Out(), terminal.IsTerminalOutput(), termWidth) |
| 285 | |
| 286 | red := func(s string) string { |
| 287 | return "\x1b[31m" + s + "\x1b[m" |
| 288 | } |
| 289 | |
| 290 | // add a field that will render with color and will not be auto-truncated |
| 291 | t.AddField("1", tableprinter.WithColor(red), tableprinter.WithTruncate(nil)) |
| 292 | t.AddField("hello") |
| 293 | t.EndRow() |
| 294 | t.AddField("2") |
| 295 | t.AddField("world") |
| 296 | t.EndRow() |
| 297 | if err := t.Render(); err != nil { |
| 298 | log.Fatal(err) |
| 299 | } |
| 300 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…