Assert stdin exists for all interactive functions.

master
voussoir 2021-10-10 00:42:18 -07:00
parent a4196f2b13
commit 1a375e4964
No known key found for this signature in database
GPG Key ID: 5F7554F8C26DACCB
1 changed files with 12 additions and 0 deletions

View File

@ -1,8 +1,14 @@
''' '''
This module provides functions for interactive command line UIs. This module provides functions for interactive command line UIs.
''' '''
import sys
from voussoirkit import pipeable from voussoirkit import pipeable
def assert_stdin():
if sys.stdin is None:
raise RuntimeError('Interactive functions don\'t work when stdin is None.')
#################################################################################################### ####################################################################################################
# ABC_CHOOSER ###################################################################################### # ABC_CHOOSER ######################################################################################
#################################################################################################### ####################################################################################################
@ -26,6 +32,8 @@ def abc_chooser(options, prompt='', must_pick=False):
The return value is the item from the options list, or None if must_pick is The return value is the item from the options list, or None if must_pick is
False and the user entered nothing. False and the user entered nothing.
''' '''
assert_stdin()
option_letters = _abc_make_option_letters(options) option_letters = _abc_make_option_letters(options)
while True: while True:
@ -55,6 +63,8 @@ def abc_chooser_many(options, prompt='', label='X'):
they like, and submit their selection by entering one more blank line. they like, and submit their selection by entering one more blank line.
The return value is a list of items from the options list. The return value is a list of items from the options list.
''' '''
assert_stdin()
selected = set() selected = set()
option_letters = _abc_make_option_letters(options) option_letters = _abc_make_option_letters(options)
@ -110,6 +120,8 @@ def getpermission(
until they choose an acceptable answer. Either way, the intended usage of until they choose an acceptable answer. Either way, the intended usage of
`if getpermission():` will always only accept in case of explicit yes. `if getpermission():` will always only accept in case of explicit yes.
''' '''
assert_stdin()
if prompt is not None: if prompt is not None:
pipeable.stderr(prompt) pipeable.stderr(prompt)
while True: while True: