typer icon indicating copy to clipboard operation
typer copied to clipboard

๐Ÿ’„ Add option for panels to fit to content

Open harkabeeparolus opened this issue 1 year ago โ€ข 12 comments

Provide an option for using Rich Panel.fit() aka Panel(expand=False) for help panels and errors. This was mentioned in discussion #607 and #680. To opt into this new, non-default behavior, just use:

app = typer.Typer(rich_expand=False)

I think this can look nicer on very wide terminals, especially for CLIs with few parameters, or short parameter descriptions, so I would prefer to have the option to choose this style sometimes.

Status

  • The code worked fine on all the examples I tried from the Typer tutorial
  • The documentation I added is perhaps a little sparse.
    • I don't know yet how to capture command output for the Typer docs, and I think an example is needed. Help?
  • I'm not sure how to write tests for this. Suggestions are welcome!

Example

rich_expand_example

harkabeeparolus avatar Dec 20 '24 10:12 harkabeeparolus

๐Ÿ“ Docs preview for commit 1e1a25674a814abedc853398abbe91f538262088 at: https://a93b4aa2.typertiangolo.pages.dev

Modified Pages

  • https://a93b4aa2.typertiangolo.pages.dev/tutorial/commands/help/ - (before)

github-actions[bot] avatar Dec 20 '24 10:12 github-actions[bot]

๐Ÿ“ Docs preview for commit b97e79e74cd3a1b1518ac189d36b3a0a3435e7d0 at: https://52aba9d8.typertiangolo.pages.dev

Modified Pages

  • https://52aba9d8.typertiangolo.pages.dev/tutorial/commands/help/ - (before)

github-actions[bot] avatar Mar 25 '25 09:03 github-actions[bot]

Any chances to merge this PR soon? Can someone please restart CI?

mshonichev avatar Apr 08 '25 12:04 mshonichev

๐Ÿ“ Docs preview for commit 03860a51404c81fe6882c45306446cf943450aee at: https://7b0a9feb.typertiangolo.pages.dev

Modified Pages

  • https://7b0a9feb.typertiangolo.pages.dev/tutorial/commands/help/ - (before)

github-actions[bot] avatar Apr 08 '25 12:04 github-actions[bot]

Any chances to merge this PR soon?

I believe what's missing is test coverage for my new code and logic, which is not my strong suit. I would appreciate any help or suggestions on how to approach writing tests for this.

harkabeeparolus avatar Apr 09 '25 14:04 harkabeeparolus

This pull request has a merge conflict that needs to be resolved.

github-actions[bot] avatar Sep 01 '25 14:09 github-actions[bot]

๐Ÿ“ Docs preview

Last commit 82db16f7d4a177c9e6fc9ee5fa10cf8ae4a5f35c at: https://8ce4e47b.typertiangolo.pages.dev

Modified Pages

  • https://8ce4e47b.typertiangolo.pages.dev/tutorial/commands/help/ - (before)

github-actions[bot] avatar Nov 12 '25 07:11 github-actions[bot]

I updated the PR to remove merge conflicts, and:

  • Fixed a bug.
  • Added rich_expand to typer.run() for convenience. ๐Ÿ˜Š

Remaining issues:

  • I still need help with test coverage. ๐Ÿ˜ฌ I'm not familiar enough with the codebase to understand what's going on.
    • I have manually tested this code on many of the code samples in the Typer documentation, and some of my own code, with no issues so far.
    • As far as I can tell, the only failing CI tests right now are on 3.8 and 3.9, which are end of life. Should we address these? ๐Ÿคจ
  • I have updated the text of the documentation, but I haven't made any screenshots, because I don't know what procedure you use to make them consistent with the rest of the docs.

harkabeeparolus avatar Nov 12 '25 13:11 harkabeeparolus

the only failing CI tests right now are on 3.8 and 3.9, which are end of life. Should we address these?

Yes, of course, as long as the CI is running 3.8/3.9 tests, that means we're still officially supporting these versions of Python, even if they've become EOL. We'll likely drop them at some point in the near future, but nevertheless every PR should always pass the full test suite.

svlandeg avatar Nov 19 '25 10:11 svlandeg

@svlandeg thanks for your review and suggestions today! ๐Ÿ˜Š

I guess my remaining points are:

  • I don't really know how to write the tests to restore 100% coverage. I can try to figure it out.
  • I also don't know how to test that the new behavior with rich_expand=False actually works. ๐Ÿ˜‰
  • There's no screenshot for the docs. Do we need one? How are those normally generated in this project?

harkabeeparolus avatar Nov 19 '25 17:11 harkabeeparolus

Hi @harkabeeparolus, thanks for the status update! I'll try to look into these issues sometime in the next 10 days.

svlandeg avatar Nov 19 '25 18:11 svlandeg