devstuff 1.13.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
dev_setup/ui.py ADDED
@@ -0,0 +1,111 @@
1
+ from __future__ import annotations
2
+
3
+ from collections.abc import Generator
4
+ from contextlib import contextmanager
5
+
6
+ import questionary
7
+ from questionary import Style as QStyle
8
+ from rich.console import Console
9
+ from rich.panel import Panel
10
+ from rich.rule import Rule
11
+ from rich.text import Text
12
+
13
+ console = Console(highlight=False)
14
+
15
+ _STYLE = QStyle([
16
+ ("qmark", "fg:#7C3AED bold"),
17
+ ("question", "bold"),
18
+ ("answer", "fg:#A78BFA bold"),
19
+ ("pointer", "fg:#7C3AED bold"),
20
+ ("highlighted", "fg:#A78BFA bold"),
21
+ ("selected", "fg:#A78BFA"),
22
+ ("separator", "fg:#6B7280"),
23
+ ("instruction", "fg:#6B7280 italic"),
24
+ ("check", "fg:#22C55E bold"),
25
+ ])
26
+
27
+
28
+ def info(msg: str) -> None:
29
+ console.print(f" [cyan bold]❯[/] {msg}")
30
+
31
+
32
+ def success(msg: str) -> None:
33
+ console.print(f" [green bold]✔[/] {msg}")
34
+
35
+
36
+ def warn(msg: str) -> None:
37
+ console.print(f" [yellow bold]⚠[/] {msg}")
38
+
39
+
40
+ def error(msg: str) -> None:
41
+ console.print(f" [red bold]✖[/] {msg}")
42
+
43
+
44
+ def dim(msg: str) -> None:
45
+ console.print(f" [dim]{msg}[/]")
46
+
47
+
48
+ def section(title: str) -> None:
49
+ console.print()
50
+ console.print(
51
+ Panel(f"[bold]{title}[/]", border_style="bright_magenta", expand=False, padding=(0, 1))
52
+ )
53
+ console.print()
54
+
55
+
56
+ def divider() -> None:
57
+ console.print(Rule(style="dim"))
58
+
59
+
60
+ def print_banner() -> None:
61
+ from dev_setup import __version__
62
+ t = Text()
63
+ t.append(" dev", style="bold bright_magenta")
64
+ t.append("-", style="dim")
65
+ t.append("setup", style="bold white")
66
+ t.append(f" v{__version__}", style="dim")
67
+ console.print()
68
+ console.print(Panel(t, border_style="bright_magenta", padding=(0, 2), expand=False))
69
+ console.print()
70
+
71
+
72
+ @contextmanager
73
+ def spinner(label: str) -> Generator[None, None, None]:
74
+ with console.status(f" [dim]{label}[/]", spinner="dots"):
75
+ yield
76
+
77
+
78
+ def confirm(prompt: str, default: bool = False) -> bool:
79
+ result = questionary.confirm(prompt, default=default, style=_STYLE).ask()
80
+ return bool(result)
81
+
82
+
83
+ def text_input(prompt: str, default: str = "", required: bool = False) -> str:
84
+ while True:
85
+ result = questionary.text(prompt, default=default, style=_STYLE).ask()
86
+ val = (result or "").strip()
87
+ if val or not required:
88
+ return val
89
+ error("This field is required.")
90
+
91
+
92
+ def select(prompt: str, choices: list[str]) -> str:
93
+ result = questionary.select(prompt, choices=choices, style=_STYLE).ask()
94
+ return result or ""
95
+
96
+
97
+ def checkbox(prompt: str, choices: list) -> list:
98
+ result = questionary.checkbox(prompt, choices=choices, style=_STYLE).ask()
99
+ return result or []
100
+
101
+
102
+ def code_block(code: str, language: str = "bash") -> None:
103
+ """Print a syntax-highlighted code panel."""
104
+ from rich.syntax import Syntax
105
+ console.print(
106
+ Panel(
107
+ Syntax(code, language, theme="monokai", line_numbers=False),
108
+ border_style="dim",
109
+ padding=(0, 1),
110
+ )
111
+ )