Skip to content

create_theme_command

cli_command_create_theme(theme_name)

Source code in src/rendercv/cli/create_theme_command/create_theme_command.py
@app.command(
    name="create-theme",
    help=(
        "Create a custom theme folder with Typst templates to customize. Example:"
        " [yellow]rendercv create-theme customtheme[/yellow]. Details: [cyan]rendercv"
        " create-theme --help[/cyan]"
    ),
)
def cli_command_create_theme(
    theme_name: Annotated[
        str,
        typer.Argument(help="The name of the new theme"),
    ],
):
    new_theme_folder = pathlib.Path.cwd() / theme_name

    if new_theme_folder.exists():
        message = f'The theme folder "{theme_name}" already exists!'
        raise RenderCVUserError(message)

    copy_templates("typst", new_theme_folder)

    # Create the __init__.py file for the new theme:
    create_init_file_for_theme(theme_name, new_theme_folder / "__init__.py")

    # Build the panel
    message = textwrap.dedent(f"""
        [green]✓[/green] Created your custom theme: [purple]./{theme_name}[/purple]

        What you can do with this theme:
        1. Modify the Typst templates in [purple]./{theme_name}/
        2. Edit [purple]./{theme_name}/__init__.py[/purple] to:
            - Add your own design options to use in the YAML input file
            - Change the default values of existing options
            - Or simply delete it if you only want to customize templates

        To use your theme, set in your YAML input file:
        [cyan]  design:
        [cyan]    theme: {theme_name}
    """).strip("\n")

    print(
        rich.panel.Panel(
            message,
            title="Theme created",
            title_align="left",
            border_style="bright_black",
        )
    )