From 040a41daa776060c348031488d554e773af90cbd Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Mon, 14 Jul 2025 02:31:35 +0100 Subject: [PATCH] add text command group --- obsws_cli/alias.py | 2 ++ obsws_cli/app.py | 1 + obsws_cli/text.py | 78 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 obsws_cli/text.py diff --git a/obsws_cli/alias.py b/obsws_cli/alias.py index 6eefe85..359891d 100644 --- a/obsws_cli/alias.py +++ b/obsws_cli/alias.py @@ -44,6 +44,8 @@ class RootTyperAliasGroup(typer.core.TyperGroup): cmd_name = 'stream' case 'sm': cmd_name = 'studiomode' + case 't': + cmd_name = 'text' case 'vc': cmd_name = 'virtualcam' return super().get_command(ctx, cmd_name) diff --git a/obsws_cli/app.py b/obsws_cli/app.py index 8adfc99..0e68533 100644 --- a/obsws_cli/app.py +++ b/obsws_cli/app.py @@ -28,6 +28,7 @@ for sub_typer in ( 'screenshot', 'stream', 'studiomode', + 'text', 'virtualcam', ): module = importlib.import_module(f'.{sub_typer}', package=__package__) diff --git a/obsws_cli/text.py b/obsws_cli/text.py new file mode 100644 index 0000000..a6bd0f4 --- /dev/null +++ b/obsws_cli/text.py @@ -0,0 +1,78 @@ +"""module containing commands for manipulating text inputs.""" + +from typing import Annotated, Optional + +import typer + +from . import console, validate +from .alias import SubTyperAliasGroup + +app = typer.Typer(cls=SubTyperAliasGroup) + + +@app.callback() +def main(): + """Control text inputs in OBS.""" + + +@app.command('current | get') +def current( + ctx: typer.Context, + input_name: Annotated[str, typer.Argument(help='Name of the text input to get.')], +): + """Get the current text for a text input.""" + if not validate.input_in_inputs(ctx, input_name): + console.err.print(f'Input [yellow]{input_name}[/yellow] not found.') + raise typer.Exit(1) + + resp = ctx.obj['obsws'].get_input_settings(name=input_name) + if not resp.input_kind.startswith('text_'): + console.err.print( + f'Input [yellow]{input_name}[/yellow] is not a text input.', + ) + raise typer.Exit(1) + + current_text = resp.input_settings.get('text', '') + if not current_text: + current_text = '(empty)' + console.out.print( + f'Current text for input {console.highlight(ctx, input_name)}: {current_text}', + ) + + +@app.command('update | set') +def update( + ctx: typer.Context, + input_name: Annotated[ + str, typer.Argument(help='Name of the text input to update.') + ], + new_text: Annotated[ + Optional[str], + typer.Argument( + help='The new text to set for the input.', + ), + ] = None, +): + """Update the text of a text input.""" + if not validate.input_in_inputs(ctx, input_name): + console.err.print(f'Input [yellow]{input_name}[/yellow] not found.') + raise typer.Exit(1) + + resp = ctx.obj['obsws'].get_input_settings(name=input_name) + if not resp.input_kind.startswith('text_'): + console.err.print( + f'Input [yellow]{input_name}[/yellow] is not a text input.', + ) + raise typer.Exit(1) + + ctx.obj['obsws'].set_input_settings( + name=input_name, + settings={'text': new_text}, + overlay=True, + ) + + if not new_text: + new_text = '(empty)' + console.out.print( + f'Text for input {console.highlight(ctx, input_name)} updated to: {new_text}', + )