-
Notifications
You must be signed in to change notification settings - Fork 358
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see the if pageSize == 0
logic repeated a few times for pagable prompts. I wonder if it would make sense to factor some of this out into a Pagable struct with composition, something like:
type Select struct {
Pagable
...
}
type Pagable struct {
PageSize int
}
func (p *Pagable) pageSize(config *PromptConfig) int {
if p.PageSize == 0 {
return config.PageSize
}
return p.PageSize
}
Then in your code:
func (s *Select) OnChange(key run, config *PromptConfig) bool {
...
pageSize := s.pageSize(config)
...
}
Going to approve this PR since I dont think the above changes are necessary, just something to think about.
Yea I thought about that while I was putting this together but it felt like a lot of ceremony for an if statement, especially considering I'd still have to pass the |
So I tried to consolidate the Select{
Pager{ PageSize: 7 }
} which is just a little too verbose for me |
0bb6203
to
a45be3a
Compare
Okay, yeah, I agree, forgot about that aspect. We could minimize this issue by having a |
Yea that's something to keep in mind. It starts to become very verbose and I think so long as we have sane interpretations of a zero value, we should keep the struct-based API as I think its much simpler for people to grok quickly |
It just occurred to me that it's also very possible that sort of API is what a solution to #105 would look like. |
* added PromptConfig to Prompt interface * documented WithPageSize * selects will pull page size from global config * removed unused variable * fixed display problem on key press
This PR is part of the work summarized in #201. It adds the
survey.WithPageSize
AskOpt
that replaces the modification ofsurvey.PageSize
as the way to modify the default page size for prompts.Since we now have to have a place for "global" configuration of prompts, I had to change the
Prompt
interface to include a reference to the config.