|
3 | 3 | import shutil |
4 | 4 |
|
5 | 5 | import click |
| 6 | +import questionary |
6 | 7 | from rich.console import Console |
7 | 8 | from rich.panel import Panel |
8 | 9 | from rich.table import Table |
@@ -58,11 +59,47 @@ def _list(): |
58 | 59 |
|
59 | 60 |
|
60 | 61 | @click.command(name="create") |
61 | | -@click.option("--name", required=True, type=click.STRING, help="Dash应用项目模板名称") |
| 62 | +@click.option("--name", type=click.STRING, help="Dash应用项目模板名称") |
62 | 63 | @click.option("--path", type=click.STRING, default=".", help="项目生成目标路径") |
63 | 64 | def _create(name, path): |
64 | 65 | """生成指定Dash应用项目模板到指定目录""" |
65 | 66 |
|
| 67 | + custom_style = questionary.Style( |
| 68 | + [ |
| 69 | + ("qmark", "fg:#FFD700 bold"), |
| 70 | + ("question", "bold cyan"), |
| 71 | + ("answer", "bold green"), |
| 72 | + ("pointer", "fg:#FFD700 bold"), |
| 73 | + ("highlighted", "fg:#00FFFF bold"), |
| 74 | + ("selected", "fg:#00FF00 bold"), |
| 75 | + ("instruction", "fg:#888"), |
| 76 | + ] |
| 77 | + ) |
| 78 | + |
| 79 | + # 如果未指定模板名称,显示交互式选择菜单 |
| 80 | + if name is None: |
| 81 | + choices = [ |
| 82 | + questionary.Choice( |
| 83 | + title=[ |
| 84 | + ("class:highlighted", template_name), |
| 85 | + ("class:text", f" - {template_info['description']}"), |
| 86 | + ], |
| 87 | + value=template_name, |
| 88 | + ) |
| 89 | + for template_name, template_info in BUILTIN_TEMPLATES.items() |
| 90 | + ] |
| 91 | + |
| 92 | + name = questionary.select( |
| 93 | + "请选择要生成的Dash应用项目模板:", |
| 94 | + choices=choices, |
| 95 | + style=custom_style, |
| 96 | + instruction="(使用方向键选择,回车确认,Esc 取消)", |
| 97 | + ).ask() |
| 98 | + |
| 99 | + if name is None: |
| 100 | + console.print("\n[yellow bold]已取消项目生成[/yellow bold]\n") |
| 101 | + return |
| 102 | + |
66 | 103 | # 检查目标项目模板是否存在 |
67 | 104 | if name not in BUILTIN_TEMPLATES.keys(): |
68 | 105 | error_msg = ( |
@@ -104,6 +141,7 @@ def _create(name, path): |
104 | 141 |
|
105 | 142 | # 确认生成 |
106 | 143 | console.print() |
| 144 | + console.print("[dim](输入 y 确认,输入 n 取消,直接回车使用默认选项 Y)[/dim]") |
107 | 145 | if not click.confirm("确认生成项目?", default=True): |
108 | 146 | console.print("\n[yellow bold]已取消项目生成[/yellow bold]\n") |
109 | 147 | return |
|
0 commit comments