Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

table: paging should work with auto-merge; fixes #315 #317

Merged
merged 2 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 3 additions & 24 deletions table/render.go
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
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