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!: Style's Width doesn't include border size #449

Open
bashbunni opened this issue Dec 2, 2024 · 0 comments · May be fixed by #451
Open

fix!: Style's Width doesn't include border size #449

bashbunni opened this issue Dec 2, 2024 · 0 comments · May be fixed by #451
Assignees
Labels
bug Something isn't working v2

Comments

@bashbunni
Copy link
Member

Describe the bug
When you set a Width on a style, that should encompass the entire styled block. Currently, it will not factor in the border size here, so if a border is set, the actual rendered width is off by 2. This also means that the wrapped text is off by 2 as well.

To Reproduce
Add this to styles_test.go (or any other test file in the repo)

func TestWidth(t *testing.T) {
	width, _, _ := term.GetSize(os.Stdout.Fd())
	content := "The Romans learned from the Greeks that quinces slowly cooked with honey would “set” when cool. The Apicius gives a recipe for preserving whole quinces, stems and leaves attached, in a bath of honey diluted with defrutum: Roman marmalade. Preserves of quince and lemon appear (along with rose, apple, plum and pear) in the Book of ceremonies of the Byzantine Emperor Constantine VII Porphyrogennetos."
	style := NewStyle().Padding(0, 2).Border(NormalBorder(), true)
	t.Log(width)
	t.Log(style.GetHorizontalFrameSize())
	contentWidth := width - style.GetHorizontalFrameSize()
	t.Log(contentWidth)
	rendered := style.Width(contentWidth).Render(content)
	t.Log(Width(rendered))
}

You'll see that contentWidth != Width(rendered)

Expected behavior
contentWidth and Width(rendered) should be the same

Notes
Should also check this is working for Height...

@bashbunni bashbunni added the bug Something isn't working label Dec 2, 2024
@bashbunni bashbunni self-assigned this Dec 2, 2024
@bashbunni bashbunni linked a pull request Dec 2, 2024 that will close this issue
@bashbunni bashbunni added the v2 label Dec 13, 2024
@bashbunni bashbunni changed the title Style's Width doesn't include border size fix!: Style's Width doesn't include border size Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working v2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant