Skip to content

Commit 027182a

Browse files
authored
table: paging should work with auto-merge; fixes #315 (#317)
1 parent d03b448 commit 027182a

File tree

6 files changed

+319
-177
lines changed

6 files changed

+319
-177
lines changed

table/render.go

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ func (t *Table) renderLine(out *strings.Builder, row rowStr, hint renderHint) {
207207
if outLine != out {
208208
t.renderLineMergeOutputs(out, outLine)
209209
}
210+
t.firstRowOfPage = false
210211

211212
// if a page size has been set, and said number of lines has already
212213
// been rendered, and the header is not being rendered right now, render
@@ -219,6 +220,7 @@ func (t *Table) renderLine(out *strings.Builder, row rowStr, hint renderHint) {
219220
out.WriteString(t.style.Box.PageSeparator)
220221
t.renderRowsBorderTop(out)
221222
t.renderRowsHeader(out)
223+
t.firstRowOfPage = true
222224
}
223225
}
224226
}
@@ -313,36 +315,13 @@ func (t *Table) renderRows(out *strings.Builder, rows []rowStr, hint renderHint)
313315
hint.rowNumber = rowIdx + 1
314316
t.renderRow(out, row, hint)
315317

316-
if t.shouldSeparate(rowIdx, len(rows)) {
318+
if t.shouldSeparateRows(rowIdx, len(rows)) {
317319
hint.isFirstRow = false
318320
t.renderRowSeparator(out, hint)
319321
}
320322
}
321323
}
322324

323-
func (t *Table) shouldSeparate(rowIdx int, numRows int) bool {
324-
// last row before footer
325-
if t.style.Options.SeparateRows && rowIdx < numRows-1 {
326-
return true
327-
}
328-
// no manually added separator
329-
if !t.separators[rowIdx] {
330-
return false
331-
}
332-
333-
pageSize := numRows
334-
if t.pageSize > 0 {
335-
pageSize = t.pageSize
336-
}
337-
if rowIdx%pageSize == pageSize-1 { // last row of page
338-
return false
339-
}
340-
if rowIdx == numRows-1 { // last row of table
341-
return false
342-
}
343-
return true
344-
}
345-
346325
func (t *Table) renderRowsBorderBottom(out *strings.Builder) {
347326
if len(t.rowsFooter) > 0 {
348327
t.renderRowSeparator(out, renderHint{

table/render_init.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ func (t *Table) reset() {
278278
t.autoIndexVIndexMaxLength = 0
279279
t.columnConfigMap = nil
280280
t.columnIsNonNumeric = nil
281+
t.firstRowOfPage = true
281282
t.maxColumnLengths = nil
282283
t.maxRowLength = 0
283284
t.numColumns = 0

0 commit comments

Comments
 (0)