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

[ansi] Wrong width truncation due to missing Strip call on StringWidth #122

Closed
luevano opened this issue Jul 11, 2024 · 0 comments · Fixed by #125
Closed

[ansi] Wrong width truncation due to missing Strip call on StringWidth #122

luevano opened this issue Jul 11, 2024 · 0 comments · Fixed by #125

Comments

@luevano
Copy link

luevano commented Jul 11, 2024

Describe the bug
Some bubbles (viewport and list, as far as I noticed) render wrongly due to Truncate behavior which in turn is due to StringWidth.

I'm not familiar with how ansi actually works so I couldn't identify the bug; but by just doing s = Strip(s) at the top of StringWidth it behaves like before.

This appears to be introduced on lipgloss 0.11.1, specifically in x/ansi 0.1.3, specifically on this commit: fe84162 from PR #115

Setup

  • WSL arch linux (5.15.153.1-microsoft-standard-WSL2)
  • bash
  • Windows Terminal
  • tmux

Output of locale:

LANG=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

To Reproduce
Steps to reproduce the behavior:

  1. Render a viewport/list
  2. Sometimes the width is more than the screen and lines overflow to the next one

Source Code
Sorry, I don't have a minimal code to reproduce. But it can be seen in the app I'm working on: mangal@dev. After loading, hitting ctrl+l to open the "logs" the viewport will be messed up.

Expected behavior
The lines should be truncated to the correct width.

Screenshots
On lipgloss 0.11.0 (or by Striping in StringWidth):
viewport:
image
list:
image

On lipgloss 0.11.1 (or without Striping in StringWidth):
viewport:
image
list (some lines get shifted down and stay "burned" throughout other views):
image

Additional context
Also seems like it is only off by 1, if I substract -1 to maxWidth in lipgloss.Render it also behaves like before.

@luevano luevano changed the title [ansi] Missing Strip call on StringWidth [ansi] Wrong width truncation due to missing Strip call on StringWidth Jul 12, 2024
aymanbagabas added a commit that referenced this issue Jul 12, 2024
We need to reset the grapheme state after encountering a non-printable
character or when we're not using uniseg for string width (ASCII
printables have a width of 1 cell).

Fixes: #122
Fixes: #123
Fixes: charmbracelet/lipgloss#332
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.

1 participant