print scene list as rich table

This commit is contained in:
onyx-and-iris 2025-05-24 06:07:35 +01:00
parent 9cfbd67b25
commit b21ed78bfa

View File

@ -3,11 +3,15 @@
from typing import Annotated from typing import Annotated
import typer import typer
from rich.console import Console
from rich.table import Table
from . import validate from . import validate
from .alias import AliasGroup from .alias import AliasGroup
app = typer.Typer(cls=AliasGroup) app = typer.Typer(cls=AliasGroup)
out_console = Console()
err_console = Console(stderr=True)
@app.callback() @app.callback()
@ -19,8 +23,20 @@ def main():
def list(ctx: typer.Context): def list(ctx: typer.Context):
"""List all scenes.""" """List all scenes."""
resp = ctx.obj.get_scene_list() resp = ctx.obj.get_scene_list()
scenes = (scene.get('sceneName') for scene in reversed(resp.scenes)) scenes = (
typer.echo('\n'.join(scenes)) (scene.get('sceneIndex'), scene.get('sceneName'))
for scene in reversed(resp.scenes)
)
table = Table(title='Scenes')
table.add_column('Scene Name', justify='left', style='cyan')
for scene_index, scene_name in scenes:
table.add_row(
scene_name,
)
out_console.print(table)
@app.command('current | get') @app.command('current | get')
@ -32,15 +48,15 @@ def current(
): ):
"""Get the current program scene or preview scene.""" """Get the current program scene or preview scene."""
if preview and not validate.studio_mode_enabled(ctx): if preview and not validate.studio_mode_enabled(ctx):
typer.echo('Studio mode is not enabled, cannot get preview scene.', err=True) err_console.print('Studio mode is not enabled, cannot get preview scene.')
raise typer.Exit(1) raise typer.Exit(1)
if preview: if preview:
resp = ctx.obj.get_current_preview_scene() resp = ctx.obj.get_current_preview_scene()
typer.echo(resp.current_preview_scene_name) out_console.print(resp.current_preview_scene_name)
else: else:
resp = ctx.obj.get_current_program_scene() resp = ctx.obj.get_current_program_scene()
typer.echo(resp.current_program_scene_name) out_console.print(resp.current_program_scene_name)
@app.command('switch | set') @app.command('switch | set')
@ -54,18 +70,16 @@ def switch(
): ):
"""Switch to a scene.""" """Switch to a scene."""
if preview and not validate.studio_mode_enabled(ctx): if preview and not validate.studio_mode_enabled(ctx):
typer.echo( err_console.print('Studio mode is not enabled, cannot set the preview scene.')
'Studio mode is not enabled, cannot set the preview scene.', err=True
)
raise typer.Exit(1) raise typer.Exit(1)
if not validate.scene_in_scenes(ctx, scene_name): if not validate.scene_in_scenes(ctx, scene_name):
typer.echo(f"Scene '{scene_name}' not found.", err=True) err_console.print(f"Scene '{scene_name}' not found.")
raise typer.Exit(1) raise typer.Exit(1)
if preview: if preview:
ctx.obj.set_current_preview_scene(scene_name) ctx.obj.set_current_preview_scene(scene_name)
typer.echo(f'Switched to preview scene: {scene_name}') out_console.print(f'Switched to preview scene: {scene_name}')
else: else:
ctx.obj.set_current_program_scene(scene_name) ctx.obj.set_current_program_scene(scene_name)
typer.echo(f'Switched to program scene: {scene_name}') out_console.print(f'Switched to program scene: {scene_name}')