feat: add hanging indent support for wrapped list items#481
feat: add hanging indent support for wrapped list items#481jy-tan wants to merge 6 commits intocharmbracelet:v2-expfrom
Conversation
|
This is really nice; thanks for the contribution. I haven't personally reviewed this one yet but it's something I'd very much like to see merged; noting down internally. |
|
@jy-tan Could you please change the base to make it against |
2e40dc9 to
2d560dc
Compare
aymanbagabas
left a comment
There was a problem hiding this comment.
We already provide ANSI aware wrapping logic for 7-bit and 8-bit sequences and UTF-8. We should probably use them instead of implementing a separate wrapping and parsing logic. Could you please explain the use case in details for consumeEscapeSequence and other wrapping functions?
https://github.com/charmbracelet/x/blob/main/ansi/wrap.go
https://github.com/charmbracelet/lipgloss/blob/v2-exp/wrap.go#L12
| } | ||
|
|
||
| // wrapListContent wraps list content with proper hanging indentation. | ||
| func wrapListContent(content string, wrapWidth int) string { |
There was a problem hiding this comment.
Why don't you use ANSI aware wrapping logic from charmbracelet/x/ansi and charmbracelet/lipgloss/v2?
ansi/list.go
Outdated
|
|
||
| // consumeEscapeSequence consumes an ANSI escape sequence starting at position i. | ||
| // Returns the position after the escape sequence. | ||
| func consumeEscapeSequence(ansiString string, i int) int { |
|
Ah wasn't aware of those existing utils. Modified to use them now, let me know if this works. |
There was a problem hiding this comment.
Hey @jy-tan, thank you again for taking the time to work on this. You still haven't answered my questions above 🙂
Honestly, I don't understand why we need to do multiple ansi.Strip and split logic around the list items. I believe you can achieve that easily without the complicated logic via lipgloss.Wrap(...) and ansi.StringWidth(...). Check out this example to do hanging indent via Lip Gloss main.go
Fixes issue #56 where list items that wrap to multiple lines did not have proper hanging indentation, causing continuation lines to align with the bullet/number instead of the text content.
Just taking a stab at this since I'd like to see this fixed, let me know if there's a better approach.
Before:
After:
The fix works by:
MarginWriter, which preserves the spacing