Table defines a document that formats a list of pairs of items either: - as a 2-column table, with the two columns aligned for example: SELECT aaa bbb FROM ccc - as sections, for example: SELECT aaa bbb FROM ccc We restrict the left value in each list item to be a one-line string to make the width
(alignment TableAlignment, docFn func(string) Doc, rows ...TableRow)
| 229 | // docFn should be set to Text or Keyword and will be used when converting |
| 230 | // TableRow label's to Docs. |
| 231 | func Table(alignment TableAlignment, docFn func(string) Doc, rows ...TableRow) Doc { |
| 232 | // Compute the nested formatting in "sections". It's simple. |
| 233 | // Note that we do not use NestUnder() because we are not grouping |
| 234 | // at this level (the group is done for the final form below). |
| 235 | items := makeTableNestedSections(docFn, rows) |
| 236 | nestedSections := Stack(items...) |
| 237 | |
| 238 | finalDoc := nestedSections |
| 239 | |
| 240 | if alignment != TableNoAlign { |
| 241 | items = makeAlignedTableItems(alignment == TableRightAlignFirstColumn /* leftPad */, docFn, rows, items) |
| 242 | alignedTable := Stack(items...) |
| 243 | finalDoc = &union{alignedTable, nestedSections} |
| 244 | } |
| 245 | |
| 246 | return Group(finalDoc) |
| 247 | } |
| 248 | |
| 249 | func computeLeftColumnWidth(rows []TableRow) int { |
| 250 | leftwidth := 0 |
no test coverage detected
searching dependent graphs…