Is it possible to change the title color in python rich panel? I have tried several ways, and I have not succeeded.
This is my code:
from rich.console import Console
from rich.markdown import Markdown
from rich.panel import Panel
import configuracion
from rich import print
def imprime_comandos (comandos: list, consola: Console, ancho_panel: int) -> None:
formato_comandos = '\n\n'.join([f""" `{c}`""" for c in comandos])
salida_cmd = Markdown(
formato_comandos,
inline_code_lexer = 'bash',
)
consola.print (
Panel(
salida_cmd,
title = "[red]Comando/s[/red]",
title_align = 'left',
width = ancho_panel,
)
)
def imprime_extras (extras: list, consola: Console, ancho_panel: int) -> None:
formato_extra = '\n'.join([f"""* {ex}""" for ex in extras])
salida_extras = Markdown(formato_extra)
salida_extras_str = str(salida_extras)
salida_extras_str = re.sub(r"|", "", salida_extras_str)
consola.print (
Panel(
salida_extras,
title = '[red]Ten en cuenta...[/red]',
title_align = 'left',
width = ancho_panel,
)
)
I was hoping to print the title in red color
In your function definition, the assignment of
consola: Consoleis not correct.I made an excerpt from your code, to show how this works. Either:
Or:
In the second example, there will be an AttributeError if you just code
console = Consolewithout the paranthesis.