From 922efddf7a2b9750909551b93ddcfb5b3cf0ff75 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Sun, 22 Jun 2025 01:57:58 +0100 Subject: [PATCH] check if we're in colourless mode before passing back highlighted text. pass context to check_mark so we can do the same there. Fixes rich.errors.MarkupError --- obsws_cli/__about__.py | 2 +- obsws_cli/console.py | 2 ++ obsws_cli/filter.py | 2 +- obsws_cli/group.py | 2 +- obsws_cli/input.py | 2 +- obsws_cli/profile.py | 4 +++- obsws_cli/scene.py | 4 ++-- obsws_cli/sceneitem.py | 8 ++++---- obsws_cli/util.py | 6 +++--- 9 files changed, 18 insertions(+), 14 deletions(-) diff --git a/obsws_cli/__about__.py b/obsws_cli/__about__.py index c1f112d..774e75d 100644 --- a/obsws_cli/__about__.py +++ b/obsws_cli/__about__.py @@ -1,4 +1,4 @@ # SPDX-FileCopyrightText: 2025-present onyx-and-iris # # SPDX-License-Identifier: MIT -__version__ = "0.18.0" +__version__ = "0.18.1" diff --git a/obsws_cli/console.py b/obsws_cli/console.py index abaef64..efb15cb 100644 --- a/obsws_cli/console.py +++ b/obsws_cli/console.py @@ -9,4 +9,6 @@ err = Console(stderr=True, style='bold red') def highlight(ctx: typer.Context, text: str) -> str: """Highlight text using the current context's style.""" + if ctx.obj['style'].name == 'no_colour': + return text return f'[{ctx.obj["style"].highlight}]{text}[/{ctx.obj["style"].highlight}]' diff --git a/obsws_cli/filter.py b/obsws_cli/filter.py index 132c450..04890c0 100644 --- a/obsws_cli/filter.py +++ b/obsws_cli/filter.py @@ -72,7 +72,7 @@ def list_( table.add_row( filter['filterName'], util.snakecase_to_titlecase(filter['filterKind']), - util.check_mark(filter['filterEnabled']), + util.check_mark(ctx, filter['filterEnabled']), '\n'.join( [ f'{util.snakecase_to_titlecase(k):<20} {v:>10}' diff --git a/obsws_cli/group.py b/obsws_cli/group.py index 4fa9845..a4fcfc9 100644 --- a/obsws_cli/group.py +++ b/obsws_cli/group.py @@ -68,7 +68,7 @@ def list_( table.add_row( str(item_id), group_name, - util.check_mark(is_enabled), + util.check_mark(ctx, is_enabled), ) console.out.print(table) diff --git a/obsws_cli/input.py b/obsws_cli/input.py index 8adfcde..b981bcb 100644 --- a/obsws_cli/input.py +++ b/obsws_cli/input.py @@ -81,7 +81,7 @@ def list_( input_mark = '' try: input_muted = ctx.obj['obsws'].get_input_mute(name=input_name).input_muted - input_mark = util.check_mark(input_muted) + input_mark = util.check_mark(ctx, input_muted) except obsws.error.OBSSDKRequestError as e: if e.code == 604: # Input does not support audio input_mark = 'N/A' diff --git a/obsws_cli/profile.py b/obsws_cli/profile.py index 1a52d32..b6da065 100644 --- a/obsws_cli/profile.py +++ b/obsws_cli/profile.py @@ -35,7 +35,9 @@ def list_(ctx: typer.Context): for profile in resp.profiles: table.add_row( profile, - util.check_mark(profile == resp.current_profile_name, empty_if_false=True), + util.check_mark( + ctx, profile == resp.current_profile_name, empty_if_false=True + ), ) console.out.print(table) diff --git a/obsws_cli/scene.py b/obsws_cli/scene.py index d3101a6..30a16b9 100644 --- a/obsws_cli/scene.py +++ b/obsws_cli/scene.py @@ -50,13 +50,13 @@ def list_( if uuid: table.add_row( scene_name, - util.check_mark(scene_name == active_scene, empty_if_false=True), + util.check_mark(ctx, scene_name == active_scene, empty_if_false=True), scene_uuid, ) else: table.add_row( scene_name, - util.check_mark(scene_name == active_scene, empty_if_false=True), + util.check_mark(ctx, scene_name == active_scene, empty_if_false=True), ) console.out.print(table) diff --git a/obsws_cli/sceneitem.py b/obsws_cli/sceneitem.py index 9d68d21..22ed81c 100644 --- a/obsws_cli/sceneitem.py +++ b/obsws_cli/sceneitem.py @@ -107,7 +107,7 @@ def list_( str(group_item_id), group_item_name, item_name, - util.check_mark(is_enabled and group_item_enabled), + util.check_mark(ctx, is_enabled and group_item_enabled), group_item_source_uuid, ) else: @@ -115,7 +115,7 @@ def list_( str(group_item_id), group_item_name, item_name, - util.check_mark(is_enabled and group_item_enabled), + util.check_mark(ctx, is_enabled and group_item_enabled), ) else: if uuid: @@ -123,7 +123,7 @@ def list_( str(item_id), item_name, '', - util.check_mark(is_enabled), + util.check_mark(ctx, is_enabled), source_uuid, ) else: @@ -131,7 +131,7 @@ def list_( str(item_id), item_name, '', - util.check_mark(is_enabled), + util.check_mark(ctx, is_enabled), ) console.out.print(table) diff --git a/obsws_cli/util.py b/obsws_cli/util.py index 4d1553b..f95a99e 100644 --- a/obsws_cli/util.py +++ b/obsws_cli/util.py @@ -1,6 +1,6 @@ """module contains utility functions for the obsws_cli package.""" -import os +import typer def snakecase_to_titlecase(snake_str: str) -> str: @@ -8,11 +8,11 @@ def snakecase_to_titlecase(snake_str: str) -> str: return snake_str.replace('_', ' ').title() -def check_mark(value: bool, empty_if_false: bool = False) -> str: +def check_mark(ctx: typer.Context, value: bool, empty_if_false: bool = False) -> str: """Return a check mark or cross mark based on the boolean value.""" if empty_if_false and not value: return '' - if os.getenv('NO_COLOR', '') != '': + if ctx.obj['style'].name == 'no_colour': return '✓' if value else '✗' return '✅' if value else '❌'