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

Option to truncate column headers #165

Open
OlafvdSpek opened this issue Feb 13, 2022 · 5 comments
Open

Option to truncate column headers #165

OlafvdSpek opened this issue Feb 13, 2022 · 5 comments

Comments

@OlafvdSpek
Copy link
Contributor

Sometimes column headers are (much) longer than the column data. An option to ignore the width of the header itself would be nice to have.

@hugovk
Copy link
Member

hugovk commented Feb 13, 2022

Please could you give some example input that causes this? And show the current output and what sort of thing you're after.

@OlafvdSpek
Copy link
Contributor Author

OlafvdSpek commented Feb 20, 2022

#!/usr/bin/python3
from prettytable import PrettyTable

t = PrettyTable()
t.field_names = ['A Field Name', 'B Field Name', 'D Field Name', 'E Field Name', 'F Field Name', 'G Field Name', 'H Field Name', 'I Field Name', 'J Field Name', 'K Field Name', 'L Field Name', 'M Field Name']
# t.field_names = ['A', 'B', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M']

t.add_row([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])
print(t)

# Current:
# +--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
# | A Field Name | B Field Name | D Field Name | E Field Name | F Field Name | G Field Name | H Field Name | I Field Name | J Field Name | K Field Name | L Field Name | M Field Name |
# +--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+
# |      0       |      1       |      2       |      3       |      4       |      5       |      6       |      7       |      8       |      9       |      10      |      11      |
# +--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+--------------+

# Desired:
# +---+---+---+---+---+---+---+---+---+---+----+----+
# | A | B | D | E | F | G | H | I | J | K | L  | M  |
# +---+---+---+---+---+---+---+---+---+---+----+----+
# | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
# +---+---+---+---+---+---+---+---+---+---+----+----+

@av-guy
Copy link
Contributor

av-guy commented Mar 7, 2022

@OlafvdSpek do you think it would be appropriate to add the option to truncate headers? Maybe something like
t.truncate_header['A Field Name'] = True?

@OlafvdSpek
Copy link
Contributor Author

Yes, but I'm not sure about the hardest part, the naming. use_header_widths, ignore_header_widths, something else?

@av-guy
Copy link
Contributor

av-guy commented Mar 7, 2022

@hugovk I can handle adding this feature. Do you have any input on what a good option name might be?

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

No branches or pull requests

3 participants