diff --git a/python/src/lib/JsonCommunicator.py b/python/src/lib/JsonCommunicator.py new file mode 100644 index 0000000..e6d9c3e --- /dev/null +++ b/python/src/lib/JsonCommunicator.py @@ -0,0 +1,30 @@ +#/usr/bin/env python +""" +veeeeeeeeeeeery early stage of something. Nothing commited yet. +propably will be converted to a class +""" + +def ask(question: str, answer_list: list, default_option: str = ""): + """ + answer_list should contain: + [ + {"short": "y", "long": "yes", "description": "helpful text"}, + {"short": "n", "long": "no", "description": "helpful text"} + ] + """ + if default_option: + default_exists = False + for option in answer_list: + if default_option == option["short"] or default_option == option["long"]: + default_exists = True + if not default_exists: + raise NameError(f"default option: '{default_option}' not found in answer_list") + + action = { + "type": question, + "content": { + "options": answer_list + } + } + # send action + # return whatever response we got from the elisp stuff