-
Notifications
You must be signed in to change notification settings - Fork 229
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
fix: return consistent border sizes when BorderStyle is used. #282
base: master
Are you sure you want to change the base?
fix: return consistent border sizes when BorderStyle is used. #282
Conversation
86319a6
to
4a09ade
Compare
@meowgorithm ping. I've pushed the changes you requested. Would you mind taking another look? |
Ping? |
get.go
Outdated
@@ -300,7 +300,7 @@ func (s Style) GetBorderTopWidth() int { | |||
// runes of varying widths, the widest rune is returned. If no border exists on | |||
// the top edge, 0 is returned. | |||
func (s Style) GetBorderTopSize() int { | |||
if !s.getAsBool(borderTopKey, false) { | |||
if !s.getAsBool(borderTopKey, s.shouldAutoEnableBorder()) { |
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 think this should probably either short-circuit with s.shouldAutoEnableBorder
or continue to have false
as the second arg here. I don't think this function call is necessary unless I'm missing something 🤔
e.g.
if !s.shouldAutoEnableBorder() || !s.getAsBool(borderTopKey, false)
Although, again not sure this check saves us in efficiency
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.
If it's to account for the border value set in BorderStyle
, wouldn't that be handled already at line 306?
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.
The double negative !a || !b
style is confusing (and I think it should actually be &&
not ||
). However I think if we invert the if
condition it will be easier to follow:
if s.shouldAutoEnableBorder() || s.getAsBool(borderTopKey, false) {
return s.getBorderStyle().GetTopSize()
}
return 0
It breaks the Go idiom of putting the happy path return at the bottom, but I think the improvement in clarity is worth it.
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.
If it's to account for the border value set in
BorderStyle
, wouldn't that be handled already at line 306?
That would ignore the show/hide border flags set on the style, e.g. under borderTopKey
, which would be a regression I believe. At the very least it would change the behavior of many existing programs which users could rightfully consider a regression.
Also related: (and might eliminate the need for multiple checks of I tried adding a custom border in the test introduced here and it's not fixed by this PR (doesn't work on Here's the failing test case in case you're curious: {
name: "Custom BorderStyle",
style: NewStyle().BorderStyle(Border{Left: " new"}),
wantX: Width(" new"),
wantY: 0,
}, |
Based on my read of
So I think |
Return non-zero border sizes when border style is set, and no border sides have been specifically turned on or off. Fixes: charmbracelet#281
4a09ade
to
f95414f
Compare
@bashbunni @meowgorithm I've pushed additional changes based on your comments. |
Thanks for your patience and effort with this one, @qualidafial. It occurred to me (and @bashbunni): is this basically the same issue as #411? If so we can probably go with this one, but bring in the getters on my branch. |
I like the |
Return non-zero border sizes when border style is set, and no border sides have been specifically turned on or off.
Fixes: #281