-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvaluereader.py
More file actions
54 lines (47 loc) · 1.9 KB
/
valuereader.py
File metadata and controls
54 lines (47 loc) · 1.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
from validator import Validator
from screen import Screen
from console import *
import colorama
from colorama import Fore, Back, Style
colorama.init(autoreset=False)
"""
|------------------------------------------|
| ENTER SOMETHING |
|------------------------------------------|
| |
| |
| |
| |
| |
| -> Entered text.... |
| |
| |
| |
| |
| |
|------------------------------------------|
| STATUS |
|------------------------------------------|
"""
class Value_reader:
""" Отримує дані від користувача та перевіряє їх з допомогою вказаного валідатора """
def __init__(self, _screen: Screen, _validator: Validator = None) -> None:
self._screen = _screen
self._validator = _validator
def read(self):
""" Читає та повертає дані від коритсувача """
success = False
show_cursor()
while not success:
self._screen.draw()
row_start = gap(self._screen.h, 1)
col_start = gap(self._screen.w, 64)
move_cursor(row_start, col_start)
print(Fore.YELLOW+'->', end='')
value = input()
if (self._validator is None and len(value)>0):
break
if(self._validator is not None and self._validator(value)):
break
hide_cursor()
return value if len(value)>0 else None