tonybaloney / wily

A Python application for tracking, reporting on timing and complexity in Python code
Apache License 2.0
1.21k stars 59 forks source link

Fix wrapping of colored values #229

Open devdanzin opened 9 months ago

devdanzin commented 9 months ago

Sometimes tabulate will create broken wrapping tables by wrapping in the middle of ANSI escape codes. A fix has been proposed at the tabulate repository, but the project seems to be dormant at the moment.

This PR uses the code from the fix to monkeypatch tabulate._CustomTextWrap._handle_long_word in report() and diff(), so we don't have the bug. A test is included.

Before patch:

├────────────┼─────────────┼───────────┼────────────┼──────────────┼────────────┼───────────────┼────────────┤
│ dbe9172    │ Add unit    │ devdanzin │ 2023-09-24 │ 14.9615      │ 74 (0)     │ 78.5874 ( 3381 (+1)  │
│            │ tests for   │           │            │ (0.0)        │            │ 31m-0.00851   │            │
│            │ some        │           │            │              │            │ 093)          │            │
│            │ commands    │           │            │              │            │               │            │
│            │ (#199)  *   │           │            │              │            │               │            │
│            │ Add uni     │           │            │              │            │               │            │
├────────────┼─────────────┼───────────┼────────────┼──────────────┼────────────┼───────────────┼────────────┤
│ d0ad384    │ Add some    │ devdanzin │ 2023-09-22 │ 14.9615 ( 74 (-1)    │ 78.5959       │ 3380 (-15) │
│            │ more typing │           │            │ 32m-0.03846  │            │ (-0.306704)   │            │
│            │ (#221)  *   │           │            │ 15)          │            │               │            │
│            │ Update      │           │            │              │            │               │            │
│            │ typing info │           │            │              │            │               │            │
├────────────┼─────────────┼───────────┼────────────┼──────────────┼────────────┼───────────────┼────────────┤

broken_color_wrap

After patch:

├────────────┼─────────────┼───────────┼────────────┼──────────────┼────────────┼───────────────┼────────────┤
│ dbe9172    │ Add unit    │ devdanzin │ 2023-09-24 │ 14.9615      │ 74 (0)     │ 78.5874 (-0   │ 3381 (+1)  │
│            │ tests for   │           │            │ (0.0)        │            │ .00851093)    │            │
│            │ some        │           │            │              │            │               │            │
│            │ commands    │           │            │              │            │               │            │
│            │ (#199)  *   │           │            │              │            │               │            │
│            │ Add uni     │           │            │              │            │               │            │
├────────────┼─────────────┼───────────┼────────────┼──────────────┼────────────┼───────────────┼────────────┤
│ d0ad384    │ Add some    │ devdanzin │ 2023-09-22 │ 14.9615 (-0  │ 74 (-1)    │ 78.5959       │ 3380 (-15) │
│            │ more typing │           │            │ .0384615)    │            │ (-0.306704)   │            │
│            │ (#221)  *   │           │            │              │            │               │            │
│            │ Update      │           │            │              │            │               │            │
│            │ typing info │           │            │              │            │               │            │
├────────────┼─────────────┼───────────┼────────────┼──────────────┼────────────┼───────────────┼────────────┤

fixed_color_wrap

codecov-commenter commented 9 months ago

Codecov Report

Attention: Patch coverage is 76.47059% with 8 lines in your changes missing coverage. Please review.

Project coverage is 95.39%. Comparing base (2590691) to head (987f1b3).

Files with missing lines Patch % Lines
src/wily/helper/__init__.py 80.76% 3 Missing and 2 partials :warning:
src/wily/commands/diff.py 50.00% 1 Missing and 1 partial :warning:
src/wily/commands/report.py 75.00% 0 Missing and 1 partial :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #229 +/- ## ========================================== - Coverage 95.86% 95.39% -0.47% ========================================== Files 25 25 Lines 1403 1434 +31 Branches 296 305 +9 ========================================== + Hits 1345 1368 +23 - Misses 33 37 +4 - Partials 25 29 +4 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.