lipgloss icon indicating copy to clipboard operation
lipgloss copied to clipboard

style.Render() adds excess whitespaces on every line of the supplied text

Open TLINDEN opened this issue 3 months ago • 1 comments

Describe the bug I am using bubbles/viewport which shows text colored using lipgloss. Basically I colorize the text like this:

buf.WriteString(conf.Colors.Body.Render(content.Body))

buf is a strings.Builder, which I later put as content into the viewport widget.

The Problem is, that this appends excess whitespaces to every line except empty lines. Sample output:

Fabio Rossi ließ sie wieder auf die Bettdecke sinken und versuchte, dorthin zurückzukehren, wo er sich eben noch befunden hatte. An den Ort ohne Gefühle, Geräusche, Gedanken und Gerüche.                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                                                                                                                                                                                          

Hower, when I change the code to this:

buf.WriteString(content.Body)

no excess whitespaces appear.

What's interesting is that it looks as expected inside the viewport widget, so it seems to be intended. However, if I just print it to STDOUT, I can see the excess spaces.

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

  • OS Ubuntu 25.04
  • Shell bash
  • Terminal xfce-terminal
  • Terminal Multiplexer tmux
  • Locale en_US.UTF-8

To Reproduce Steps to reproduce the behavior: Snippet see above, feed in a large block of text, which contains lines wider than the terminal width. It doesn't happen, when all lines are smaller than the terminal.

Source Code

  • https://github.com/TLINDEN/epuppy
  • build
  • execute `./epuppy $epubfile -t | less

Expected behavior Do not append any excess spaces.

TLINDEN avatar Oct 16 '25 09:10 TLINDEN

I changed the xml parser and switched to xmlquery, which among other things, also fixed this issue. I don't really know how, since I believe it was not my code at fault. But since it's fixed for me, you might close this issue if you wish.

Thanks!

TLINDEN avatar Oct 17 '25 12:10 TLINDEN