PrintTo is the core functionality for printing the table, placing the formatted table into the writer given to it as argument. The exported Print() is just a wrapper around this which redirects the result into CF data structures. Once a table has been printed onto a Writer, it cannot be printed agai
(result io.Writer)
| 74 | // Once a table has been printed onto a Writer, it cannot be printed |
| 75 | // again. |
| 76 | func (t *Table) PrintTo(result io.Writer) error { |
| 77 | t.rowHeight = make([]int, len(t.rows)+1) |
| 78 | |
| 79 | rowIndex := 0 |
| 80 | if !t.headerPrinted { |
| 81 | // row transformer header row |
| 82 | err := t.calculateMaxSize(transHeader, rowIndex, t.headers) |
| 83 | if err != nil { |
| 84 | return err |
| 85 | } |
| 86 | rowIndex++ |
| 87 | } |
| 88 | |
| 89 | for _, row := range t.rows { |
| 90 | // table is row transformer itself, for content rows |
| 91 | err := t.calculateMaxSize(t, rowIndex, row) |
| 92 | if err != nil { |
| 93 | return err |
| 94 | } |
| 95 | rowIndex++ |
| 96 | } |
| 97 | |
| 98 | rowIndex = 0 |
| 99 | if !t.headerPrinted { |
| 100 | err := t.printRow(result, transHeader, rowIndex, t.headers) |
| 101 | if err != nil { |
| 102 | return err |
| 103 | } |
| 104 | t.headerPrinted = true |
| 105 | rowIndex++ |
| 106 | } |
| 107 | |
| 108 | for row := range t.rows { |
| 109 | err := t.printRow(result, t, rowIndex, t.rows[row]) |
| 110 | if err != nil { |
| 111 | return err |
| 112 | } |
| 113 | rowIndex++ |
| 114 | } |
| 115 | |
| 116 | t.rows = [][]string{} |
| 117 | return nil |
| 118 | } |
| 119 | |
| 120 | // calculateMaxSize iterates over the collected rows of the specified |
| 121 | // table, and their strings, determining the height of each row (in |
no test coverage detected