Skip to content

Commit

Permalink
table: paging should work with auto-merge; fixes #315
Browse files Browse the repository at this point in the history
  • Loading branch information
jedib0t committed Apr 8, 2024
1 parent d03b448 commit 25779f3
Show file tree
Hide file tree
Showing 6 changed files with 434 additions and 177 deletions.
27 changes: 3 additions & 24 deletions table/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ func (t *Table) renderLine(out *strings.Builder, row rowStr, hint renderHint) {
if outLine != out {
t.renderLineMergeOutputs(out, outLine)
}
t.firstRowOfPage = false

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

if t.shouldSeparate(rowIdx, len(rows)) {
if t.shouldSeparateRows(rowIdx, len(rows)) {
hint.isFirstRow = false
t.renderRowSeparator(out, hint)
}
}
}

func (t *Table) shouldSeparate(rowIdx int, numRows int) bool {
// last row before footer
if t.style.Options.SeparateRows && rowIdx < numRows-1 {
return true
}
// no manually added separator
if !t.separators[rowIdx] {
return false
}

pageSize := numRows
if t.pageSize > 0 {
pageSize = t.pageSize
}
if rowIdx%pageSize == pageSize-1 { // last row of page
return false
}
if rowIdx == numRows-1 { // last row of table
return false
}
return true
}

func (t *Table) renderRowsBorderBottom(out *strings.Builder) {
if len(t.rowsFooter) > 0 {
t.renderRowSeparator(out, renderHint{
Expand Down
1 change: 1 addition & 0 deletions table/render_init.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ func (t *Table) reset() {
t.autoIndexVIndexMaxLength = 0
t.columnConfigMap = nil
t.columnIsNonNumeric = nil
t.firstRowOfPage = true
t.maxColumnLengths = nil
t.maxRowLength = 0
t.numColumns = 0
Expand Down
Loading

0 comments on commit 25779f3

Please sign in to comment.