-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshared.py
More file actions
37 lines (25 loc) · 832 Bytes
/
shared.py
File metadata and controls
37 lines (25 loc) · 832 Bytes
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
import os
import sys
import time
import pygame
TEXT_SPEED = 0.01 # Typing effect speed
def clear():
os.system("cls" if os.name == "nt" else "clear")
def typewriter(text, speed=TEXT_SPEED, end="\n"):
"""Prints text with a typewriter effect."""
for char in text:
sys.stdout.write(char)
sys.stdout.flush()
time.sleep(speed)
print(end, flush=True)
def typewriter_rtl(text, speed=TEXT_SPEED, end="\n"):
"""Prints text with a typewriter effect, right-aligned."""
terminal_width = os.get_terminal_size().columns
padding = terminal_width - len(text)
formatted_text = " " * max(padding, 0) + text
for char in formatted_text:
sys.stdout.write(char)
sys.stdout.flush()
if char != " ":
time.sleep(speed)
print(end, flush=True)