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

Is max_width word-wrapping configurable? #258

Open
ajgringo619 opened this issue Sep 13, 2023 · 10 comments
Open

Is max_width word-wrapping configurable? #258

ajgringo619 opened this issue Sep 13, 2023 · 10 comments
Labels
enhancement New feature or request

Comments

@ajgringo619
Copy link

In my use-case, the column in question contains package names, which sometimes have hyphens or multiple hyphens. When I set a max_width on the column, some of the package names get split up:

| bluedevil breeze breeze-gtk eos-bash-shared glib2 kactivitymanagerd kde-cli-     |
| tools kde-gtk-config kdecoration kdeplasma-addons khotkeys kinfocenter kmenuedit | 
| kpipewire kscreen kscreenlocker ksystemstats kwallet-pam kwin layer-shell-qt     | 
| lib32-glib2 libarchive libkscreen libksysguard libwebp milou oxygen-sounds       | 
| plasma-desktop plasma-disks plasma-integration plasma-nm plasma-pa plasma-       | 
| workspace polkit-kde-agent powerdevil python-gobject qt5-webengine sddm-kcm      |
| sqlite systemsettings vivaldi                                                    |

Is there a way to exclude hyphenated words from being wrapped?

@hugovk
Copy link
Member

hugovk commented Sep 13, 2023

No, but it could be done by setting break_on_hyphens=False here:

line = textwrap.fill(line, width)

>>> import textwrap
>>> line = "bluedevil breeze breeze-gtk eos-bash-shared glib2 kactivitymanagerd kde-cli-tools"
>>> textwrap.fill(line, 40)
'bluedevil breeze breeze-gtk eos-bash-\nshared glib2 kactivitymanagerd kde-cli-\ntools'
>>> textwrap.fill(line, 40, break_on_hyphens=False)
'bluedevil breeze breeze-gtk\neos-bash-shared glib2 kactivitymanagerd\nkde-cli-tools'
>>>

Docs: https://docs.python.org/3/library/textwrap.html

Would you like to put a PR together to make it configurable?

Maybe the thing to do would have a dictionary that can be used to set all the other textwrap.fill parameters?

@ajgringo619
Copy link
Author

I've got the time, just not sure where to begin. Can you point me in the right direction? Never contributed directly to a Github project before.

@hugovk
Copy link
Member

hugovk commented Sep 13, 2023

Sure!

The high level is:

You start off by forking this repo, there's a Fork button on the main page: https://github.com/jazzband/prettytable

Then clone it to your computer, for example: git clone https://github.com/ajgringo619/PrettyTable

Docs: https://docs.github.com/en/get-started/quickstart/fork-a-repo

The comes the coding, add what's needed, with tests. You can test locally via tox, pip install -U tox, then tox -e py311 to test with Python 3.11 for example.

Also it's a good idea to enable GitHub Actions on your fork - https://github.com/ajgringo619/PrettyTable/actions - then it'll run the tests when you push.

When you're ready, you create a "pull request" to submit it back here. Then we can review it, update it, then merge.

Docs: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request

Feel free to ask more details about any of these steps!

@hugovk hugovk added the enhancement New feature or request label Sep 13, 2023
@ajgringo619
Copy link
Author

Thanks for the detailed info, although I'm sure I'mm be asking a lot more questions. First one: what's the oldest version of Python I should be testing on?

@hugovk
Copy link
Member

hugovk commented Sep 13, 2023

We follow the same as the upstream supported CPython versions, so Python 3.8.

You don't necessarily need to install all the versions though, because the CI will test 3.8-3.12 on Ubuntu, Windows and macOS.

@ajgringo619
Copy link
Author

I've already got versions 3.9 through 3.11 installed, so one more won't be a problem. Thanks again for all the info!

@anibal2j
Copy link

anibal2j commented Apr 1, 2024

Is this fix going to fix the fact that column headers should also wrap? I have column headers that are dynamic, and I need them to wrap - otherwise the table looks terrible. SHould I open a new issue for that?

@ajgringo619
Copy link
Author

Can't believe it's been 7 months since I had "time" to work on this; I deleted the fork as it was just sitting there collecting dust. If I can truly commit to this in the future, I will post again with actual progress.

@av-guy
Copy link
Contributor

av-guy commented Apr 21, 2024

@ajgringo619 I can take care of this one if you would like.

@ajgringo619
Copy link
Author

@ajgringo619 I can take care of this one if you would like.

Thanks a bunch. I'll be happy to test whatever you come up with.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants