feat: dynamically adjust page size based on terminal height#21
feat: dynamically adjust page size based on terminal height#21ZaidQtaish wants to merge 1 commit intoBharath-code:mainfrom
Conversation
b38d701 to
12dc58d
Compare
There was a problem hiding this comment.
Pull request overview
This PR updates the TUI pagination behavior so the number of repositories shown per page adapts to the available terminal height, instead of using a fixed default (15), and tweaks the docs navbar GitHub link styling.
Changes:
- Update
resizeTable()to setpageSizebased on the computed table height (with a minimum of 5). - Trigger a table refresh after resizing so the new
pageSizetakes effect immediately. - Adjust the docs navbar GitHub link styling to use a flex layout.
Reviewed changes
Copilot reviewed 1 out of 1 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| internal/tui/model.go | Dynamically derives pageSize from terminal/table height and refreshes the table on resize. |
| docs/index.html | Updates inline styles for the GitHub link container in the navbar. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| m.pageSize = h // Update page size based on new height | ||
| m.updateTable() // Refresh table to apply new page size |
There was a problem hiding this comment.
Calling m.updateTable() from resizeTable() means every tea.WindowSizeMsg will re-run applyFilter() and sortRepos() (O(n log n)) even though only the current page slice needs to change. Consider updating just the visible rows for the current page (and only re-sorting when the underlying repo list / filter / sort mode changes) to avoid unnecessary work during continuous resize events.
| m.pageSize = h // Update page size based on new height | |
| m.updateTable() // Refresh table to apply new page size | |
| // Only refresh the table when the effective page size actually changes | |
| if h != m.pageSize { | |
| m.pageSize = h // Update page size based on new height | |
| m.updateTable() // Refresh table to apply new page size | |
| } |
| m.pageSize = h // Update page size based on new height | ||
| m.updateTable() // Refresh table to apply new page size |
There was a problem hiding this comment.
pageSize can change on resize without adjusting currentPage. If pageSize increases, currentPage*m.pageSize may become out of range, and getCurrentPageRepos() will silently fall back to showing the first page while currentPage remains unchanged, leading to inconsistent pagination state (and incorrect “Page X of Y” behavior). After changing pageSize, clamp currentPage to [0, totalPages-1] (or reset it) before refreshing rows.
| m.pageSize = h // Update page size based on new height | |
| m.updateTable() // Refresh table to apply new page size | |
| m.pageSize = h // Update page size based on new height | |
| // Clamp currentPage to the valid range for the new page size to keep pagination consistent | |
| totalRows := len(m.table.Rows()) | |
| if totalRows == 0 { | |
| m.currentPage = 0 | |
| } else { | |
| totalPages := (totalRows + m.pageSize - 1) / m.pageSize | |
| if totalPages < 1 { | |
| totalPages = 1 | |
| } | |
| if m.currentPage < 0 { | |
| m.currentPage = 0 | |
| } else if m.currentPage >= totalPages { | |
| m.currentPage = totalPages - 1 | |
| } | |
| } | |
| m.updateTable() // Refresh table to apply new page size and current page |
| // Ensure page size is at least 5 to avoid too small pages | ||
| if h < 5 { | ||
| h = 5 | ||
| } | ||
| m.pageSize = h // Update page size based on new height |
There was a problem hiding this comment.
This change makes pageSize effectively ignore the configured cfg.PageSize (the initial pageSize from config will be overwritten on the first window-size event). If pageSize is meant to remain user-configurable, consider only applying the dynamic sizing when the config value is unset/default, or treating the config value as a hard override / max.
| // Ensure page size is at least 5 to avoid too small pages | |
| if h < 5 { | |
| h = 5 | |
| } | |
| m.pageSize = h // Update page size based on new height | |
| // Compute a dynamic page size based on height, with a minimum of 5 | |
| dynamicPageSize := h | |
| if dynamicPageSize < 5 { | |
| dynamicPageSize = 5 | |
| } | |
| // If a positive PageSize is configured, respect it; otherwise use the dynamic size | |
| if m.cfg != nil && m.cfg.PageSize > 0 { | |
| m.pageSize = m.cfg.PageSize | |
| } else { | |
| m.pageSize = dynamicPageSize | |
| } |
|
Will review the code, and test it. |
Description
The page size was hardcoded to 15 repos per page regardless of terminal size. This updates
resizeTable()to dynamically setpageSizebased on available terminal height, so larger terminals show more repos and smaller ones show fewer. Minimum page size is capped at 5.Fixes #17
Type of Change
Checklist