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

Add minimum height option to table #154

Merged
merged 7 commits into from
Oct 17, 2023
Merged

Conversation

robertjli
Copy link
Contributor

Fixes #115.

Adds a WithMinimumHeight() option to Model. When set, we add "padding" rows when rendering the view to meet the specified minimum height.

Caveats:

  • If the data size or page size is large, the table ends up being taller than the minimum height. The issue mentions "fixed" height (from me too), so I just want to call out that this solution is slightly different, but the use case is to fill the screen so I think this PR still fits that criteria.
  • There is an edge case where there are zero rows of data and a small minimum height, where we are one line height away from the requested minimum. Because we can't add only a border, we add an empty row with border anyway, leading to a table that is one line taller than the requested minimum.

table/pagination.go Outdated Show resolved Hide resolved
Copy link
Owner

@Evertras Evertras left a comment

Choose a reason for hiding this comment

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

Thanks for the effort, and the test coverage! Seems reasonable overall, just a comment about modifying that exported function.

Would be good to slip this into one of the examples as well. Maybe the flex example since it's dealing with stretching horizontally, we can also stretch it vertically.

@robertjli
Copy link
Contributor Author

Would be good to slip this into one of the examples as well. Maybe the flex example since it's dealing with stretching horizontally, we can also stretch it vertically.

Sounds good, I've added it to the flex example!

Copy link
Owner

@Evertras Evertras left a comment

Choose a reason for hiding this comment

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

LGTM

@Evertras
Copy link
Owner

Ah we're going to need to be careful with coverage as well. You've added a bunch of checks in the options, but looks like they aren't covered: https://coveralls.io/builds/63298625/source?filename=table%2Foptions.go

I know it's a bit verbose, but it would be helpful to have tests to make sure the expected internal height values are correct after adding these options when a minimum height is set.

@Evertras
Copy link
Owner

Actually, looking at your tests, I think we'd just have to change the order of things. Basically, apply the minimum height first, then apply the options after. This would call your checks directly and should help considerably. Maybe pass in a function that applies extra options rather than a pre-set model with the options already applied?

@robertjli
Copy link
Contributor Author

Maybe pass in a function that applies extra options rather than a pre-set model with the options already applied?

Do you mean in the view tests?

What do you think about adding a test in options_test.go that creates a model with a minimum height, then applies each of the changed options and re-checks the internal values?

@Evertras
Copy link
Owner

Maybe pass in a function that applies extra options rather than a pre-set model with the options already applied?

Do you mean in the view tests?

What do you think about adding a test in options_test.go that creates a model with a minimum height, then applies each of the changed options and re-checks the internal values?

I think that would work fine too!

@Evertras
Copy link
Owner

Thanks for the contribution! Will release this along with your other PR once it's in.

@Evertras Evertras merged commit 6544304 into Evertras:main Oct 17, 2023
7 checks passed
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.

feat: method to expand to fill height tea.WithAltScreen()
2 participants