mirror of
https://github.com/onyx-and-iris/obsws-cli.git
synced 2025-06-27 14:00:30 +01:00
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
This commit is contained in:
parent
4a0147aa8a
commit
922efddf7a
@ -1,4 +1,4 @@
|
||||
# SPDX-FileCopyrightText: 2025-present onyx-and-iris <code@onyxandiris.online>
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
__version__ = "0.18.0"
|
||||
__version__ = "0.18.1"
|
||||
|
@ -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}]'
|
||||
|
@ -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}'
|
||||
|
@ -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)
|
||||
|
@ -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'
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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 '❌'
|
||||
|
Loading…
x
Reference in New Issue
Block a user