Exemple #1
0
def encounter2b():
    inquiry.prompt({
        'type':
        'list',
        'name':
        'weapon',
        'message':
        'Pick one',
        'choices': [
            'Use the stick', 'Grab a large rock', 'Try and make a run for it',
            'Attack the wolf unarmed'
        ]
    })
    print 'The wolf mauls you. You die. The end.'
Exemple #2
0
def exitHouse():
    answers = inquiry.prompt(directionsPrompt)
    if answers['direction'] == 'Forward':
        print 'You find yourself in a forest'
        print 'There is a wolf in front of you; a friendly looking dwarf to the right and an impasse to the left.'
        encounter1()
    else:
        print 'You cannot go that way. Try again'
        exitHouse()
Exemple #3
0
def encounter2a():
    answers = inquiry.prompt(directionsPrompt)
    direction = answers['direction']
    if direction == 'Forward':
        print 'You find a painted wooden sign that says:'
        print ' ____  _____  ____  _____ '
        print '(_  _)(  _  )(  _ \\(  _  ) '
        print '  )(   )(_)(  )(_) ))(_)(  '
        print ' (__) (_____)(____/(_____) '
    else:
        print 'You cannot go that way'
        encounter2a()
Exemple #4
0
def encounter1():
    answers = inquiry.prompt(directionsPrompt)
    direction = answers['direction']
    if direction == 'Forward':
        print 'You attempt to fight the wolf'
        print 'Theres a stick and some stones lying around you could use as a weapon'
        encounter2b()
    elif direction == 'Right':
        print 'You befriend the dwarf'
        print 'He helps you kill the wolf. You can now move forward'
        encounter2a()
    else:
        print 'You cannot go that way'
        encounter1()
Exemple #5
0
 result = inquiry.prompt([{
     'type':
     'checkbox',
     'message':
     'Select toppings',
     'name':
     'toppings',
     'choices': [
         inquiry.Separator(' = The Meats = '), {
             'name': 'Pepperoni'
         }, {
             'name': 'Ham'
         }, {
             'name': 'Ground Meat'
         }, {
             'name': 'Bacon'
         },
         inquiry.Separator(' = The Cheeses = '), {
             'name': 'Mozzarella',
             'checked': True
         }, {
             'name': 'Cheddar'
         }, {
             'name': 'Parmesan'
         },
         inquiry.Separator(' = The usual ='), {
             'name': 'Mushroom'
         }, {
             'name': 'Tomato'
         },
         inquiry.Separator(' = The extras = '), {
             'name': 'Pineapple'
         }, {
             'name': 'Olives',
             'disabled': 'out of stock'
         }, {
             'name': 'Extra cheese'
         }
     ],
     'validate':
     lambda answer: 'You must choose at least one topping.'
     if len(answer) < 1 else True
 }])
Exemple #6
0
import inquiry
import json

try:
    result = inquiry.prompt([{
        'type':
        'rawlist',
        'name':
        'theme',
        'message':
        'What do you want to do?',
        'choices': [
            'Order a pizza', 'Make a reservation',
            inquiry.Separator(), 'Ask opening hours',
            'Talk to the receptionist'
        ]
    }, {
        'type':
        'rawlist',
        'name':
        'size',
        'message':
        'What size do you need',
        'choices': ['Jumbo', 'Large', 'Standard', 'Medium', 'Small', 'Micro'],
        'filter':
        lambda val: val.lower(),
    }])
except KeyboardInterrupt:
    print 'Aborted.'
else:
    print json.dumps(result, indent=2)
Exemple #7
0
import json

try:
    result = inquiry.prompt([{
        'type':
        'expand',
        'message':
        'Conflict on `file.js`: ',
        'name':
        'overwrite',
        'choices': [{
            'key': 'y',
            'name': 'Overwrite',
            'value': 'overwrite'
        }, {
            'key': 'a',
            'name': 'Overwrite this one and all next',
            'value': 'overwrite_all'
        }, {
            'key': 'd',
            'name': 'Show diff',
            'value': 'diff'
        },
                    inquiry.Separator(), {
                        'key': 'x',
                        'name': 'Abort',
                        'value': 'abort'
                    }]
    }])
except KeyboardInterrupt:
    print 'Aborted.'
else:
Exemple #8
0
import inquiry
import json

choices = [chr(x + 65) for x in range(0, 26)]
choices.append('Multiline option \n  super cool feature')
choices.append({
    'name':
    'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium.',
    'value': 'foo',
    'short': 'The long option'
})

