-
-
Notifications
You must be signed in to change notification settings - Fork 377
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
feat(block): add Block::bordered
#736
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #736 +/- ##
=====================================
Coverage 92.3% 92.3%
=====================================
Files 48 48
Lines 14807 14817 +10
=====================================
+ Hits 13673 13683 +10
Misses 1134 1134 ☔ View full report in Codecov by Sentry. |
Intuitively I would say the correct name for this function would be |
Sounds great, I change it now. |
This avoid creating a block with no borders and then settings Borders::ALL. i.e. ```diff - Block::default().borders(Borders::ALL); + Block::all_borders(); ```
c88da07
to
2d82e0e
Compare
It would be worth taking a look through the following to get some idea of how people are calling this outside and inside ratatui:
Perhaps it would be worth breaking backwards compatibility and introducing borders, and title params to the let block = Block::new("title", Borders:ALL); P.S. |
There's enough ways to create titles (left align, center align, right align; multiple titles etc) that I don't think I'd want to do this.
Also, as an example, But I could be convinced that |
I'm in strong disagreement with this statement. A constructor should accept the most common or most necessary items that a type needs. Builder methods are there for the things which are more optional than necessary. If 90% (unchecked number) of the usages of block set borders and a title, then that is what should be in the
That's fine - "Multiple titles" is a lower priority item as it falls in the 5% bucket. Also, I've been rethinking the need for
Not sure what you mean by this.
This would be a very bad idea as it would break the UI of every app out there. |
Added an issue for fixing up title: |
In languages like Python, all of these can build a Block(title = "title", borders = "all")
Block(borders = "all", title = "title")
Block(borders = "all")
Block() In Rust, we have to use this pattern for the same benefits (not breaking future features, configuration of defaults, changing order in which you set fields, etc): Block::new().title("title").borders(Borders::ALL) which my understanding of is why it the convention for building Also, you can build a fwiw, I like that Also, it is generally way faster for me to type |
It'd be nice if GitHub allowed us to fork a part of thread into a separate issue :) We can continue this discussion off this PR. |
Discussion continues in #747 |
Reading https://rust-lang.github.io/api-guidelines/predictability.html#constructors-are-static-inherent-methods-c-ctor, |
Block::all_borders
Block::bordered
I'd be in favor of I like |
Responding to relevant comments regarding breaking If breaking changes weren't a concern, I would have changed the default of But I get @kdheepak's point where you basically want a clean sheet and add onto it. So I'd keep The opposite could do too, i.e. As for adding parameters to
Anyway I'm afraid this will be too much of a breaking change and thus not worth it. Which is why I choose a specialized |
This avoid creating a block with no borders and then settings Borders::ALL. i.e.
Searching on github, 1.3K use
.borders(Borders:ALL)
for a total of 1.5K.borders(
usage.Names I considered:
all
: too implicit,Block::all()
in the wild isn't clearwith_borders
: would be confused withwith_borders(b: Borders)
i.e. with a parameterwith_all_borders
: the most explicit but too long imoborders_all
: to match withBorders::ALL
enum, nothing wrong with that, I just feel likeBlock::all_borders
is easier to read and more natural