Source code for xiuminglib.interact

import sys

from .log import get_logger
logger = get_logger()





[docs]def ask_to_proceed(msg, level='warning'): """Pauses there to ask the user whether to proceed. Args: msg (str): Message to display to the user. level (str, optional): Message level, essentially deciding the message color: ``'info'``, ``'warning'``, or ``'error'``. """ logger_print = getattr(logger, level) logger_print(msg) logger_print("Proceed? (y/n)") need_input = True while need_input: response = input().lower() if response in ('y', 'n'): need_input = False if need_input: logger.error("Enter only y or n!") if response == 'n': sys.exit()
[docs]def format_print(msg, fmt): """Prints a message with format. Args: msg (str): Message to print. fmt (str): Format; try your luck with any value -- don't worry; if it's illegal, you will be prompted with all legal values. """ fmt_strs = { 'header': '\033[95m', 'okblue': '\033[94m', 'okgreen': '\033[92m', 'warn': '\033[93m', 'fail': '\033[91m', 'bold': '\033[1m', 'underline': '\033[4m', } if fmt in fmt_strs.keys(): start_str = fmt_strs[fmt] end_str = '\033[0m' elif len(fmt) == 1: start_str = "\n<" + "".join([fmt] * 78) + '\n\n' # as per PEP8 end_str = '\n' + start_str[2:-2] + ">\n" else: raise ValueError( ("Legal values for fmt: %s, plus any single character " "(which will be repeated into the line separator), " "but input is '%s'") % (list(fmt_strs.keys()), fmt)) print(start_str + msg + end_str)