-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCustomIO.py
101 lines (88 loc) · 3.55 KB
/
CustomIO.py
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
from time import sleep
from random import randint
from sys import stdout, stdin
from select import select
import fonts
class CustomIO:
"""
This Class is used for a customised input and output functions.
"""
def __init__(self):
pass
def typel(self, text='', delay=-1.0):
"""
This function prints a given text with a delay between each letters
making it appear like it is being typed.
The typing speed can be adjusted by changing the 'delay' value.
:param text : The text to be printed
:param delay: The printing interval between to letters; if user does not provide any,
an random delay is generated for each letter
:return : None (at return no New-Line is created!)
"""
for letter in text:
if delay == -1:
delay = (1 / randint(2, 5) - 0.1) or 0.1
print(letter, end='', flush=stdout)
sleep(delay)
def timer_input(self, wait=5):
"""
This functions waits for a user input for a given period of time.
:param wait: the waiting time required for input; default is 5 seconds
:return : the value entered (if any)
"""
wait = float(wait)
if select([stdin], [], [], wait)[0]:
return stdin.readline().strip()
def loading(self):
self.typel('* LOADING', 0.3)
sleep(1)
self.typel('...', 0.3)
print(' *')
def print_spaces(self, length):
"""
Prints spaces for a given length.
Note : No new-line is created.
:param length: The length of spaces needed.
:return: None
"""
for x in range(0, length):
print(' ', end='', flush=stdout)
def speech_bill(self, text, secure=1):
"""
This method prints the speechs of Bill Zuckerberg.
:param secure: Whether he speaks by secure channel yo you(1, default) or directly to TRA (0)
:param text: His Speech.
:return: None
"""
if secure:
print(fonts.font_light('aqua') + '[Bill: ', end='')
self.typel(' ' + text + ']')
print(fonts.default())
elif secure == 0:
print(fonts.font_dark('aqua') + fonts.bold() + 'Bill : ', end='')
self.typel(' ' + text)
print(fonts.default())
def speech_tra(self, text, face=1):
"""
This method prints the speech of TRA
:param face: 1: T-Rex personality, 2: Angel Personality
:param text: His Speech.
:return: None
"""
if face == 1:
print(fonts.font_light('red') + fonts.bold() + 'T-REX: ', end='')
self.typel(' ' + text, 0.1)
print(fonts.default())
if face == 2:
print(fonts.font_light('yellow') + fonts.bold() + 'ANGEL: ', end='')
self.typel(' ' + text, 0.1)
print(fonts.default())
def zebra_bar(self, color1, color2, lenght):
for x in range(0, int(lenght/10)):
print(fonts.bar_dark(color1) + ' ', end='' + fonts.default())
print(fonts.bar_dark(color2) + ' ', end='' + fonts.default())
print()
#print(fonts.bar_light('grey'), ' ' + fonts.default(), end='')
for x in range(0, int(lenght/10)):
print(fonts.bar_dark(color2) + ' ', end='' + fonts.default())
print(fonts.bar_dark(color1) + ' ', end='' + fonts.default())