-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintro.py
More file actions
465 lines (392 loc) · 13.9 KB
/
Copy pathintro.py
File metadata and controls
465 lines (392 loc) · 13.9 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
"""
Intro animada estilo DedSec / Watch Dogs para EJ Tools.
Instalación:
pip install rich pyfiglet terminaltexteffects
Uso:
from intro import show_intro
show_intro("EJ TOOLS")
"""
from __future__ import annotations
import os
import random
import shutil
import sys
import time
from typing import Any
# ---------------------------------------------------------------------------
# Dependencias con fallback amable si faltan
# ---------------------------------------------------------------------------
_MISSING: list[str] = []
try:
from rich.align import Align
from rich.console import Console
from rich.live import Live
from rich.panel import Panel
from rich.text import Text
except ImportError: # pragma: no cover
_MISSING.append("rich")
Align = Console = Live = Panel = Text = None # type: ignore
try:
from pyfiglet import Figlet
except ImportError: # pragma: no cover
_MISSING.append("pyfiglet")
Figlet = None # type: ignore
try:
from terminaltexteffects.effects.effect_decrypt import Decrypt, DecryptConfig
from terminaltexteffects.effects.effect_unstable import Unstable, UnstableConfig
from terminaltexteffects.engine.terminal import TerminalConfig
from terminaltexteffects.utils.graphics import Color
except ImportError: # pragma: no cover
_MISSING.append("terminaltexteffects")
Decrypt = DecryptConfig = Unstable = UnstableConfig = TerminalConfig = Color = None # type: ignore
# Paleta neon DedSec
NEON_GREEN = "#00FF00"
NEON_CYAN = "#00FFFF"
NEON_MAGENTA = "#FF00FF"
NEON_DIM_GREEN = "#00CB00"
NEON_DARK_GREEN = "#008000"
# Fuentes pyfiglet a probar (en orden de preferencia)
_FIGLET_FONTS = ("doom", "slant", "cyberlarge", "big", "standard")
def _clear() -> None:
"""Limpia la pantalla de la terminal."""
os.system("cls" if os.name == "nt" else "clear")
def _term_size() -> tuple[int, int]:
"""Devuelve (columnas, filas) de la terminal con valores seguros."""
try:
size = shutil.get_terminal_size(fallback=(80, 24))
cols = max(40, size.columns)
rows = max(12, size.lines)
return cols, rows
except Exception:
return 80, 24
def _hide_cursor() -> None:
sys.stdout.write("\033[?25l")
sys.stdout.flush()
def _show_cursor() -> None:
sys.stdout.write("\033[?25h")
sys.stdout.flush()
def _center_block(text: str, width: int | None = None) -> str:
"""Centra cada línea de un bloque de texto ASCII."""
cols = width or _term_size()[0]
lines = text.splitlines() or [""]
return "\n".join(line.center(cols) for line in lines)
def _pick_figlet_font() -> str:
"""Elige la primera fuente pyfiglet disponible de la lista preferida."""
if Figlet is None:
return "standard"
for name in _FIGLET_FONTS:
try:
Figlet(font=name)
return name
except Exception:
continue
return "standard"
def _render_logo(program_name: str) -> str:
"""Genera el logo ASCII grande del nombre del programa."""
if Figlet is None:
return program_name
font = _pick_figlet_font()
cols, _ = _term_size()
# Ancho contenido: logo impactante pero no gigante (acelera el Decrypt)
width = max(40, min(cols - 4, 90))
try:
fig = Figlet(font=font, width=width)
art = fig.renderText(program_name)
except Exception:
art = program_name + "\n"
# Si el arte es demasiado ancho, reintenta con fuente más compacta
max_line = max((len(line) for line in art.splitlines()), default=0)
if max_line > cols - 2 and font != "standard":
try:
fig = Figlet(font="standard", width=width)
art = fig.renderText(program_name)
except Exception:
pass
return art.rstrip("\n")
def _matrix_rain(duration: float = 0.9, density: float = 0.18) -> None:
"""
Corto efecto de lluvia matrix / ruido binario neon.
Usa rich.Live si está disponible; si no, print simple.
"""
cols, rows = _term_size()
# Usa pocas filas para que sea un flash rápido, no un muro eterno
height = max(8, min(rows - 2, 18))
charset = "01░▒▓█#@$%&*<>/\\|{}[]"
# Columnas activas con velocidad y glifo propios
drops = [
{
"y": random.randint(-height, 0),
"speed": random.uniform(0.35, 1.2),
"chars": [random.choice(charset) for _ in range(height)],
}
for _ in range(cols)
]
frames = max(8, int(duration * 28))
console = Console(highlight=False) if Console else None
def paint() -> Any:
grid = [[" " for _ in range(cols)] for _ in range(height)]
colors = [[NEON_DARK_GREEN for _ in range(cols)] for _ in range(height)]
for x, drop in enumerate(drops):
if random.random() > density and drop["y"] < 0:
continue
head = int(drop["y"])
for trail in range(0, 6):
yy = head - trail
if 0 <= yy < height:
ch = random.choice(charset) if trail == 0 else drop["chars"][yy % height]
grid[yy][x] = ch
if trail == 0:
colors[yy][x] = NEON_GREEN
elif trail < 3:
colors[yy][x] = NEON_DIM_GREEN
else:
colors[yy][x] = NEON_DARK_GREEN
drop["y"] += drop["speed"]
if drop["y"] > height + 2:
drop["y"] = random.randint(-8, -1)
drop["speed"] = random.uniform(0.35, 1.2)
if Text is None:
return "\n".join("".join(row) for row in grid)
text = Text()
for y in range(height):
for x in range(cols):
text.append(grid[y][x], style=f"bold {colors[y][x]}")
if y < height - 1:
text.append("\n")
return text
try:
_hide_cursor()
if console and Live is not None:
with Live(console=console, refresh_per_second=30, transient=True) as live:
for _ in range(frames):
live.update(paint())
time.sleep(duration / frames)
else:
for _ in range(frames):
sys.stdout.write("\033[H")
frame = paint()
sys.stdout.write(str(frame))
sys.stdout.write("\n")
sys.stdout.flush()
time.sleep(duration / frames)
finally:
_show_cursor()
def _typewriter(
text: str,
style: str = NEON_CYAN,
delay: float = 0.03,
prefix: str = "",
) -> None:
"""Escribe texto centrado carácter a carácter (typewriter suave)."""
cols, _ = _term_size()
full = f"{prefix}{text}"
pad = max(0, (cols - len(full)) // 2)
left = " " * pad
console = Console(highlight=False) if Console else None
buffer = ""
try:
_hide_cursor()
for ch in full:
buffer += ch
line = left + buffer
if console and Text is not None:
t = Text(line, style=f"bold {style}")
console.print(t, end="\r")
else:
sys.stdout.write("\r" + line)
sys.stdout.flush()
time.sleep(delay + random.uniform(0, 0.015))
# Salto de línea final
if console:
console.print()
else:
sys.stdout.write("\n")
sys.stdout.flush()
finally:
_show_cursor()
def _make_terminal_config(*, full_width: bool = False) -> Any:
"""
Configuración de canvas centrado.
full_width=False → el canvas sigue el ancho del texto (más rápido, menos padding).
full_width=True → usa todo el ancho del terminal.
"""
tc = TerminalConfig._build_config()
tc.frame_rate = 75
tc.canvas_width = 0 if full_width else -1
tc.canvas_height = -1
tc.anchor_canvas = "c"
tc.anchor_text = "c"
tc.no_eol = True
tc.terminal_background_color = Color("000000")
return tc
def _run_decrypt(text: str, *, typing_speed: int = 8) -> None:
"""Efecto Decrypt estilo película de hackers (verde → cyan/magenta)."""
if Decrypt is None:
print(_center_block(text))
return
cfg = DecryptConfig._build_config()
cfg.typing_speed = max(1, typing_speed)
cfg.ciphertext_colors = (
Color("008000"),
Color("00cb00"),
Color("00ff00"),
Color("00ffff"),
)
cfg.final_gradient_stops = (
Color("00ff00"),
Color("00ffff"),
Color("ff00ff"),
)
cfg.final_gradient_steps = 10
effect = Decrypt(
text,
effect_config=cfg,
terminal_config=_make_terminal_config(full_width=False),
)
with effect.terminal_output(end_symbol="") as terminal:
for frame in effect:
terminal.print(frame)
def _run_unstable(text: str) -> None:
"""Efecto Unstable (glitch / explosión y reensamblado) para el lema."""
if Unstable is None:
_run_decrypt(text, typing_speed=6)
return
cfg = UnstableConfig._build_config()
cfg.unstable_color = Color("ff00ff")
# Más rápido = intro más corta sin perder el punch visual
cfg.explosion_speed = 1.8
cfg.reassembly_speed = 1.6
cfg.final_gradient_stops = (
Color("00ff00"),
Color("00ffff"),
Color("ff00ff"),
Color("ffffff"),
)
cfg.final_gradient_steps = 8
effect = Unstable(
text,
effect_config=cfg,
terminal_config=_make_terminal_config(full_width=False),
)
with effect.terminal_output(end_symbol="") as terminal:
for frame in effect:
terminal.print(frame)
def _static_fallback(program_name: str) -> None:
"""Banner estático si faltan librerías de efectos."""
_clear()
logo = _render_logo(program_name)
if Console and Panel and Align:
console = Console()
console.print(
Panel(
Align.center(
f"[bold {NEON_GREEN}]{logo}[/]\n"
f"[bold {NEON_CYAN}]by @ej3mplo[/]\n\n"
f"[bold {NEON_MAGENTA}]Privacy is a universal right[/]"
),
border_style=NEON_GREEN,
title="[bold cyan]DEDSEC[/]",
subtitle="[dim]offline node[/]",
)
)
else:
print(_center_block(logo))
print(_center_block("by @ej3mplo"))
print(_center_block("Privacy is a universal right"))
time.sleep(1.2)
_clear()
def show_intro(program_name: str = "EJ TOOLS") -> None:
"""
Intro cinematográfica estilo DedSec.
Secuencia:
1. Limpia pantalla + matrix rain / ruido binario corto
2. Logo ASCII (pyfiglet) con flash glitch neon
3. Nombre del programa con Decrypt (terminaltexteffects)
4. Typewriter: by @ej3mplo
5. Lema con efecto Unstable (glitch fuerte)
6. Pausa y limpia para dejar paso al menú
"""
if _MISSING:
# Aviso una sola vez y banner de respaldo
sys.stderr.write(
"[intro] Faltan dependencias: "
+ ", ".join(_MISSING)
+ "\n pip install rich pyfiglet terminaltexteffects\n"
)
try:
_static_fallback(program_name)
except Exception:
print(program_name)
print("by @ej3mplo")
print("Privacy is a universal right")
return
console = Console(highlight=False)
try:
_hide_cursor()
cols, _ = _term_size()
# --- 1. Matrix rain ---
_clear()
_matrix_rain(duration=0.5, density=0.25)
time.sleep(0.04)
# --- 2. Logo ASCII (pyfiglet) con flash glitch corto ---
_clear()
logo = _render_logo(program_name)
glitch_chars = "░▒▓█▄▀■□▪▫01#@$%"
# 3 frames de ruido sobre el logo y luego el arte limpio
for i in range(3):
noisy_lines = []
for line in logo.splitlines():
if not line.strip():
noisy_lines.append(line)
continue
noisy_lines.append(
"".join(
ch if ch == " " or random.random() > 0.35 else random.choice(glitch_chars)
for ch in line
)
)
color = (NEON_MAGENTA, NEON_CYAN, NEON_GREEN)[i]
console.print(
Align.center(Text("\n".join(noisy_lines), style=f"bold {color}")),
end="",
)
time.sleep(0.07)
_clear()
console.print(Align.center(Text(logo, style=f"bold {NEON_GREEN}")))
time.sleep(0.25)
# --- 3. Nombre del programa con Decrypt (cinematográfico) ---
print()
_run_decrypt(program_name, typing_speed=2)
time.sleep(0.18)
# --- 4. Crédito typewriter ---
print()
_typewriter("by @ej3mplo", style=NEON_CYAN, delay=0.03, prefix="")
time.sleep(0.12)
# --- 5. Lema con glitch fuerte (Unstable) ---
print()
divider = "═" * min(42, cols - 4)
console.print(Align.center(Text(divider, style=f"dim {NEON_GREEN}")))
time.sleep(0.05)
_run_unstable("Privacy is a universal right")
time.sleep(0.06)
console.print(Align.center(Text(divider, style=f"dim {NEON_MAGENTA}")))
# --- 6. Hold y salida limpia hacia el menú ---
time.sleep(0.65)
except KeyboardInterrupt:
# Si el usuario cancela la intro, no tumbar el programa
pass
except Exception as exc:
# Cualquier fallo de efectos → banner estático y seguir
sys.stderr.write(f"[intro] efecto falló ({exc}); usando fallback.\n")
try:
_static_fallback(program_name)
return
except Exception:
pass
finally:
_show_cursor()
_clear()
if __name__ == "__main__":
# Demo rápida independiente
show_intro("EJ TOOLS")
print("→ Aquí iría el menú del programa.")