try:
    result = inquiry.prompt([{
        'type': 'list',
        'name': 'letter',
        'message': "What's your favorite letter?",
        'choices': choices
    }, {
        'type': 'checkbox',
        'name': 'name',
        'message': 'Select the letter contained in your name:',
        'choices': choices
    }])
except KeyboardInterrupt:
    print 'Aborted.'
else:
    print json.dumps(result, indent=2)
Exemple #9
0
import inquiry
import json
import re


def requireLetterAndNumber(value):
    if re.search('\w', value) and re.search('\d', value):
        return True
    return 'Password need to have at least a letter and a number'


try:
    result = inquiry.prompt([{
        'type': 'password',
        'message': 'Enter a password',
        'name': 'password1',
        'validate': requireLetterAndNumber
    }, {
        'type': 'password',
        'message': 'Enter a masked password',
        'name': 'password2',
        'mask': '*',
        'validate': requireLetterAndNumber
    }])
except KeyboardInterrupt:
    print 'Aborted.'
else:
    print json.dumps(result, indent=2)
Exemple #10
0
try:
    result = inquiry.prompt([{
        'type': 'confirm',
        'name': 'bacon',
        'message': 'Do you like bacon?'
    }, {
        'type':
        'input',
        'name':
        'favorite',
        'message':
        'Bacon lover, what is your favorite type of bacon?',
        'when':
        lambda answers: answers.get('bacon', None),
    }, {
        'type':
        'confirm',
        'name':
        'pizza',
        'message':
        'Ok... Do you like pizza?',
        'when':
        lambda answers: not likesFood('bacon')(answers),
    }, {
        'type': 'input',
        'name': 'favorite',
        'message': 'Whew! What is your favorite type of pizza?',
        'when': likesFood('pizza'),
    }])
except KeyboardInterrupt:
    print 'Aborted.'
Exemple #11
0
    valid = re.match(
        '^([01]{1})?[-.\s]?\(?(\d{3})\)?[-.\s]?(\d{3})[-.\s]?(\d{4})\s?((?:#|ext\.?\s?|x\.?\s?){1}(?:\d+)?)?$',
        value)

    if valid:
        return True

    return 'Please enter a valid phone number'


try:
    result = inquiry.prompt([{
        'type': 'input',
        'name': 'first_name',
        'message': "What's your first name"
    }, {
        'type': 'input',
        'name': 'last_name',
        'message': "What's your last name",
        'default': lambda answers: 'Doe',
    }, {
        'type': 'input',
        'name': 'phone',
        'message': "What's your phone number",
        'validate': validate_telephone
    }])
except KeyboardInterrupt:
    print 'Aborted.'
else:
    print json.dumps(result, indent=2)
Exemple #12
0
 result = inquiry.prompt([{
     'type': 'confirm',
     'name': 'toBeDelivered',
     'message': 'Is this for delivery?',
     'default': False
 }, {
     'type': 'input',
     'name': 'phone',
     'message': "What's your phone number?",
     'validate': validate_telephone,
 }, {
     'type': 'list',
     'name': 'size',
     'message': 'What size do you need?',
     'choices': ['Large', 'Medium', 'Small'],
     'filter': lambda val: val.lower(),
 }, {
     'type': 'input',
     'name': 'quantity',
     'message': 'How many do you need?',
     'validate': validate_float,
     'filter': float
 }, {
     'type':
     'expand',
     'name':
     'toppings',
     'message':
     'What about the toppings?',
     'choices': [{
         'key': 'p',
         'name': 'Pepperoni and cheese',
         'value': 'PepperoniCheese'
     }, {
         'key': 'a',
         'name': 'All dressed',
         'value': 'alldressed'
     }, {
         'key': 'w',
         'name': 'Hawaiian',
         'value': 'hawaiian'
     }]
 }, {
     'type': 'rawlist',
     'name': 'beverage',
     'message': 'You also get a free 2L beverage',
     'choices': ['Pepsi', '7up', 'Coke']
 }, {
     'type': 'input',
     'name': 'comments',
     'message': 'Any comments on your purchase experience?',
     'default': 'Nope, all good!'
 }, {
     'type':
     'list',
     'name':
     'prize',
     'message':
     'For leaving a comment, you get a freebie',
     'choices': ['cake', 'fries'],
     'when':
     lambda answers: answers['comments'] != 'Nope, all good!',
 }])