-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from lelit/master
Fix issue #14
Showing
4 changed files
with
88 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from pprint import pprint | ||
|
||
import inquirer | ||
|
||
if __name__ == '__main__': | ||
|
||
questions = [ | ||
inquirer.Text('user', message='Please enter your github username', validate=lambda _, x: x != '.'), | ||
inquirer.Password('password', message='Please enter your password'), | ||
inquirer.Text('repo', message='Please enter the repo name', default='default'), | ||
inquirer.Checkbox('topics', message='Please define your type of project?', choices=['common', 'backend', 'frontend'], ), | ||
inquirer.Text('organization', message='If this is a repo from a organization please enter the organization name, if not just leave this blank'), | ||
inquirer.Confirm('correct', message='This will delete all your current labels and create a new ones. Continue?', default=False), | ||
] | ||
|
||
answers = inquirer.prompt(questions) | ||
|
||
# Ask again, using previous values as defaults | ||
|
||
answers = inquirer.prompt(questions, answers=answers) | ||
|
||
pprint(answers) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,8 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from readchar import key | ||
from inquirer import errors | ||
from .base import BaseConsoleRender | ||
from ._text import Text | ||
|
||
|
||
class Password(BaseConsoleRender): | ||
title_inline = True | ||
|
||
def __init__(self, *args, **kwargs): | ||
super(Password, self).__init__(*args, **kwargs) | ||
self.current = '' | ||
|
||
class Password(Text): | ||
def get_current_value(self): | ||
return '*' * len(self.current) | ||
|
||
def process_input(self, pressed): | ||
if pressed == key.CTRL_C: | ||
raise KeyboardInterrupt() | ||
|
||
if pressed == key.ENTER: | ||
raise errors.EndOfInput(self.current) | ||
|
||
if pressed == key.BACKSPACE: | ||
if len(self.current): | ||
self.current = self.current[:-1] | ||
return | ||
|
||
if len(pressed) != 1: | ||
return | ||
|
||
self.current += pressed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import unittest | ||
import pexpect | ||
from readchar import key | ||
|
||
|
||
expected_result = r"""\ | ||
{'correct': True,\r\n | ||
'organization': '',\r\n | ||
'password': 'edcba',\r\n | ||
'repo': 'default',\r\n | ||
'topics': \['common'\],\r\n | ||
'user': 'abcde'}\r\n""" | ||
|
||
|
||
class PreAnswersTest(unittest.TestCase): | ||
def setUp(self): | ||
self.sut = pexpect.spawn('python examples/pre_answers.py') | ||
|
||
def test_minimal_input(self): | ||
# user | ||
self.sut.expect("Please enter", timeout=1) | ||
self.sut.send('abcde') | ||
self.sut.send(key.ENTER) | ||
# password | ||
self.sut.expect("Please enter", timeout=1) | ||
self.sut.send('edcba') | ||
self.sut.send(key.ENTER) | ||
# repo | ||
self.sut.expect("Please enter", timeout=1) | ||
self.sut.send(key.ENTER) | ||
# topics | ||
self.sut.expect("Please define", timeout=1) | ||
self.sut.send(key.SPACE) | ||
self.sut.send(key.ENTER) | ||
# organization | ||
self.sut.expect("If this is", timeout=1) | ||
self.sut.send(key.ENTER) | ||
# correct | ||
self.sut.expect("This will delete", timeout=1) | ||
self.sut.send('y') | ||
|
||
# again | ||
|
||
# user | ||
self.sut.expect("Please enter", timeout=1) | ||
self.sut.send(key.ENTER) | ||
# password | ||
self.sut.expect("Please enter", timeout=1) | ||
self.sut.send(key.ENTER) | ||
# repo | ||
self.sut.expect("Please enter", timeout=1) | ||
self.sut.send(key.ENTER) | ||
# topics | ||
self.sut.expect("Please define", timeout=1) | ||
self.sut.send(key.ENTER) | ||
# organization | ||
self.sut.expect("If this is", timeout=1) | ||
self.sut.send(key.ENTER) | ||
# correct | ||
self.sut.expect("This will delete", timeout=1) | ||
self.sut.send(key.ENTER) | ||
|
||
self.sut.expect([expected_result, pexpect.EOF], timeout=1) |