[CLI] Auto-fit human tables to terminal width#4251
Conversation
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
hanouticelina
left a comment
There was a problem hiding this comment.
ok looks good to me ✔️ ready for review
…gingface_hub into cli-adaptive-table-width
Wauplin
left a comment
There was a problem hiding this comment.
Sorry more comments that I would have thought because it took me some time to understand the different subtleties. The main feedback is that I think now we do adaptative truncation we should be less opinionated (i.e less hardcoded stuff) than before
| if no_truncate: | ||
| return natural.copy() |
There was a problem hiding this comment.
Ok I see, the "let's truncate container values to arbitrary 35 cols" is useful when using --no-truncate so that we still truncate columns that might be extremely long (like a json dump^^). What do you think of instead of --no-truncate we allow users to do a --truncate 1000 for instance? (in which case we consider the terminal to be 1000 columns width). This way the user can set the value they want and we don't take decisions for them
and maybe still allow --no-truncate for "don't truncate at all, even if extremely long line" (or accept --truncate -1 but feels weird? 😕)
There was a problem hiding this comment.
in any case, I would move all the truncation logic inside _compute_column_caps (could be renamed _truncate_columns?). At the moment values are truncated before and inside the method
There was a problem hiding this comment.
in any case, I would move all the truncation logic inside _compute_column_caps (could be renamed _truncate_columns?). At the moment values are truncated before and inside the method
_truncate_columns now does width calc, shrinking and truncation.
Ok I see, the "let's truncate container values to arbitrary 35 cols" is useful when using --no-truncate so that we still truncate columns that might be extremely long (like a json dump^^). What do you think of instead of --no-truncate we allow users to do a --truncate 1000 for instance? (in which case we consider the terminal to be 1000 columns width). This way the user can set the value they want and we don't take decisions for them
yes why not, I'm okay with breaking --no-truncate. added this in my TODO (low prio imo), I will open a follow-up PR and discuss the flags semantics there if that's okay with you
Wauplin
left a comment
There was a problem hiding this comment.
Made another pass especially on the --no-truncate part
There was a problem hiding this comment.
| if is_truncated: | |
| self.hint("Use `--no-truncate` or `--format json` to display full values.") |
and then update the hints here
…gingface_hub into cli-adaptive-table-width
There was a problem hiding this comment.
Pinact found unpinned actions in this repo.
Auto-fixable, but outside this PR's diff (run pinact run locally and commit):
.github/workflows/model_card_consistency_reminder.yml:15—actions/checkout@v6→actions/checkout@de0fac2e45… # v6.0.2.github/workflows/python-prerelease.yml:34—actions/checkout@v6→actions/checkout@de0fac2e45… # v6.0.2.github/workflows/python-quality.yml:23—- actions/checkout@v6→- actions/checkout@de0fac2e45… # v6.0.2.github/workflows/python-quality.yml:25—actions/setup-python@v6→actions/setup-python@a309ff8b42… # v6.2.0.github/workflows/python-tests.yml:22—actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6→actions/setup-python@a309ff8b42… # v6.2.0.github/workflows/python-tests.yml:57—actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6→actions/setup-python@a309ff8b42… # v6.2.0.github/workflows/python-tests.yml:152—codecov/codecov-action@75cd11691c0faa626561e295848008c8a7dddffe # v5→codecov/codecov-action@75cd11691c… # v5.5.4.github/workflows/python-tests.yml:174—actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6→actions/setup-python@a309ff8b42… # v6.2.0.github/workflows/python-tests.yml:221—codecov/codecov-action@75cd11691c0faa626561e295848008c8a7dddffe # v5→codecov/codecov-action@75cd11691c… # v5.5.4.github/workflows/release.yml:293—- actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6→- actions/setup-python@a309ff8b42… # v6.2.0.github/workflows/release.yml:348—- actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6→- actions/setup-python@a309ff8b42… # v6.2.0.github/workflows/release.yml:435—- actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6→- actions/setup-python@a309ff8b42… # v6.2.0.github/workflows/release.yml:555—- actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6→- actions/setup-python@a309ff8b42… # v6.2.0.github/workflows/release.yml:690—- actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6→- actions/setup-python@a309ff8b42… # v6.2.0.github/workflows/release.yml:930—actions/create-github-app-token@fee1f7d63c2ff003460e3d139729b119787bc349 # v2→actions/create-github-app-token@fee1f7d63c… # v2.2.2.github/workflows/release.yml:1018—actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6→actions/setup-python@a309ff8b42… # v6.2.0.github/workflows/release.yml:1032—actions/create-github-app-token@fee1f7d63c2ff003460e3d139729b119787bc349 # v2→actions/create-github-app-token@fee1f7d63c… # v2.2.2.github/workflows/release.yml:1056—peter-evans/create-pull-request@22a9089034f40e5a961c8808d113e2c98fb63676 # v7→peter-evans/create-pull-request@22a9089034… # v7.0.11.github/workflows/release.yml:1109—actions/create-github-app-token@fee1f7d63c2ff003460e3d139729b119787bc349 # v2→actions/create-github-app-token@fee1f7d63c… # v2.2.2.github/workflows/style-bot-action.yml:47—actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8→actions/github-script@ed597411d8… # v8.0.0.github/workflows/style-bot-action.yml:77—actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8→actions/github-script@ed597411d8… # v8.0.0.github/workflows/style-bot-action.yml:122—actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8→actions/github-script@ed597411d8… # v8.0.0.github/workflows/style-bot-action.yml:140—actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8→actions/github-script@ed597411d8… # v8.0.0.github/workflows/style-bot-action.yml:184—actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6→actions/setup-python@a309ff8b42… # v6.2.0.github/workflows/style-bot-action.yml:260—actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8→actions/github-script@ed597411d8… # v8.0.0.github/workflows/style-bot-action.yml:303—actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8→actions/github-script@ed597411d8… # v8.0.0.github/workflows/style-bot-action.yml:369—actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8→actions/github-script@ed597411d8… # v8.0.0.github/workflows/sync-hf-cli-skill.yml:17—actions/checkout@v4→actions/checkout@34e114876b… # v4.3.1.github/workflows/sync-hf-cli-skill.yml:20—actions/setup-python@v5→actions/setup-python@a26af69be9… # v5.6.0.github/workflows/sync-hf-cli-skill.yml:46—actions/create-github-app-token@v2→actions/create-github-app-token@fee1f7d63c… # v2.2.2.github/workflows/sync-hf-cli-skill.yml:53—actions/checkout@v4→actions/checkout@34e114876b… # v4.3.1.github/workflows/sync-hf-cli-skill.yml:60—astral-sh/setup-uv@v7→astral-sh/setup-uv@37802adc94… # v7.6.0.github/workflows/sync-hf-cli-skill.yml:86—peter-evans/create-pull-request@v7→peter-evans/create-pull-request@22a9089034… # v7.0.11.github/workflows/build_repocard_examples.yaml:18—actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6→actions/setup-python@a309ff8b42… # v6.2.0.github/workflows/update-inference-types.yaml:22—actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6→actions/setup-python@a309ff8b42… # v6.2.0.github/workflows/update-inference-types.yaml:37—- actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6→- actions/setup-node@53b83947a5… # v6.3.0.github/workflows/update-inference-types.yaml:41—pnpm/action-setup@b906affcce14559ad1aafd4ab0e942779e9f58b1 # v4→pnpm/action-setup@b906affcce… # v4.3.0.github/workflows/update-inference-types.yaml:71—peter-evans/create-pull-request@c0f553fe549906ede9cf27b5156039d195d2ece0 # v8→peter-evans/create-pull-request@c0f553fe54… # v8.1.0
|
This PR has been shipped as part of the v1.17.0 release. |
Follow-up to #4229.
This PR replaces the hardcoded 35-char per-cell cap in human tables with a column-aware algorithm that uses the actual terminal width. non-tty keeps the legacy 35 char cap,
--no-truncatebypasses the adaptive logic entirely. with a narrow terminal, only the widest columns shrink, naturally narrow columns (dates, ints, headers) keep their natural width. for very narrow, columns shrink to a per-column floor (max(10, header_len)), table wraps slightly.Note
Medium Risk
Changes core CLI table rendering logic, which could subtly affect output formatting and truncation behavior across many commands (especially in narrow terminals or when piping output). Functionality is localized to display concerns with test coverage added for the new adaptive behavior.
Overview
Human-mode CLI tables now auto-fit the terminal width instead of truncating every cell at a fixed 35 characters.
This adds a column-aware truncation algorithm that computes per-column width caps from the detected terminal width, shrinks only the widest columns when needed, keeps the legacy fixed cap for non-TTY output, and leaves
--no-truncateas an override to bypass truncation. Documentation and tests were updated to describe and validate the adaptive shrinking behavior.Reviewed by Cursor Bugbot for commit ed2b809. Configure here.