renderRow renders a row. It merges the cells of a row into one string. Each line of each cell is merged with the same line of the other cells.
(t table, r row)
| 257 | // It merges the cells of a row into one string. |
| 258 | // Each line of each cell is merged with the same line of the other cells. |
| 259 | func (p TablePrinter) renderRow(t table, r row) string { |
| 260 | var s string |
| 261 | |
| 262 | // Merge lines of cells and add separator |
| 263 | // Use t.maxColumnWidths to add padding to corresponding cell |
| 264 | // A newline in a cell should be in the same column as original cell |
| 265 | for i := 0; i < r.height; i++ { |
| 266 | for j, c := range r.cells { |
| 267 | var currentLine string |
| 268 | if i < len(c.lines) { |
| 269 | currentLine = c.lines[i] |
| 270 | } |
| 271 | paddingForLine := t.maxColumnWidths[j] - internal.GetStringMaxWidth(currentLine) |
| 272 | |
| 273 | // Add right alignment if necessary |
| 274 | if p.RightAlignment { |
| 275 | s += strings.Repeat(" ", paddingForLine) |
| 276 | } |
| 277 | |
| 278 | // Add line content |
| 279 | if i < len(c.lines) { |
| 280 | s += c.lines[i] |
| 281 | } |
| 282 | |
| 283 | // Add padding for left alignment, except for last column |
| 284 | if j < len(r.cells)-1 { |
| 285 | if p.LeftAlignment { |
| 286 | s += strings.Repeat(" ", paddingForLine) |
| 287 | } |
| 288 | s += p.SeparatorStyle.Sprint(p.Separator) |
| 289 | } else if p.LeftAlignment { |
| 290 | // Add padding after last column |
| 291 | s += strings.Repeat(" ", paddingForLine) |
| 292 | } |
| 293 | } |
| 294 | s += "\n" |
| 295 | } |
| 296 | |
| 297 | return s |
| 298 | } |
| 299 | |
| 300 | // Render prints the TablePrinter to the terminal. |
| 301 | func (p TablePrinter) Render() error { |
no test coverage detected