MCPcopy Index your code
hub / github.com/cloudfoundry/cli / DisplayNonWrappingTable

Method DisplayNonWrappingTable

util/ui/table.go:45–79  ·  view source on GitHub ↗

DisplayNonWrappingTable outputs a matrix of strings as a table to UI.Out. Prefix will be prepended to each row and padding adds the specified number of spaces between columns.

(prefix string, table [][]string, padding int)

Source from the content-addressed store, hash-verified

43// Prefix will be prepended to each row and padding adds the specified number
44// of spaces between columns.
45func (ui *UI) DisplayNonWrappingTable(prefix string, table [][]string, padding int) {
46 ui.terminalLock.Lock()
47 defer ui.terminalLock.Unlock()
48
49 if len(table) == 0 {
50 return
51 }
52
53 var columnPadding []int
54
55 rows := len(table)
56 columns := len(table[0])
57 for col := 0; col < columns; col++ {
58 var max int
59 for row := 0; row < rows; row++ {
60 if strLen := wordSize(table[row][col]); max < strLen {
61 max = strLen
62 }
63 }
64 columnPadding = append(columnPadding, max+padding)
65 }
66
67 for row := 0; row < rows; row++ {
68 fmt.Fprint(ui.Out, prefix)
69 for col := 0; col < columns; col++ {
70 data := table[row][col]
71 var addedPadding int
72 if col+1 != columns {
73 addedPadding = columnPadding[col] - wordSize(data)
74 }
75 fmt.Fprintf(ui.Out, "%s%s", data, strings.Repeat(" ", addedPadding))
76 }
77 fmt.Fprintf(ui.Out, "\n")
78 }
79}
80
81// DisplayTableWithHeader outputs a simple non-wrapping table with bolded
82// headers.

Callers 2

DisplayKeyValueTableMethod · 0.95

Calls 1

wordSizeFunction · 0.85

Tested by

no test coverage detected