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

"nonspacing mark" unicode causes container's width to shift #258

Closed
OnFireByte opened this issue Feb 8, 2024 · 2 comments · Fixed by #268
Closed

"nonspacing mark" unicode causes container's width to shift #258

OnFireByte opened this issue Feb 8, 2024 · 2 comments · Fixed by #268

Comments

@OnFireByte
Copy link

OnFireByte commented Feb 8, 2024

Describe the bug
Nonspacing mark unicodes are a type of character that doesn't consume space; instead, they "attach" themselves to the previous character. For example, "ี" or "ุ" are nonspacing marks commonly attached to another character like "ด," resulting in "ดี" or "ดุ."

When there are nonspacing mark unicodes inside lipgloss's container, the layout will shift on that line because lipgloss counts these characters as normal unicode that occupy 1 space.

Setup
Please complete the following information along with version numbers, if applicable.

  • macOS
  • zsh
  • iterm2
  • th_TH.UTF-8

To Reproduce
Steps to reproduce the behavior:

  1. Create a style with a fixed width, such as 16 characters.
  2. Render it with a string that has nonspacing mark unicodes, for example, "สวัสดี." ("ั" and "ี" are nonspacing marks)
  3. See the layout shift.

Source Code

package main

import (
	"fmt"

	"github.com/charmbracelet/lipgloss"
)

var box = lipgloss.NewStyle().Width(8).Height(8).Border(lipgloss.RoundedBorder())

func main() {
	fmt.Println(box.Render("สวัสดี"))
}

Screenshots
image

@mikelorant
Copy link
Contributor

This is a known issue that is pending these pull requests:

Without these being merged, the problem cannot be resolved. For context, this is due to incorrect rune width calculations not handling grapheme clusters (which obviously understand ZWJ).

@mikelorant
Copy link
Contributor

Confirmed this is fixed with the pull requests I have listed above:
CleanShot 2024-02-16 at 16 23 20

@OnFireByte OnFireByte reopened this Feb 16, 2024
aymanbagabas added a commit that referenced this issue Mar 14, 2024
Use ANSI aware, wide characters support, uniseg backed term/ansi package
to calculate string widths, truncate, and wrap strings.

Related: muesli/reflow#71
Fixes: #258
Fixes: #220
aymanbagabas added a commit that referenced this issue Mar 15, 2024
Use ANSI aware, wide characters support, uniseg backed term/ansi package
to calculate string widths, truncate, and wrap strings.

Related: muesli/reflow#71
Fixes: #258
Fixes: #220
aymanbagabas added a commit that referenced this issue Mar 17, 2024
Use ANSI aware, wide characters support, uniseg backed term/ansi package
to calculate string widths, truncate, and wrap strings.

Related: muesli/reflow#71
Fixes: #258
Fixes: #220
aymanbagabas added a commit that referenced this issue Mar 28, 2024
Use ANSI aware, wide characters support, uniseg backed term/ansi package
to calculate string widths, truncate, and wrap strings.

Related: muesli/reflow#71
Fixes: #258
Fixes: #220
aymanbagabas added a commit that referenced this issue Mar 28, 2024
Use ANSI aware, wide characters support, uniseg backed term/ansi package
to calculate string widths, truncate, and wrap strings.

Related: muesli/reflow#71
Fixes: #258
Fixes: #220
aymanbagabas added a commit that referenced this issue Mar 28, 2024
Use ANSI aware, wide characters support, uniseg backed term/ansi package
to calculate string widths, truncate, and wrap strings.

Related: muesli/reflow#71
Fixes: #258
Fixes: #220
aymanbagabas added a commit that referenced this issue Mar 28, 2024
Use ANSI aware, wide characters support, uniseg backed term/ansi package
to calculate string widths, truncate, and wrap strings.

Related: muesli/reflow#71
Fixes: #258
Fixes: #220
aymanbagabas added a commit that referenced this issue Mar 28, 2024
Use ANSI aware, wide characters support, uniseg backed term/ansi package
to calculate string widths, truncate, and wrap strings.

Related: muesli/reflow#71
Fixes: #258
Fixes: #220
aymanbagabas added a commit that referenced this issue Mar 29, 2024
* feat: switch to term/ansi for text manipulation

Use ANSI aware, wide characters support, uniseg backed term/ansi package
to calculate string widths, truncate, and wrap strings.

Related: muesli/reflow#71
Fixes: #258
Fixes: #220

* Update get.go
aymanbagabas added a commit that referenced this issue Mar 29, 2024
* feat: switch to term/ansi for text manipulation

Use ANSI aware, wide characters support, uniseg backed term/ansi package
to calculate string widths, truncate, and wrap strings.

Related: muesli/reflow#71
Fixes: #258
Fixes: #220

* fix: combining both conditional and unconditional wrapping

Uses `ansi.SmartWrap` charmbracelet/x#57

Fixes: muesli/reflow#43

* chore: update deps

* Update get.go
aymanbagabas added a commit that referenced this issue Apr 23, 2024
Use ANSI aware, wide characters support, uniseg backed term/ansi package
to calculate string widths, truncate, and wrap strings.

Related: muesli/reflow#71
Fixes: #258
Fixes: #220
aymanbagabas added a commit that referenced this issue Apr 29, 2024
Use ANSI aware, wide characters support, uniseg backed term/ansi package
to calculate string widths, truncate, and wrap strings.

Related: muesli/reflow#71
Fixes: #258
Fixes: #220
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants