bchao1 / bullet

🚅 Interactive prompts made simple. Build a prompt like stacking blocks.
https://pypi.org/project/bullet/
MIT License
3.55k stars 113 forks source link

feature request - check if value is integer and ask to re-enter if not #60

Closed afortiori closed 4 years ago

afortiori commented 4 years ago

Hello!

This library is amazing! I'm not very familiar with GitHub issues so my apologies if I format this incorrectly. Sometimes I'd like to have the user input a whole number (ie. when asking for user age). With the number feature, there doesn't seem to currently be a way to specify an integer as the desired input. When I tried to just specify an integer with type = int, I got a value error. Of course, that's easily fixed by doing this:

try:
  number_input = Numbers(prompt="What is your age?\n", type = int ).launch()
except:
  print("Please enter a whole number.")
  number_input = Numbers(prompt="What is your age?\n", type = int ).launch()

However, I wondered if in the future the package could be designed to handle this problem without the need to use try-expect on the user of the package's end.