|
| 1 | +import os |
| 2 | +import sys |
| 3 | +from pprint import pprint |
| 4 | + |
| 5 | +try: |
| 6 | + from fuzzyfinder import fuzzyfinder |
| 7 | +except ImportError: |
| 8 | + raise ImportError( |
| 9 | + "The required package 'fuzzyfinder' is not installed. Install it using:\n\n" |
| 10 | + " pip install fuzzyfinder\n" |
| 11 | + ) |
| 12 | + |
| 13 | +sys.path.append(os.path.realpath(".")) |
| 14 | +import inquirer # noqa |
| 15 | + |
| 16 | + |
| 17 | +choices = [ |
| 18 | + "apple", "banana", "grapefruit", "blueberry", "strawberry", "blackberry", |
| 19 | + "raspberry", "cherry", "mango", "pineapple", "watermelon", "cantaloupe", |
| 20 | + "honeydew", "kiwi", "papaya", "fig", "pomegranate", "date", "coconut", |
| 21 | + "lemon", "lime", "orange", "tangerine", "peach", "plum", "apricot", |
| 22 | + "pear", "persimmon", "guava", "passionfruit", "lychee", "dragonfruit", |
| 23 | + "starfruit", "durian", "jackfruit", "elderberry", "mulberry", "boysenberry", |
| 24 | + "carrot", "potato", "tomato", "cucumber", "lettuce", "spinach", "broccoli", |
| 25 | + "cauliflower", "cabbage", "zucchini", "squash", "pumpkin", "radish", |
| 26 | + "beet", "onion", "garlic", "shallot", "leek", "celery", "asparagus", |
| 27 | + "artichoke", "pepper", "chili", "jalapeno", "habanero", "ghost pepper", |
| 28 | + "serrano", "poblano", "corn", "peas", "green beans", "chickpeas", |
| 29 | + "lentils", "soybeans", "quinoa", "rice", "barley", "oats", "wheat"] |
| 30 | + |
| 31 | + |
| 32 | +def filter_func(text, collection): |
| 33 | + g = fuzzyfinder(text, collection, accessor=lambda x: str(x)) |
| 34 | + return list(g) |
| 35 | + |
| 36 | + |
| 37 | +questions = [ |
| 38 | + inquirer.FilterList( |
| 39 | + "size", |
| 40 | + message="Select item ", |
| 41 | + choices=choices, |
| 42 | + carousel=False, |
| 43 | + filter_func= filter_func, |
| 44 | + ), |
| 45 | +] |
| 46 | + |
| 47 | +answers = inquirer.prompt(questions) |
| 48 | + |
| 49 | +pprint(answers) |
0 commit comments