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

fix: border size getters when implicit borders are present #411

Merged
merged 5 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions borders.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,6 @@

func (s Style) applyBorder(str string) string {
var (
topSet = s.isSet(borderTopKey)
rightSet = s.isSet(borderRightKey)
bottomSet = s.isSet(borderBottomKey)
leftSet = s.isSet(borderLeftKey)

border = s.getBorderStyle()
hasTop = s.getAsBool(borderTopKey, false)
hasRight = s.getAsBool(borderRightKey, false)
Expand All @@ -252,7 +247,7 @@

// If a border is set and no sides have been specifically turned on or off
// render borders on all sides.
if border != noBorder && !(topSet || rightSet || bottomSet || leftSet) {
if s.implicitBorders() {
hasTop = true
hasRight = true
hasBottom = true
Expand All @@ -264,7 +259,7 @@
return str
}

lines, width := getLines(str)

Check failure on line 262 in borders.go

View workflow job for this annotation

GitHub Actions / build / govulncheck

undefined: getLines

if hasLeft {
if border.Left == "" {
Expand Down
25 changes: 21 additions & 4 deletions get.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@
// 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, false) && !s.implicitBorders() {
return 0
}
return s.getBorderStyle().GetTopSize()
Expand All @@ -310,7 +310,7 @@
// runes of varying widths, the widest rune is returned. If no border exists on
// the left edge, 0 is returned.
func (s Style) GetBorderLeftSize() int {
if !s.getAsBool(borderLeftKey, false) {
if !s.getAsBool(borderLeftKey, false) && !s.implicitBorders() {
return 0
}
return s.getBorderStyle().GetLeftSize()
Expand All @@ -320,7 +320,7 @@
// contain runes of varying widths, the widest rune is returned. If no border
// exists on the left edge, 0 is returned.
func (s Style) GetBorderBottomSize() int {
if !s.getAsBool(borderBottomKey, false) {
if !s.getAsBool(borderBottomKey, false) && !s.implicitBorders() {
return 0
}
return s.getBorderStyle().GetBottomSize()
Expand All @@ -330,7 +330,7 @@
// contain runes of varying widths, the widest rune is returned. If no border
// exists on the right edge, 0 is returned.
func (s Style) GetBorderRightSize() int {
if !s.getAsBool(borderRightKey, false) {
if !s.getAsBool(borderRightKey, false) && !s.implicitBorders() {
return 0
}
return s.getBorderStyle().GetRightSize()
Expand Down Expand Up @@ -411,7 +411,7 @@
// GetTransform returns the transform set on the style. If no transform is set
// nil is returned.
func (s Style) GetTransform() func(string) string {
return s.getAsTransform(transformKey)

Check failure on line 414 in get.go

View workflow job for this annotation

GitHub Actions / build / govulncheck

s.getAsTransform undefined (type Style has no field or method getAsTransform)
}

// Returns whether or not the given property is set.
Expand Down Expand Up @@ -519,6 +519,23 @@
return s.borderStyle
}

// Returns whether or not the style has implicit borders. This happens when
// a border style has been set but no border sides have been explicitly turned
// on or off.
func (s Style) implicitBorders() bool {
var (
borderStyle = s.getBorderStyle()
topSet = s.isSet(borderTopKey)
rightSet = s.isSet(borderRightKey)
bottomSet = s.isSet(borderBottomKey)
leftSet = s.isSet(borderLeftKey)
)
return borderStyle != noBorder && !(topSet || rightSet || bottomSet || leftSet)
return true
}
return false

Check failure on line 536 in get.go

View workflow job for this annotation

GitHub Actions / build / build (ubuntu-latest)

syntax error: non-declaration statement outside function body

Check failure on line 536 in get.go

View workflow job for this annotation

GitHub Actions / coverage (^1, ubuntu-latest)

syntax error: non-declaration statement outside function body

Check failure on line 536 in get.go

View workflow job for this annotation

GitHub Actions / coverage (^1, ubuntu-latest)

syntax error: non-declaration statement outside function body

Check failure on line 536 in get.go

View workflow job for this annotation

GitHub Actions / lint / lint-soft (ubuntu-latest)

expected declaration, found 'return' (typecheck)

Check failure on line 536 in get.go

View workflow job for this annotation

GitHub Actions / lint / lint (ubuntu-latest)

expected declaration, found 'return' (typecheck)

Check failure on line 536 in get.go

View workflow job for this annotation

GitHub Actions / lint / lint (ubuntu-latest)

expected declaration, found 'return' (typecheck)

Check failure on line 536 in get.go

View workflow job for this annotation

GitHub Actions / build / govulncheck

expected declaration, found 'return'

Check failure on line 536 in get.go

View workflow job for this annotation

GitHub Actions / lint / lint-soft (ubuntu-latest)

expected declaration, found 'return' (typecheck)

Check failure on line 536 in get.go

View workflow job for this annotation

GitHub Actions / lint / lint-soft (macos-latest)

expected declaration, found 'return' (typecheck)

Check failure on line 536 in get.go

View workflow job for this annotation

GitHub Actions / lint / lint-soft (macos-latest)

expected declaration, found 'return' (typecheck)
aymanbagabas marked this conversation as resolved.
Show resolved Hide resolved
}

func (s Style) getAsTransform(propKey) func(string) string {
if !s.isSet(transformKey) {
return nil
Expand Down
Loading