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

Allow output from commands to be wrapped to terminal width (fix #81) #201

Merged
merged 19 commits into from
Jul 29, 2023

Conversation

devdanzin
Copy link
Collaborator

Adds --wrap to commands, so output that is too wide for a given terminal width is wrapped inside the table cells.

Uses shutil.get_terminal_size() to get terminal size, then calculates an approximation of maximum column width and passes that as maxcolwidths and maxheadercolwidths parameters to tabulate.tabulate().

Adds some tests, but not exact output testing.

Fixes #81, except for very narrow terminals with lots of metrics.

@codecov-commenter
Copy link

codecov-commenter commented Jul 16, 2023

Codecov Report

Merging #201 (fd5511b) into master (b0411ae) will increase coverage by 0.09%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #201      +/-   ##
==========================================
+ Coverage   95.33%   95.42%   +0.09%     
==========================================
  Files          24       24              
  Lines        1244     1269      +25     
  Branches      279      287       +8     
==========================================
+ Hits         1186     1211      +25     
  Misses         33       33              
  Partials       25       25              
Files Changed Coverage Δ
src/wily/__main__.py 95.69% <100.00%> (+0.11%) ⬆️
src/wily/commands/diff.py 89.28% <100.00%> (+0.12%) ⬆️
src/wily/commands/index.py 100.00% <100.00%> (ø)
src/wily/commands/list_metrics.py 90.90% <100.00%> (+2.02%) ⬆️
src/wily/commands/rank.py 96.61% <100.00%> (+0.05%) ⬆️
src/wily/commands/report.py 97.22% <100.00%> (+0.05%) ⬆️
src/wily/helper/__init__.py 100.00% <100.00%> (ø)
@tonybaloney
Copy link
Owner

Please can you comment with some screenshots of what this looks like to confirm I'm seeing the same thing

@devdanzin
Copy link
Collaborator Author

Thanks for taking a look at this!

First, I'll show some good cases for most commands, then I'll use wily report to show how it works in different widths and how and when it breaks.

Rank:

wrap_rank_narrow_nowrap
wrap_rank_narrow_wrap

Diff:

wrap_diff_wide_nowrap
wrap_diff_wide_wrap

Index:

wrap_index_medium_nowrap
wrap_index_medium_wrap

List-metrics:

wrap_list_wide_nowrap
wrap_list_wide_wrap

Report wide, default metrics:

wrap_report_wide_nowrap
wrap_report_wide_wrap

Report very wide, default metrics:

Here we see that this PR isn't optimal about using available width: it doesn't actually need wrapping here.
wrap_report_verywide_nowrap
wrap_report_verywide_wrap

Report very wide, many metrics:

wrap_report_verywide_nowrap_manymetrics
wrap_report_verywide_wrap_manymetrics

How it sorta breaks:

When the terminal is narrow enough, table cells become vertical text one character wide. That might still be better than the otherwise overlapping output in some situation, but it does look silly.
wrap_report_medium_nowrap
wrap_report_medium_wrap

wrap_report_narrow_nowrap
wrap_report_narrow_wrap

How it breaks:

When the terminal is narrow enough, the code tries to output the vertical text as above, but fails and the result is harder to read than the previous overlapping output we'd get.
wrap_report_narrow_wrap_too_many_metrics

There's some more context at #81 (comment)

@click.option(
"-w",
"--wrap/--no-wrap",
default=False,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change to default=True

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reviewing! Changed here and in all other commands, was that the intention?

@tonybaloney
Copy link
Owner

Great, in that case please change the PR so this new behaviour is on by default. This looks much better

@devdanzin
Copy link
Collaborator Author

Tests aren't passing due to an issue I see no relation with this PR, but could be wrong. It's fixed by #203, and I could make the fix in this PR instead if that's cleaner.

@tonybaloney tonybaloney merged commit d501d01 into tonybaloney:master Jul 29, 2023
19 checks passed
@devdanzin devdanzin deleted the column_widths branch July 29, 2023 01:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants