Allows setting maximum column width --columns-width - #307
Conversation
jm66
commented
Oct 16, 2019
- If specified --columns-width or HASS_COL_WIDTH env var truncates column values
- Uses default const.COLUMNS_WIDTH_STR
- Fixes allow setting maximum column width (feature req) #253
| show_envvar=True, | ||
| help=( | ||
| 'Columns custom width. ' | ||
| 'If specified truncates column values (default: auto)' |
There was a problem hiding this comment.
default is None here, right ? ..and how do I actually specify that if I wanted to ?
There was a problem hiding this comment.
Was thinking something like this:
@click.option(
'--columns-width',
default=0,
type=click.INT,
envvar='HASS_COL_WIDTH',
show_default=True,
help=('Truncates column values (0: auto, -1: disable).'),
)
But I'm not pretty sure. Thoughts?
There was a problem hiding this comment.
I can't think of a better approach at the moment - implement it and update the PR and lets see.
| row.append(", ".join(map(str, val))) | ||
| result.append(row) | ||
|
|
||
| # Truncates data |
There was a problem hiding this comment.
its crude and it somewhat works but I feel we should be able to do better than requiring users to pass in a width setting to get this.
How about using something like shutil.get_terminal_size() to get width and calculate a default max_width based on columns/terminal_width with an option to ignore it ?
There was a problem hiding this comment.
then you could truly have a auto for column_width but should also have a -1 or max or something to have it just print everything as it does now.
There was a problem hiding this comment.
Thanks for the feedback. What about this:
terminal_size = shutil.get_terminal_size()
number_c = min([len(r) for r in result])
columns_width = int(terminal_size.columns / number_c)
There was a problem hiding this comment.
looks about right - update the PR and we'll see.
|
I like the idea - left some comments on how I think we can make it better and have a better auto default. |
| ('CHANGED', 'last_changed'), | ||
| ] | ||
| COLUMNS_SERVICES = [('DOMAIN', 'domain'), ("SERVICE", "domain.services[*]")] | ||
| COLUMNS_WIDTH_STR = "..." |
There was a problem hiding this comment.
Was considering to replace ... with the horizontal ellipsis \u2026. Thoughts?
There was a problem hiding this comment.
should be okey I think.
|
PR updated. Thank you. |
- If specified --columns-width or HASS_COL_WIDTH env var truncates column values - Uses default const.COLUMNS_WIDTH_STR - Fixes home-assistant-ecosystem#253
any other integer will be taken as fixed column width. Default value is -1: disable since truncating columns without user consent might be a little too much. 0: auto does a basic calculation based on the terminal size shutil.get_terminal_size() and the number of columns in the result.
dd4cbc9 to
b6b5dd2
Compare
|
I've rebased it to get the ci tests to hopefully pass! |
Codecov Report
@@ Coverage Diff @@
## dev #307 +/- ##
==========================================
- Coverage 75.25% 75.22% -0.04%
==========================================
Files 22 22
Lines 1560 1574 +14
==========================================
+ Hits 1174 1184 +10
- Misses 386 390 +4
Continue to review full report at Codecov.
|
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |