MCPcopy Create free account
hub / github.com/cli/go-gh / ExampleTablePrinter

Function ExampleTablePrinter

pkg/tableprinter/table_test.go:14–35  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

12)
13
14func 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
37func Test_ttyTablePrinter_autoTruncate(t *testing.T) {
38 buf := bytes.Buffer{}

Callers

nothing calls this directly

Calls 6

WithTruncateFunction · 0.85
WithColorFunction · 0.85
NewFunction · 0.70
AddFieldMethod · 0.65
EndRowMethod · 0.65
RenderMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…