Skip to content

[BUG] help line length miscalculated when using stylized text #1159

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

Open
7 tasks done
zmeir opened this issue Feb 20, 2025 · 0 comments
Open
7 tasks done

[BUG] help line length miscalculated when using stylized text #1159

zmeir opened this issue Feb 20, 2025 · 0 comments

Comments

@zmeir
Copy link

zmeir commented Feb 20, 2025

Discussed in #1101

Originally posted by zmeir December 23, 2024

First Check

  • I added a very descriptive title here.
  • I used the GitHub search to find a similar question and didn't find it.
  • I searched the Typer documentation, with the integrated search.
  • I already searched in Google "How to X in Typer" and didn't find any information.
  • I already read and followed all the tutorials in the docs and didn't find an answer.
  • I already checked if it is not related to Typer but to Click.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

from typing import Annotated

import typer


app = typer.Typer()


@app.command()
def example(
    a: Annotated[str, typer.Option(help="This is A")],
    b: Annotated[str, typer.Option(help=f"This is {typer.style('B', underline=True)}")],
):
    pass


if __name__ == "__main__":
    app()

Description

When using typer.style in the help text of a command option, the rightmost | in the "frame" of the Options output is misaligned. This seems to be due to a miscalculation of the help line length, caused by the invisible style characters.

Using the example script - run python example.py --help and you should get this output:
image
(highlighted the misaligned part)

Operating System

macOS

Operating System Details

macOS version: 13.7.1 (22H221)

Typer Version

0.15.1

Python Version

3.10.13

Additional Context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant