|
@@ -0,0 +1,29 @@
|
|
|
+from PyInquirer import prompt, Validator, ValidationError
|
|
|
+from prompt_toolkit import document
|
|
|
+import regex
|
|
|
+
|
|
|
+class NickNameValidator(Validator):
|
|
|
+ def validate(self, document: document.Document) -> None:
|
|
|
+ ok = regex.match('^[A-Z][a-z]+$', document.text)
|
|
|
+ if not ok:
|
|
|
+ raise ValidationError(message = 'Please enter a correct name, with a uppercase and letters', cursor_position = len(document.text))
|
|
|
+
|
|
|
+widget = [
|
|
|
+ {
|
|
|
+ 'type':'input',
|
|
|
+ 'name':'nickname',
|
|
|
+ 'message':'Choose a nickname :',
|
|
|
+ 'qmark':'>>>',
|
|
|
+ 'validate':NickNameValidator
|
|
|
+ }
|
|
|
+]
|
|
|
+
|
|
|
+try :
|
|
|
+ result = prompt(widget)
|
|
|
+except ValueError :
|
|
|
+ print('Pb !!!')
|
|
|
+ exit()
|
|
|
+
|
|
|
+print('Your answer is')
|
|
|
+print(result["nickname"])
|
|
|
+print(type(result["nickname"]))
|