swiftly icon indicating copy to clipboard operation
swiftly copied to clipboard

Improve word wrapping of long lines

Open cmcgee1024 opened this issue 9 months ago • 4 comments

Swiftly has some long lines of text and currently relies on the shell to do the wrapping. Most shells do a bad job of wrapping at word boundaries, so words get chopped in the middle, which is not a great experience.

Instead, swiftly can use the same approach as the argument parser where it can attempt to detect the terminal width, and wrap lines around word boundaries. Here is the relevant code in the swift-argument-parser:

https://github.com/apple/swift-argument-parser/blob/d67151befa39533a6a449136c7992537cbf8ec99/Sources/ArgumentParser/Utilities/Platform.swift#L189 https://github.com/apple/swift-argument-parser/blob/d67151befa39533a6a449136c7992537cbf8ec99/Sources/ArgumentParser/Utilities/StringExtensions.swift#L13-L55

This shouldn't be a large change since it can be put into the SwiftlyCore.print() function that's used whenever output is being emitted.

cmcgee1024 avatar Mar 13 '25 16:03 cmcgee1024

There are some cases where the lines shouldn't be wrapped, such as command-lines. Also, there are some cases where the print is called with pre-wrapped lines for simple prose. These should rely on the new print functionality to wrap based on the terminal width.

cmcgee1024 avatar Mar 13 '25 16:03 cmcgee1024

Hi @cmcgee1024

Can I work on this?

roulpriya avatar Apr 19 '25 13:04 roulpriya

@roulpriya, yes, I've assigned this issue to you since I can see that you've got a PR ready for it.

cmcgee1024 avatar Apr 21 '25 10:04 cmcgee1024

Can you please review the PR?

roulpriya avatar Apr 21 '25 11:04 roulpriya

@roulpriya I think that this can be closed now since you've implemented the wrapping feature with the linked PR's.

cmcgee1024 avatar Jun 05 '25 17:06 cmcgee1024

Sure, we can close it.

roulpriya avatar Jun 06 '25 05:06 roulpriya