From ddb92bb317594cac559276d29e0d463360c42386 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Fri, 6 Jun 2025 20:53:35 +0100 Subject: [PATCH] upd console colouring error messages now have style `bold red` error highlights are now yellow normal highlights are now green patch bump --- obsws_cli/__about__.py | 2 +- obsws_cli/app.py | 2 +- obsws_cli/filter.py | 36 +++++++++++++++++++++++++----------- obsws_cli/group.py | 36 ++++++++++++++++++++++-------------- obsws_cli/hotkey.py | 2 +- obsws_cli/input.py | 2 +- obsws_cli/profile.py | 18 ++++++++++-------- obsws_cli/projector.py | 26 ++++++++++++++++++-------- obsws_cli/record.py | 8 +++++--- obsws_cli/replaybuffer.py | 2 +- obsws_cli/scene.py | 8 ++++---- obsws_cli/scenecollection.py | 20 ++++++++++++++------ obsws_cli/screenshot.py | 8 +++++--- obsws_cli/stream.py | 2 +- obsws_cli/studiomode.py | 2 +- obsws_cli/virtualcam.py | 2 +- 16 files changed, 111 insertions(+), 65 deletions(-) diff --git a/obsws_cli/__about__.py b/obsws_cli/__about__.py index d78f92b..f14fd96 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.16.3" +__version__ = "0.16.4" diff --git a/obsws_cli/app.py b/obsws_cli/app.py index 3651fae..36b2b0c 100644 --- a/obsws_cli/app.py +++ b/obsws_cli/app.py @@ -34,7 +34,7 @@ for sub_typer in ( app.add_typer(module.app, name=sub_typer) out_console = Console() -err_console = Console(stderr=True) +err_console = Console(stderr=True, style='bold red') def version_callback(value: bool): diff --git a/obsws_cli/filter.py b/obsws_cli/filter.py index a4fa534..8ee8fd3 100644 --- a/obsws_cli/filter.py +++ b/obsws_cli/filter.py @@ -12,7 +12,7 @@ from .alias import AliasGroup app = typer.Typer(cls=AliasGroup) out_console = Console() -err_console = Console(stderr=True) +err_console = Console(stderr=True, style='bold red') @app.callback() @@ -39,13 +39,15 @@ def list_( resp = ctx.obj.get_source_filter_list(source_name) except obsws.error.OBSSDKRequestError as e: if e.code == 600: - err_console.print(f"No source was found by the name of '{source_name}'.") + err_console.print( + f'No source was found by the name of [yellow]{source_name}[/yellow].' + ) raise typer.Exit(1) else: raise if not resp.filters: - out_console.print(f'No filters found for source {source_name}') + out_console.print(f'No filters found for source [yellow]{source_name}[/yellow]') raise typer.Exit() table = Table(title=f'Filters for Source: {source_name}', padding=(0, 2)) @@ -101,12 +103,14 @@ def enable( """Enable a filter for a source.""" if _get_filter_enabled(ctx, source_name, filter_name): err_console.print( - f'Filter {filter_name} is already enabled for source {source_name}' + f'Filter [yellow]{filter_name}[/yellow] is already enabled for source [yellow]{source_name}[/yellow]' ) raise typer.Exit(1) ctx.obj.set_source_filter_enabled(source_name, filter_name, enabled=True) - out_console.print(f'Enabled filter {filter_name} for source {source_name}') + out_console.print( + f'Enabled filter [green]{filter_name}[/green] for source [green]{source_name}[/green]' + ) @app.command('disable | off') @@ -128,12 +132,14 @@ def disable( """Disable a filter for a source.""" if not _get_filter_enabled(ctx, source_name, filter_name): err_console.print( - f'Filter {filter_name} is already disabled for source {source_name}' + f'Filter [yellow]{filter_name}[/yellow] is already disabled for source [yellow]{source_name}[/yellow]' ) raise typer.Exit(1) ctx.obj.set_source_filter_enabled(source_name, filter_name, enabled=False) - out_console.print(f'Disabled filter {filter_name} for source {source_name}') + out_console.print( + f'Disabled filter [green]{filter_name}[/green] for source [green]{source_name}[/green]' + ) @app.command('toggle | tg') @@ -158,9 +164,13 @@ def toggle( ctx.obj.set_source_filter_enabled(source_name, filter_name, enabled=new_state) if new_state: - out_console.print(f'Enabled filter {filter_name} for source {source_name}') + out_console.print( + f'Enabled filter [green]{filter_name}[/green] for source [green]{source_name}[/green]' + ) else: - out_console.print(f'Disabled filter {filter_name} for source {source_name}') + out_console.print( + f'Disabled filter [green]{filter_name}[/green] for source [green]{source_name}[/green]' + ) @app.command('status | ss') @@ -182,6 +192,10 @@ def status( """Get the status of a filter for a source.""" is_enabled = _get_filter_enabled(ctx, source_name, filter_name) if is_enabled: - out_console.print(f'Filter {filter_name} is enabled for source {source_name}') + out_console.print( + f'Filter [green]{filter_name}[/green] is enabled for source [green]{source_name}[/green]' + ) else: - out_console.print(f'Filter {filter_name} is disabled for source {source_name}') + out_console.print( + f'Filter [green]{filter_name}[/green] is disabled for source [green]{source_name}[/green]' + ) diff --git a/obsws_cli/group.py b/obsws_cli/group.py index bb543f3..6541519 100644 --- a/obsws_cli/group.py +++ b/obsws_cli/group.py @@ -12,7 +12,7 @@ from .protocols import DataclassProtocol app = typer.Typer(cls=AliasGroup) out_console = Console() -err_console = Console(stderr=True) +err_console = Console(stderr=True, style='bold red') @app.callback() @@ -98,7 +98,9 @@ def show( resp = ctx.obj.get_scene_item_list(scene_name) if (group := _get_group(group_name, resp)) is None: - err_console.print(f"Group '{group_name}' not found in scene {scene_name}.") + err_console.print( + f'Group [yellow]{group_name}[/yellow] not found in scene [yellow]{scene_name}[/yellow].' + ) raise typer.Exit(1) ctx.obj.set_scene_item_enabled( @@ -107,7 +109,7 @@ def show( enabled=True, ) - out_console.print(f"Group '{group_name}' is now visible.") + out_console.print(f'Group [green]{group_name}[/green] is now visible.') @app.command('hide | h') @@ -122,12 +124,14 @@ def hide( ): """Hide a group in a scene.""" if not validate.scene_in_scenes(ctx, scene_name): - err_console.print(f"Scene '{scene_name}' not found.") + err_console.print(f'Scene [yellow]{scene_name}[/yellow] not found.') raise typer.Exit(1) resp = ctx.obj.get_scene_item_list(scene_name) if (group := _get_group(group_name, resp)) is None: - err_console.print(f"Group '{group_name}' not found in scene {scene_name}.") + err_console.print( + f'Group [yellow]{group_name}[/yellow] not found in scene [yellow]{scene_name}[/yellow].' + ) raise typer.Exit(1) ctx.obj.set_scene_item_enabled( @@ -136,7 +140,7 @@ def hide( enabled=False, ) - out_console.print(f"Group '{group_name}' is now hidden.") + out_console.print(f'Group [green]{group_name}[/green] is now hidden.') @app.command('toggle | tg') @@ -151,12 +155,14 @@ def toggle( ): """Toggle a group in a scene.""" if not validate.scene_in_scenes(ctx, scene_name): - err_console.print(f"Scene '{scene_name}' not found.") + err_console.print(f'Scene [yellow]{scene_name}[/yellow] not found.') raise typer.Exit(1) resp = ctx.obj.get_scene_item_list(scene_name) if (group := _get_group(group_name, resp)) is None: - err_console.print(f"Group '{group_name}' not found in scene {scene_name}.") + err_console.print( + f'Group [yellow]{group_name}[/yellow] not found in scene [yellow]{scene_name}[/yellow].' + ) raise typer.Exit(1) new_state = not group.get('sceneItemEnabled') @@ -167,9 +173,9 @@ def toggle( ) if new_state: - out_console.print(f"Group '{group_name}' is now visible.") + out_console.print(f'Group [green]{group_name}[/green] is now visible.') else: - out_console.print(f"Group '{group_name}' is now hidden.") + out_console.print(f'Group [green]{group_name}[/green] is now hidden.') @app.command('status | ss') @@ -184,12 +190,14 @@ def status( ): """Get the status of a group in a scene.""" if not validate.scene_in_scenes(ctx, scene_name): - err_console.print(f"Scene '{scene_name}' not found.") + err_console.print(f'Scene [yellow]{scene_name}[/yellow] not found.') raise typer.Exit(1) resp = ctx.obj.get_scene_item_list(scene_name) if (group := _get_group(group_name, resp)) is None: - err_console.print(f"Group '{group_name}' not found in scene {scene_name}.") + err_console.print( + f'Group [yellow]{group_name}[/yellow] not found in scene [yellow]{scene_name}[/yellow].' + ) raise typer.Exit(1) enabled = ctx.obj.get_scene_item_enabled( @@ -198,6 +206,6 @@ def status( ) if enabled.scene_item_enabled: - out_console.print(f"Group '{group_name}' is now visible.") + out_console.print(f'Group [green]{group_name}[/green] is now visible.') else: - out_console.print(f"Group '{group_name}' is now hidden.") + out_console.print(f'Group [green]{group_name}[/green] is now hidden.') diff --git a/obsws_cli/hotkey.py b/obsws_cli/hotkey.py index 4cfff78..4bf14c2 100644 --- a/obsws_cli/hotkey.py +++ b/obsws_cli/hotkey.py @@ -10,7 +10,7 @@ from .alias import AliasGroup app = typer.Typer(cls=AliasGroup) out_console = Console() -err_console = Console(stderr=True) +err_console = Console(stderr=True, style='bold red') @app.callback() diff --git a/obsws_cli/input.py b/obsws_cli/input.py index aa65426..9f06474 100644 --- a/obsws_cli/input.py +++ b/obsws_cli/input.py @@ -11,7 +11,7 @@ from .alias import AliasGroup app = typer.Typer(cls=AliasGroup) out_console = Console() -err_console = Console(stderr=True) +err_console = Console(stderr=True, style='bold red') @app.callback() diff --git a/obsws_cli/profile.py b/obsws_cli/profile.py index ffcc54c..59eabc2 100644 --- a/obsws_cli/profile.py +++ b/obsws_cli/profile.py @@ -11,7 +11,7 @@ from .alias import AliasGroup app = typer.Typer(cls=AliasGroup) out_console = Console() -err_console = Console(stderr=True) +err_console = Console(stderr=True, style='bold red') @app.callback() @@ -60,16 +60,18 @@ def switch( ): """Switch to a profile.""" if not validate.profile_exists(ctx, profile_name): - err_console.print(f"Profile '{profile_name}' not found.") + err_console.print(f'Profile [yellow]{profile_name}[/yellow] not found.') raise typer.Exit(1) resp = ctx.obj.get_profile_list() if resp.current_profile_name == profile_name: - err_console.print(f"Profile '{profile_name}' is already the current profile.") + err_console.print( + f'Profile [yellow]{profile_name}[/yellow] is already the current profile.' + ) raise typer.Exit(1) ctx.obj.set_current_profile(profile_name) - out_console.print(f"Switched to profile '{profile_name}'.") + out_console.print(f'Switched to profile [green]{profile_name}[/green].') @app.command('create | new') @@ -82,11 +84,11 @@ def create( ): """Create a new profile.""" if validate.profile_exists(ctx, profile_name): - err_console.print(f"Profile '{profile_name}' already exists.") + err_console.print(f'Profile [yellow]{profile_name}[/yellow] already exists.') raise typer.Exit(1) ctx.obj.create_profile(profile_name) - out_console.print(f"Created profile '{profile_name}'.") + out_console.print(f'Created profile [green]{profile_name}[/green].') @app.command('remove | rm') @@ -99,8 +101,8 @@ def remove( ): """Remove a profile.""" if not validate.profile_exists(ctx, profile_name): - err_console.print(f"Profile '{profile_name}' not found.") + err_console.print(f'Profile [yellow]{profile_name}[/yellow] not found.') raise typer.Exit(1) ctx.obj.remove_profile(profile_name) - out_console.print(f"Removed profile '{profile_name}'.") + out_console.print(f'Removed profile [green]{profile_name}[/green].') diff --git a/obsws_cli/projector.py b/obsws_cli/projector.py index 21c82d8..04c2d29 100644 --- a/obsws_cli/projector.py +++ b/obsws_cli/projector.py @@ -10,7 +10,7 @@ from .alias import AliasGroup app = typer.Typer(cls=AliasGroup) out_console = Console() -err_console = Console(stderr=True) +err_console = Console(stderr=True, style='bold red') @app.callback() @@ -61,11 +61,21 @@ def open( if not source_name: source_name = ctx.obj.get_current_program_scene().scene_name - ctx.obj.open_source_projector( - source_name=source_name, - monitor_index=monitor_index, - ) + monitors = ctx.obj.get_monitor_list().monitors + for monitor in monitors: + if monitor['monitorIndex'] == monitor_index: + ctx.obj.open_source_projector( + source_name=source_name, + monitor_index=monitor_index, + ) - out_console.print( - f'Opened projector for source [bold]{source_name}[/] on monitor [bold]{monitor_index}[/].' - ) + out_console.print( + f'Opened projector for source [green]{source_name}[/] on monitor [green]{monitor["monitorName"]}[/].' + ) + + break + else: + err_console.print( + f'Monitor with index [yellow]{monitor_index}[/yellow] not found.' + ) + raise typer.Exit(code=1) diff --git a/obsws_cli/record.py b/obsws_cli/record.py index a0e0737..337a436 100644 --- a/obsws_cli/record.py +++ b/obsws_cli/record.py @@ -10,7 +10,7 @@ from .alias import AliasGroup app = typer.Typer(cls=AliasGroup) out_console = Console() -err_console = Console(stderr=True) +err_console = Console(stderr=True, style='bold red') @app.callback() @@ -49,7 +49,9 @@ def stop(ctx: typer.Context): raise typer.Exit(1) resp = ctx.obj.stop_record() - out_console.print(f'Recording stopped successfully. Saved to: {resp.output_path}') + out_console.print( + f'Recording stopped successfully. Saved to: [green]{resp.output_path}[/green]' + ) @app.command('toggle | tg') @@ -125,5 +127,5 @@ def directory( out_console.print(f'Recording directory updated to: {record_directory}') else: out_console.print( - f'Recording directory: {ctx.obj.get_record_directory().record_directory}' + f'Recording directory: [green]{ctx.obj.get_record_directory().record_directory}[/green]' ) diff --git a/obsws_cli/replaybuffer.py b/obsws_cli/replaybuffer.py index 8c37289..c9e4a24 100644 --- a/obsws_cli/replaybuffer.py +++ b/obsws_cli/replaybuffer.py @@ -7,7 +7,7 @@ from .alias import AliasGroup app = typer.Typer(cls=AliasGroup) out_console = Console() -err_console = Console(stderr=True) +err_console = Console(stderr=True, style='bold red') @app.callback() diff --git a/obsws_cli/scene.py b/obsws_cli/scene.py index 6d09eb7..0523b78 100644 --- a/obsws_cli/scene.py +++ b/obsws_cli/scene.py @@ -11,7 +11,7 @@ from .alias import AliasGroup app = typer.Typer(cls=AliasGroup) out_console = Console() -err_console = Console(stderr=True) +err_console = Console(stderr=True, style='bold red') @app.callback() @@ -78,12 +78,12 @@ def switch( raise typer.Exit(1) if not validate.scene_in_scenes(ctx, scene_name): - err_console.print(f"Scene '{scene_name}' not found.") + err_console.print(f'Scene [yellow]{scene_name}[/yellow] not found.') raise typer.Exit(1) if preview: ctx.obj.set_current_preview_scene(scene_name) - out_console.print(f'Switched to preview scene: {scene_name}') + out_console.print(f'Switched to preview scene: [green]{scene_name}[/green]') else: ctx.obj.set_current_program_scene(scene_name) - out_console.print(f'Switched to program scene: {scene_name}') + out_console.print(f'Switched to program scene: [green]{scene_name}[/green]') diff --git a/obsws_cli/scenecollection.py b/obsws_cli/scenecollection.py index 5d01303..5bba444 100644 --- a/obsws_cli/scenecollection.py +++ b/obsws_cli/scenecollection.py @@ -11,7 +11,7 @@ from .alias import AliasGroup app = typer.Typer(cls=AliasGroup) out_console = Console() -err_console = Console(stderr=True) +err_console = Console(stderr=True, style='bold red') @app.callback() @@ -49,7 +49,9 @@ def switch( ): """Switch to a scene collection.""" if not validate.scene_collection_in_scene_collections(ctx, scene_collection_name): - err_console.print(f"Scene collection '{scene_collection_name}' not found.") + err_console.print( + f'Scene collection [yellow]{scene_collection_name}[/yellow] not found.' + ) raise typer.Exit(1) current_scene_collection = ( @@ -57,12 +59,14 @@ def switch( ) if scene_collection_name == current_scene_collection: err_console.print( - f'Scene collection "{scene_collection_name}" is already active.' + f'Scene collection [yellow]{scene_collection_name}[/yellow] is already active.' ) raise typer.Exit(1) ctx.obj.set_current_scene_collection(scene_collection_name) - out_console.print(f"Switched to scene collection '{scene_collection_name}'") + out_console.print( + f'Switched to scene collection [green]{scene_collection_name}[/green].' + ) @app.command('create | new') @@ -74,8 +78,12 @@ def create( ): """Create a new scene collection.""" if validate.scene_collection_in_scene_collections(ctx, scene_collection_name): - err_console.print(f"Scene collection '{scene_collection_name}' already exists.") + err_console.print( + f'Scene collection [yellow]{scene_collection_name}[/yellow] already exists.' + ) raise typer.Exit(1) ctx.obj.create_scene_collection(scene_collection_name) - out_console.print(f'Created scene collection {scene_collection_name}') + out_console.print( + f'Created scene collection [green]{scene_collection_name}[/green].' + ) diff --git a/obsws_cli/screenshot.py b/obsws_cli/screenshot.py index 2d523d9..cec6ee0 100644 --- a/obsws_cli/screenshot.py +++ b/obsws_cli/screenshot.py @@ -79,14 +79,16 @@ def save( match e.code: case 403: err_console.print( - 'The image format (file extension) must be included in the file name ' + 'The [yellow]image format[/yellow] (file extension) must be included in the file name, ' "for example: '/path/to/screenshot.png'.", ) raise typer.Exit(1) case 600: - err_console.print(f"No source was found by the name of '{source_name}'") + err_console.print( + f'No source was found by the name of [yellow]{source_name}[/yellow]' + ) raise typer.Exit(1) case _: raise - out_console.print(f"Screenshot saved to [bold]'{output_path}'[/bold].") + out_console.print(f'Screenshot saved to [green]{output_path}[/green].') diff --git a/obsws_cli/stream.py b/obsws_cli/stream.py index 98b494c..9a39cd5 100644 --- a/obsws_cli/stream.py +++ b/obsws_cli/stream.py @@ -7,7 +7,7 @@ from .alias import AliasGroup app = typer.Typer(cls=AliasGroup) out_console = Console() -err_console = Console(stderr=True) +err_console = Console(stderr=True, style='bold red') @app.callback() diff --git a/obsws_cli/studiomode.py b/obsws_cli/studiomode.py index ada0adb..c3e1df1 100644 --- a/obsws_cli/studiomode.py +++ b/obsws_cli/studiomode.py @@ -7,7 +7,7 @@ from .alias import AliasGroup app = typer.Typer(cls=AliasGroup) out_console = Console() -err_console = Console(stderr=True) +err_console = Console(stderr=True, style='bold red') @app.callback() diff --git a/obsws_cli/virtualcam.py b/obsws_cli/virtualcam.py index b57f778..e911a2b 100644 --- a/obsws_cli/virtualcam.py +++ b/obsws_cli/virtualcam.py @@ -7,7 +7,7 @@ from .alias import AliasGroup app = typer.Typer(cls=AliasGroup) out_console = Console() -err_console = Console(stderr=True) +err_console = Console(stderr=True, style='bold red') @app.callback()