mirror of
https://github.com/onyx-and-iris/slobs-cli.git
synced 2025-06-27 15:20:24 +01:00
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:
parent
10cb9777fa
commit
d8622ab037
@ -1,3 +1,3 @@
|
|||||||
"""module for package metadata."""
|
"""module for package metadata."""
|
||||||
|
|
||||||
__version__ = '0.11.0'
|
__version__ = '0.11.1'
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
"""module for console output handling."""
|
"""module for console output handling."""
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
import asyncclick as click
|
import asyncclick as click
|
||||||
from rich.console import Console
|
from rich.console import Console
|
||||||
|
|
||||||
out = 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:
|
def highlight(ctx: click.Context, text: str) -> str:
|
||||||
"""Highlight text for console output."""
|
"""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}]'
|
return f'[{ctx.obj["style"].highlight}]{text}[/{ctx.obj["style"].highlight}]'
|
||||||
|
|
||||||
|
|
||||||
def warning(ctx: click.Context, text: str) -> str:
|
def warning(ctx: click.Context, text: str) -> str:
|
||||||
"""Format warning text for console output."""
|
"""Format warning text for console output."""
|
||||||
if ctx.obj['style'].name == 'no_colour':
|
return f'[{ctx.obj["style"].warning}]{text}[/{ctx.obj["style"].warning}]'
|
||||||
return text
|
|
||||||
return f'[magenta]{text}[/magenta]'
|
|
||||||
|
@ -20,10 +20,11 @@ class Style:
|
|||||||
"""Base class for styles."""
|
"""Base class for styles."""
|
||||||
|
|
||||||
name: str = 'no_colour'
|
name: str = 'no_colour'
|
||||||
border: str | None = None
|
border: str = 'none'
|
||||||
header: str | None = None
|
header: str = 'none'
|
||||||
cell: str | None = None
|
cell: str = 'none'
|
||||||
highlight: str | None = None
|
highlight: str = 'none'
|
||||||
|
warning: str = 'none'
|
||||||
no_border: bool = False
|
no_border: bool = False
|
||||||
|
|
||||||
def __post_init__(self):
|
def __post_init__(self):
|
||||||
@ -43,6 +44,7 @@ class Red(Style):
|
|||||||
border: str = 'dark_red'
|
border: str = 'dark_red'
|
||||||
cell: str = 'red'
|
cell: str = 'red'
|
||||||
highlight: str = 'red3'
|
highlight: str = 'red3'
|
||||||
|
warning: str = 'magenta'
|
||||||
|
|
||||||
|
|
||||||
@register_style
|
@register_style
|
||||||
@ -55,6 +57,7 @@ class Magenta(Style):
|
|||||||
border: str = 'dark_magenta'
|
border: str = 'dark_magenta'
|
||||||
cell: str = 'magenta'
|
cell: str = 'magenta'
|
||||||
highlight: str = 'magenta3'
|
highlight: str = 'magenta3'
|
||||||
|
warning: str = 'magenta'
|
||||||
|
|
||||||
|
|
||||||
@register_style
|
@register_style
|
||||||
@ -67,6 +70,7 @@ class Purple(Style):
|
|||||||
border: str = 'purple'
|
border: str = 'purple'
|
||||||
cell: str = 'medium_orchid'
|
cell: str = 'medium_orchid'
|
||||||
highlight: str = 'medium_orchid'
|
highlight: str = 'medium_orchid'
|
||||||
|
warning: str = 'magenta'
|
||||||
|
|
||||||
|
|
||||||
@register_style
|
@register_style
|
||||||
@ -79,6 +83,7 @@ class Blue(Style):
|
|||||||
border: str = 'dark_blue'
|
border: str = 'dark_blue'
|
||||||
cell: str = 'blue'
|
cell: str = 'blue'
|
||||||
highlight: str = 'blue3'
|
highlight: str = 'blue3'
|
||||||
|
warning: str = 'magenta'
|
||||||
|
|
||||||
|
|
||||||
@register_style
|
@register_style
|
||||||
@ -91,6 +96,7 @@ class Cyan(Style):
|
|||||||
border: str = 'dark_cyan'
|
border: str = 'dark_cyan'
|
||||||
cell: str = 'cyan'
|
cell: str = 'cyan'
|
||||||
highlight: str = 'cyan3'
|
highlight: str = 'cyan3'
|
||||||
|
warning: str = 'magenta'
|
||||||
|
|
||||||
|
|
||||||
@register_style
|
@register_style
|
||||||
@ -103,6 +109,7 @@ class Green(Style):
|
|||||||
border: str = 'dark_green'
|
border: str = 'dark_green'
|
||||||
cell: str = 'green'
|
cell: str = 'green'
|
||||||
highlight: str = 'green3'
|
highlight: str = 'green3'
|
||||||
|
warning: str = 'magenta'
|
||||||
|
|
||||||
|
|
||||||
@register_style
|
@register_style
|
||||||
@ -115,6 +122,7 @@ class Yellow(Style):
|
|||||||
border: str = 'yellow3'
|
border: str = 'yellow3'
|
||||||
cell: str = 'wheat1'
|
cell: str = 'wheat1'
|
||||||
highlight: str = 'yellow3'
|
highlight: str = 'yellow3'
|
||||||
|
warning: str = 'magenta'
|
||||||
|
|
||||||
|
|
||||||
@register_style
|
@register_style
|
||||||
@ -127,6 +135,7 @@ class Orange(Style):
|
|||||||
border: str = 'dark_orange'
|
border: str = 'dark_orange'
|
||||||
cell: str = 'orange'
|
cell: str = 'orange'
|
||||||
highlight: str = 'orange3'
|
highlight: str = 'orange3'
|
||||||
|
warning: str = 'magenta'
|
||||||
|
|
||||||
|
|
||||||
@register_style
|
@register_style
|
||||||
@ -139,6 +148,7 @@ class White(Style):
|
|||||||
border: str = 'white'
|
border: str = 'white'
|
||||||
cell: str = 'white'
|
cell: str = 'white'
|
||||||
highlight: str = 'white'
|
highlight: str = 'white'
|
||||||
|
warning: str = 'magenta'
|
||||||
|
|
||||||
|
|
||||||
@register_style
|
@register_style
|
||||||
@ -151,6 +161,7 @@ class Grey(Style):
|
|||||||
border: str = 'grey50'
|
border: str = 'grey50'
|
||||||
cell: str = 'grey70'
|
cell: str = 'grey70'
|
||||||
highlight: str = 'grey90'
|
highlight: str = 'grey90'
|
||||||
|
warning: str = 'magenta'
|
||||||
|
|
||||||
|
|
||||||
@register_style
|
@register_style
|
||||||
@ -163,6 +174,7 @@ class Navy(Style):
|
|||||||
border: str = 'deep_sky_blue4'
|
border: str = 'deep_sky_blue4'
|
||||||
cell: str = 'light_sky_blue3'
|
cell: str = 'light_sky_blue3'
|
||||||
highlight: str = 'light_sky_blue3'
|
highlight: str = 'light_sky_blue3'
|
||||||
|
warning: str = 'magenta'
|
||||||
|
|
||||||
|
|
||||||
@register_style
|
@register_style
|
||||||
@ -175,6 +187,7 @@ class Black(Style):
|
|||||||
border: str = 'black'
|
border: str = 'black'
|
||||||
cell: str = 'grey30'
|
cell: str = 'grey30'
|
||||||
highlight: str = 'grey30'
|
highlight: str = 'grey30'
|
||||||
|
warning: str = 'magenta'
|
||||||
|
|
||||||
|
|
||||||
def request_style_obj(style_name: str, no_border: bool) -> Style:
|
def request_style_obj(style_name: str, no_border: bool) -> Style:
|
||||||
|
@ -10,6 +10,10 @@ def check_mark(ctx: click.Context, value: bool, empty_if_false: bool = False) ->
|
|||||||
if empty_if_false and not value:
|
if empty_if_false and not value:
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
if os.getenv('NO_COLOR', '') != '' or ctx.obj['style'].name == 'no_colour':
|
# rich gracefully handles the absence of colour throughout the rest of the application,
|
||||||
|
# but here we must handle it manually.
|
||||||
|
# If NO_COLOR is set, we return plain text symbols.
|
||||||
|
# Otherwise, we return coloured symbols.
|
||||||
|
if os.getenv('NO_COLOR', '') != '':
|
||||||
return '✓' if value else '✗'
|
return '✓' if value else '✗'
|
||||||
return '✅' if value else '❌'
|
return '✅' if value else '❌'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user