Skip to content

feat: dynamically adjust page size based on terminal height#21

Open
ZaidQtaish wants to merge 1 commit intoBharath-code:mainfrom
ZaidQtaish:feat/dynamic-page-size
Open

feat: dynamically adjust page size based on terminal height#21
ZaidQtaish wants to merge 1 commit intoBharath-code:mainfrom
ZaidQtaish:feat/dynamic-page-size

Conversation

@ZaidQtaish
Copy link
Contributor

Description

The page size was hardcoded to 15 repos per page regardless of terminal size. This updates resizeTable() to dynamically set pageSize based 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

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to change)
  • 📚 Documentation update
  • 🔧 Refactoring (no functional changes)

Checklist

  • I have tested my changes locally
  • I have updated the documentation (if applicable)
  • My code follows the project's style guidelines
  • I have added tests that prove my fix/feature works (if applicable)

Copilot AI review requested due to automatic review settings March 3, 2026 20:53
@ZaidQtaish ZaidQtaish force-pushed the feat/dynamic-page-size branch from b38d701 to 12dc58d Compare March 3, 2026 20:56
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 set pageSize based on the computed table height (with a minimum of 5).
  • Trigger a table refresh after resizing so the new pageSize takes 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.

Comment on lines +379 to +380
m.pageSize = h // Update page size based on new height
m.updateTable() // Refresh table to apply new page size
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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
}

Copilot uses AI. Check for mistakes.
Comment on lines +379 to +380
m.pageSize = h // Update page size based on new height
m.updateTable() // Refresh table to apply new page size
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
Comment on lines +375 to +379
// 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
Copy link

Copilot AI Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
// 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
}

Copilot uses AI. Check for mistakes.
@Bharath-code
Copy link
Owner

Will review the code, and test it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Make the default number of listed repos respect the current terminal size.

3 participants