-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgen_screenshots.py
More file actions
131 lines (105 loc) · 3.98 KB
/
Copy pathgen_screenshots.py
File metadata and controls
131 lines (105 loc) · 3.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
"""Generate terminal-style screenshots using rich Console SVG export."""
import subprocess
import sys
from pathlib import Path
from rich.console import Console
from rich.text import Text
from rich.terminal_theme import DIMMED_MONOKAI
DIR = Path(__file__).parent / "screenshots"
DIR.mkdir(exist_ok=True)
URL = "ascii-banner.com"
def run(*args: str) -> str:
r = subprocess.run(
[sys.executable, "-m", "ascii_banner", *args],
capture_output=True, text=True,
)
return r.stdout.rstrip("\n")
def _footer(console: Console) -> None:
console.print()
console.print(Text(URL, style="dim"))
def save_svg(content: str, filename: str, title: str = "ascii-banner", width: int = 100) -> None:
console = Console(file=None, record=True, width=width, force_terminal=True)
console.print(Text.from_ansi(content))
_footer(console)
svg = console.export_svg(title=title, theme=DIMMED_MONOKAI)
(DIR / filename).write_text(svg)
print(f" {filename}")
def save_svg_with_cmd(cmd: str, args: list[str], filename: str, width: int = 100) -> None:
output = run(*args)
console = Console(file=None, record=True, width=width, force_terminal=True)
prompt = Text("$ ", style="green")
prompt.append(cmd, style="white")
console.print(prompt)
console.print()
console.print(Text.from_ansi(output))
_footer(console)
svg = console.export_svg(title="ascii-banner", theme=DIMMED_MONOKAI)
(DIR / filename).write_text(svg)
print(f" {filename}")
THEME = DIMMED_MONOKAI
def main() -> None:
print("Generating screenshots...\n")
# 1. Hero
save_svg_with_cmd(
'ascii-banner -f Slant "ASCII BANNER"',
["-f", "Slant", "ASCII BANNER"],
"hero.svg", width=80,
)
# 2. Fonts showcase
out1 = run("-f", "Doom", "Hello World")
out2 = run("-f", "Banner3", "-c", "#ff9900", "BITCOIN")
console = Console(file=None, record=True, width=80, force_terminal=True)
console.print(Text("$ ", style="green") + Text('ascii-banner -f Doom "Hello World"', style="white"))
console.print()
console.print(Text.from_ansi(out1))
console.print()
console.print(Text("$ ", style="green") + Text('ascii-banner -f Banner3 -c "#ff9900" "BITCOIN"', style="white"))
console.print()
console.print(Text.from_ansi(out2))
_footer(console)
(DIR / "fonts-showcase.svg").write_text(console.export_svg(title="ascii-banner", theme=THEME))
print(" fonts-showcase.svg")
# 3. Rainbow
save_svg_with_cmd(
'ascii-banner -c rainbow "Hello World"',
["-f", "standard", "-c", "rainbow", "Hello World"],
"rainbow.svg", width=60,
)
# 4. Border
save_svg_with_cmd(
'ascii-banner --border rounded "HACK THE PLANET"',
["--border", "rounded", "HACK THE PLANET"],
"border.svg", width=95,
)
# 5. Comment formatting
save_svg_with_cmd(
'ascii-banner --comment python -f small "CONFIG"',
["--comment", "python", "-f", "small", "CONFIG"],
"comment.svg", width=50,
)
# 6. Tag browsing (first 3 gothic fonts)
output = run("-t", "gothic", "-s", "md", "DOOM")
lines = output.split("\n")
trimmed, count = [], 0
for line in lines:
if line.startswith("── "):
count += 1
if count > 3:
break
trimmed.append(line)
console = Console(file=None, record=True, width=80, force_terminal=True)
console.print(Text("$ ", style="green") + Text('ascii-banner -t gothic -s md "DOOM"', style="white"))
console.print()
console.print(Text.from_ansi("\n".join(trimmed)))
_footer(console)
(DIR / "tags.svg").write_text(console.export_svg(title="ascii-banner", theme=THEME))
print(" tags.svg")
# 7. Gradient
save_svg_with_cmd(
'ascii-banner -c gradient:red:cyan "GRADIENT"',
["-f", "standard", "-c", "gradient:red:cyan", "GRADIENT"],
"gradient.svg", width=60,
)
print("\nDone! SVG files in screenshots/")
if __name__ == "__main__":
main()