From d8a73519d5945bb150177291660ba6ab9a8726c8e5a411abbdce785e0e1c1c3b Mon Sep 17 00:00:00 2001 From: ranomier Date: Thu, 16 Jan 2025 04:07:08 +0100 Subject: [PATCH] the start of something --- python/src/lib/JsonCommunicator.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 python/src/lib/JsonCommunicator.py 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