question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Markup and rich formatting in click.echo

See original GitHub issue

Is there any way to print rich-formatted types and text in the body of a command with click.echo?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ewelscommented, Jun 9, 2022

Oh I see! By body you just mean the output of the tool itself. This is kind of beyond the scope of rich-click as it’s no longer to do with the click command-line interface handling - it’s just the main content of your program. However I can see the confusion as you’re using a click utility function in your example (you could use this anywhere, with or without a command line interface).

Anyway, the easiest way to do this is to just use rich directly:

import rich_click as click
from rich import print

@click.command()
def cli():
    """A helpful CLI."""
    ...
    ... # doing stuff...
    ...

    print("[bold green]Success!![/]") 

Does this make sense? Hope this helps!

0reactions
ewelscommented, Jun 12, 2022

I think regular print() should work as well 🤔 See the basic example which does this.

Anyway, I’ll close now if you’re happy 😄 Shout if you run into any issues!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Utilities — Click Documentation (7.x)
The most obvious helper is the echo() function, which in many ways works like the Python print statement or function. The main difference...
Read more >
Printing and Colors - Typer - tiangolo
Rich also supports a custom markup syntax to set colors and styles, for example: ... typer.echo() (which is actually just click.echo() ) applies...
Read more >
Console Markup — Rich 12.6.0 documentation
Rich supports a simple markup which you can use to insert color and styles virtually everywhere Rich would accept a string (e.g. print()...
Read more >
Speech Synthesis Markup Language (SSML) Reference
SSML is a markup language that provides a standard way to mark up text for the generation of ... <speak> <amazon:domain name="long-form"> Meet...
Read more >
What Is the Command Line? Plain text vs. formatted text
Users with visual disabilities, click here to download the Word file. ... What is the difference between a plain text document and a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found