inpy-input 1.1.8__tar.gz
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.
- inpy_input-1.1.8/PKG-INFO +9 -0
- inpy_input-1.1.8/inpy/__init__.py +1 -0
- inpy_input-1.1.8/inpy/inpy.py +210 -0
- inpy_input-1.1.8/inpy_input.egg-info/PKG-INFO +9 -0
- inpy_input-1.1.8/inpy_input.egg-info/SOURCES.txt +7 -0
- inpy_input-1.1.8/inpy_input.egg-info/dependency_links.txt +1 -0
- inpy_input-1.1.8/inpy_input.egg-info/top_level.txt +1 -0
- inpy_input-1.1.8/setup.cfg +4 -0
- inpy_input-1.1.8/setup.py +11 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from .inpy import *
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import termios
|
|
3
|
+
import tty
|
|
4
|
+
import string
|
|
5
|
+
|
|
6
|
+
CORES = {
|
|
7
|
+
"black": "30",
|
|
8
|
+
"red": "31",
|
|
9
|
+
"green": "32",
|
|
10
|
+
"yellow": "33",
|
|
11
|
+
"blue": "34",
|
|
12
|
+
"magenta": "35",
|
|
13
|
+
"cyan": "36",
|
|
14
|
+
"white": "37",
|
|
15
|
+
"bright_black": "90",
|
|
16
|
+
"bright_red": "91",
|
|
17
|
+
"bright_green": "92",
|
|
18
|
+
"bright_yellow": "93",
|
|
19
|
+
"bright_blue": "94",
|
|
20
|
+
"bright_magenta": "95",
|
|
21
|
+
"bright_cyan": "96",
|
|
22
|
+
"bright_white": "97"
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
ESTILOS = {
|
|
26
|
+
"bold": "1",
|
|
27
|
+
"underline": "4",
|
|
28
|
+
"reverse": "7"
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
RESET = "\033[0m"
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _ler_tecla():
|
|
35
|
+
fd = sys.stdin.fileno()
|
|
36
|
+
old = termios.tcgetattr(fd)
|
|
37
|
+
try:
|
|
38
|
+
tty.setraw(fd)
|
|
39
|
+
tecla = sys.stdin.read(1)
|
|
40
|
+
finally:
|
|
41
|
+
termios.tcsetattr(fd, termios.TCSADRAIN, old)
|
|
42
|
+
return tecla
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _gerar_codigo(style):
|
|
46
|
+
if not style:
|
|
47
|
+
return ""
|
|
48
|
+
partes = style.lower().split()
|
|
49
|
+
codigos = []
|
|
50
|
+
for p in partes:
|
|
51
|
+
if p in CORES:
|
|
52
|
+
codigos.append(CORES[p])
|
|
53
|
+
elif p in ESTILOS:
|
|
54
|
+
codigos.append(ESTILOS[p])
|
|
55
|
+
if not codigos:
|
|
56
|
+
return ""
|
|
57
|
+
return "\033[" + ";".join(codigos) + "m"
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def _permitido(tecla, modo):
|
|
61
|
+
if modo == "all":
|
|
62
|
+
return True
|
|
63
|
+
if modo == "numbers":
|
|
64
|
+
return tecla.isdigit()
|
|
65
|
+
if modo == "letters":
|
|
66
|
+
return tecla.isalpha()
|
|
67
|
+
if modo == "alphanumeric":
|
|
68
|
+
return tecla.isalnum()
|
|
69
|
+
if modo == "chars":
|
|
70
|
+
return tecla in string.punctuation
|
|
71
|
+
return True
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def input(
|
|
75
|
+
prompt="",
|
|
76
|
+
message_color="bright_white",
|
|
77
|
+
color="bright_white",
|
|
78
|
+
hide=False,
|
|
79
|
+
hide_full=False,
|
|
80
|
+
hide_char="*",
|
|
81
|
+
auto_enter_word=None,
|
|
82
|
+
accept="all",
|
|
83
|
+
allowed_chars=None,
|
|
84
|
+
max_chars=None,
|
|
85
|
+
reset_if_exceed=False,
|
|
86
|
+
lock_after_limit=False
|
|
87
|
+
):
|
|
88
|
+
texto = ""
|
|
89
|
+
codigo_prompt = _gerar_codigo(message_color)
|
|
90
|
+
codigo_texto = _gerar_codigo(color)
|
|
91
|
+
print(codigo_prompt + prompt + RESET, end="", flush=True)
|
|
92
|
+
|
|
93
|
+
while True:
|
|
94
|
+
tecla = _ler_tecla()
|
|
95
|
+
|
|
96
|
+
if tecla == "\x03":
|
|
97
|
+
print("^C")
|
|
98
|
+
raise KeyboardInterrupt
|
|
99
|
+
|
|
100
|
+
if tecla == "\r":
|
|
101
|
+
break
|
|
102
|
+
|
|
103
|
+
if tecla == "\x7f":
|
|
104
|
+
if texto:
|
|
105
|
+
texto = texto[:-1]
|
|
106
|
+
if not hide_full:
|
|
107
|
+
sys.stdout.write("\b \b")
|
|
108
|
+
sys.stdout.flush()
|
|
109
|
+
continue
|
|
110
|
+
|
|
111
|
+
if not _permitido(tecla, accept):
|
|
112
|
+
continue
|
|
113
|
+
|
|
114
|
+
if allowed_chars and tecla not in allowed_chars:
|
|
115
|
+
continue
|
|
116
|
+
|
|
117
|
+
if max_chars and len(texto) >= max_chars:
|
|
118
|
+
if reset_if_exceed:
|
|
119
|
+
while len(texto) > 0:
|
|
120
|
+
sys.stdout.write("\b \b")
|
|
121
|
+
texto = texto[:-1]
|
|
122
|
+
sys.stdout.flush()
|
|
123
|
+
continue
|
|
124
|
+
if lock_after_limit:
|
|
125
|
+
continue
|
|
126
|
+
|
|
127
|
+
texto += tecla
|
|
128
|
+
|
|
129
|
+
if hide_full:
|
|
130
|
+
pass
|
|
131
|
+
elif hide:
|
|
132
|
+
sys.stdout.write(hide_char)
|
|
133
|
+
else:
|
|
134
|
+
sys.stdout.write(codigo_texto + tecla + RESET)
|
|
135
|
+
|
|
136
|
+
sys.stdout.flush()
|
|
137
|
+
|
|
138
|
+
if auto_enter_word:
|
|
139
|
+
texto_check = texto.lower()
|
|
140
|
+
if isinstance(auto_enter_word, str):
|
|
141
|
+
palavras = [auto_enter_word]
|
|
142
|
+
else:
|
|
143
|
+
palavras = list(auto_enter_word)
|
|
144
|
+
|
|
145
|
+
for palavra in palavras:
|
|
146
|
+
if texto_check.endswith(str(palavra).lower()):
|
|
147
|
+
print()
|
|
148
|
+
return texto
|
|
149
|
+
|
|
150
|
+
print()
|
|
151
|
+
return texto
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def help_input(language="pt"):
|
|
155
|
+
if language.lower() == "pt":
|
|
156
|
+
print("""
|
|
157
|
+
================================
|
|
158
|
+
AJUDA DO INPUT AVANÇADO
|
|
159
|
+
================================
|
|
160
|
+
|
|
161
|
+
Use "bright_white" para branco real.
|
|
162
|
+
|
|
163
|
+
Cores:
|
|
164
|
+
black red green yellow blue magenta cyan white
|
|
165
|
+
bright_black bright_red bright_green bright_yellow
|
|
166
|
+
bright_blue bright_magenta bright_cyan bright_white
|
|
167
|
+
|
|
168
|
+
Estilos:
|
|
169
|
+
bold underline reverse
|
|
170
|
+
|
|
171
|
+
Exemplo:
|
|
172
|
+
|
|
173
|
+
input(
|
|
174
|
+
prompt="Senha: ",
|
|
175
|
+
message_color="bright_white bold",
|
|
176
|
+
color="bright_cyan",
|
|
177
|
+
hide=True,
|
|
178
|
+
max_chars=8
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
================================
|
|
182
|
+
""")
|
|
183
|
+
else:
|
|
184
|
+
print("""
|
|
185
|
+
================================
|
|
186
|
+
ADVANCED INPUT HELP
|
|
187
|
+
================================
|
|
188
|
+
|
|
189
|
+
Use "bright_white" for true white.
|
|
190
|
+
|
|
191
|
+
Colors:
|
|
192
|
+
black red green yellow blue magenta cyan white
|
|
193
|
+
bright_black bright_red bright_green bright_yellow
|
|
194
|
+
bright_blue bright_magenta bright_cyan bright_white
|
|
195
|
+
|
|
196
|
+
Styles:
|
|
197
|
+
bold underline reverse
|
|
198
|
+
|
|
199
|
+
Example:
|
|
200
|
+
|
|
201
|
+
input(
|
|
202
|
+
prompt="Password: ",
|
|
203
|
+
message_color="bright_white bold",
|
|
204
|
+
color="bright_cyan",
|
|
205
|
+
hide=True,
|
|
206
|
+
max_chars=8
|
|
207
|
+
)
|
|
208
|
+
|
|
209
|
+
================================
|
|
210
|
+
""")
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
inpy
|