jazzband / prettytable

Display tabular data in a visually appealing ASCII table format
https://pypi.org/project/PrettyTable/
Other
1.35k stars 154 forks source link

Widen tables with long titles #216

Closed etjones closed 1 year ago

etjones commented 1 year ago

Recalculated this to scale the table correctly.

Original behavior:


Without title:
+---------+---------+
| field a | field b |
+---------+---------+
|    a1   |    b1   |
|    a2   |    b2   |
+---------+---------+

With title:
+-----------------------------------------------------------------+
| === 80 char str ================================================================ |
+--------------------------------+--------------------------------+
|            field a             |            field b             |
+--------------------------------+--------------------------------+
|               a1               |               b1               |
|               a2               |               b2               |
+--------------------------------+--------------------------------+

New behavior:

With title:
+-----------------------------------------------------------------------------------+
|  === 80 char str ================================================================ |
+-----------------------------------------+-----------------------------------------+
|                 field a                 |                 field b                 |
+-----------------------------------------+-----------------------------------------+
|                    a1                   |                    b1                   |
|                    a2                   |                    b2                   |
+-----------------------------------------+-----------------------------------------+
codecov[bot] commented 1 year ago

Codecov Report

Merging #216 (bd7183d) into master (c73b7e3) will increase coverage by 0.14%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #216      +/-   ##
==========================================
+ Coverage   94.05%   94.19%   +0.14%     
==========================================
  Files           5        5              
  Lines        2254     2258       +4     
==========================================
+ Hits         2120     2127       +7     
+ Misses        134      131       -3     
Flag Coverage Δ
macos-latest 94.19% <100.00%> (+0.14%) :arrow_up:
ubuntu-latest 94.19% <100.00%> (+0.14%) :arrow_up:
windows-latest 94.06% <100.00%> (+0.14%) :arrow_up:

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/prettytable/prettytable.py 90.43% <100.00%> (+0.22%) :arrow_up:
tests/test_prettytable.py 100.00% <100.00%> (ø)

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

hugovk commented 1 year ago

Thank you!

kzwolenik95 commented 1 year ago

This change broke parameter min_table_width: I have suggested fix in #219

Traceback (most recent call last):
  File "=prettytable\hehe.py", line 22, in <module>
    print(x)
  File "prettytable\src\prettytable\prettytable.py", line 330, in __str__
    return self.get_string()
  File "prettytable\src\prettytable\prettytable.py", line 1715, in get_string
    self._compute_widths(formatted_rows, options)
  File "prettytable\src\prettytable\prettytable.py", line 1592, in _compute_widths
    scale = 1.0 * (len(options["title"]) - border_char_count) / sum(widths)
TypeError: object of type 'NoneType' has no len()