set default values for no_colour style to 'none'.

This fixes rich markup error

ensure errors are written without colour if NO_COLOR is set
This commit is contained in:
2025-06-22 10:49:05 +01:00
parent 10cb9777fa
commit d8622ab037
4 changed files with 29 additions and 12 deletions

View File

@@ -1,21 +1,21 @@
"""module for console output handling."""
import os
import asyncclick as click
from rich.console import Console
out = Console()
err = Console(stderr=True, style='bold red')
err = Console(
stderr=True, style='bold red' if os.getenv('NO_COLOR', '') != '' else 'none'
)
def highlight(ctx: click.Context, text: str) -> str:
"""Highlight text for console output."""
if ctx.obj['style'].name == 'no_colour':
return text
return f'[{ctx.obj["style"].highlight}]{text}[/{ctx.obj["style"].highlight}]'
def warning(ctx: click.Context, text: str) -> str:
"""Format warning text for console output."""
if ctx.obj['style'].name == 'no_colour':
return text
return f'[magenta]{text}[/magenta]'
return f'[{ctx.obj["style"].warning}]{text}[/{ctx.obj["style"].warning}]'