From cfb62d61b6faa204f40d344da11cf111456886f6 Mon Sep 17 00:00:00 2001 From: Ryan Date: Fri, 22 Jul 2022 14:36:04 -0400 Subject: [PATCH 01/11] testing different checkbox form --- blue/5G/daedalus/daedalus.py | 57 +++++++++++++++++------------------- blue/pyproject.toml | 2 +- 2 files changed, 28 insertions(+), 31 deletions(-) diff --git a/blue/5G/daedalus/daedalus.py b/blue/5G/daedalus/daedalus.py index ee39265a..1eed8462 100644 --- a/blue/5G/daedalus/daedalus.py +++ b/blue/5G/daedalus/daedalus.py @@ -31,7 +31,7 @@ from plumbum.cmd import rm # pytype: disable=import-error from plumbum.cmd import sudo # pytype: disable=import-error from plumbum.cmd import tar # pytype: disable=import-error -from InquirerPy import prompt +from inuirer import prompt, Checkbox, Editor level_int = {'CRITICAL': 50, 'ERROR': 40, 'WARNING': 30, 'INFO': 20, @@ -269,42 +269,39 @@ def execute_prompt(questions): Run end user prompt with supplied questions and return the selected answers """ - answers = prompt(questions, style=custom_style) + answers = prompt(questions, theme=custom_style) return answers @staticmethod def main_questions(): """Ask which services to start""" return [ - { - 'type': 'checkbox', - 'name': 'services', - 'message': 'What services would you like to start?', - 'choices': [ - {'name': '4G Open5GS EPC (HSS, MME, SMF, SGWC, PCRF)', - 'value': '4G Open5GS EPC (HSS, MME, SMF, SGWC, PCRF)', - 'enabled': True}, - {'name': 'Open5GS User Plane Network (UPF, SGWU)', - 'value': 'Open5GS User Plane Network (UPF, SGWU)', - 'enabled': True}, - {'name': 'Subscriber Database (MongoDB)', - 'value': 'Subscriber Database (MongoDB)', - 'enabled': True}, - {'name': '5G Open5GS Core (NRF, AUSF, NSSF, UDM, BSF, PCF, UDR, AMF)', 'value': '5G Open5GS Core (NRF, AUSF, NSSF, UDM, BSF, PCF, UDR, AMF)'}, - {'name': '5G UERANSIM gNodeB (gNB)', 'value': '5G UERANSIM gNodeB (gNB)'}, - {'name': '4G srsRAN eNodeB (eNB)', 'value': '4G srsRAN eNodeB (eNB)'}, - {'name': '5G srsRAN NSA gNodeB (gNB)', 'value': '5G srsRAN NSA gNodeB (gNB)'}, - {'name': '4G BladeRF eNodeB (eNB)', 'value': '4G BladeRF eNodeB (eNB)'}, - {'name': '4G Ettus USRP B2xx eNodeB (eNB)', 'value': '4G Ettus USRP B2xx eNodeB (eNB)'}, - {'name': '5G Ettus USRP B2xx NSA gNodeB (gNB)', 'value': '5G Ettus USRP B2xx NSA gNodeB (gNB)'}, - {'name': '4G LimeSDR eNodeB (eNB)', 'value': '4G LimeSDR eNodeB (eNB)'}, - {'name': '4G srsRAN UE (UE)', 'value': '4G srsRAN UE (UE)'}, - {'name': '5G srsRAN UE (UE)', 'value': '5G srsRAN UE (UE)'}, - {'name': '5G UERANSIM UE (UE)', 'value': '5G UERANSIM UE (UE)'}, - {'name': 'Add UE IMSIs', 'value': 'Add UE IMSIs'}, - {'name': 'Subscriber WebUI', 'value': 'Subscriber WebUI'}, + Checkbox('services', + message = 'What services would you like to start?', + choices = [ + '4G Open5GS EPC (HSS, MME, SMF, SGWC, PCRF)', + 'Open5GS User Plane Network (UPF, SGWU)', + 'Subscriber Database (MongoDB)', + '5G Open5GS Core (NRF, AUSF, NSSF, UDM, BSF, PCF, UDR, AMF)', + '5G UERANSIM gNodeB (gNB)', + '4G srsRAN eNodeB (eNB)', + '5G srsRAN NSA gNodeB (gNB)' + '4G BladeRF eNodeB (eNB)', + '4G Ettus USRP B2xx eNodeB (eNB)', + '5G Ettus USRP B2xx NSA gNodeB (gNB)', + '4G LimeSDR eNodeB (eNB)', + '4G srsRAN UE (UE)', + '5G srsRAN UE (UE)', + '5G UERANSIM UE (UE)', + 'Add UE IMSIs', + 'Subscriber WebUI', ], - }, + default = [ + '4G Open5GS EPC (HSS, MME, SMF, SGWC, PCRF)', + 'Open5GS User Plane Network (UPF, SGWU)', + 'Subscriber Database (MongoDB)' + ] + ), ] @staticmethod diff --git a/blue/pyproject.toml b/blue/pyproject.toml index 8919a063..64a7652d 100644 --- a/blue/pyproject.toml +++ b/blue/pyproject.toml @@ -20,7 +20,7 @@ dependencies = [ "docker-compose == 1.29.2", "dovesnap == 1.1.1", "plumbum == 1.7.2", - "inquirerpy == 0.3.4", + "inquirer == 2.9.2", ] [project.optional-dependencies] From 1b8b6afd2749a86fc049982110610b4b936a112f Mon Sep 17 00:00:00 2001 From: Ryan Date: Fri, 22 Jul 2022 14:53:13 -0400 Subject: [PATCH 02/11] initial checkboxes working --- blue/5G/daedalus/daedalus.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/blue/5G/daedalus/daedalus.py b/blue/5G/daedalus/daedalus.py index 1eed8462..54eec0cc 100644 --- a/blue/5G/daedalus/daedalus.py +++ b/blue/5G/daedalus/daedalus.py @@ -31,7 +31,7 @@ from plumbum.cmd import rm # pytype: disable=import-error from plumbum.cmd import sudo # pytype: disable=import-error from plumbum.cmd import tar # pytype: disable=import-error -from inuirer import prompt, Checkbox, Editor +from inquirer import prompt, Checkbox, Editor level_int = {'CRITICAL': 50, 'ERROR': 40, 'WARNING': 30, 'INFO': 20, @@ -269,7 +269,7 @@ def execute_prompt(questions): Run end user prompt with supplied questions and return the selected answers """ - answers = prompt(questions, theme=custom_style) + answers = prompt(questions) #, theme=custom_style) return answers @staticmethod From 7d2e2a0a764a9d3244071b25a639f687b5f94852 Mon Sep 17 00:00:00 2001 From: Ryan Date: Fri, 22 Jul 2022 15:12:43 -0400 Subject: [PATCH 03/11] convert validators --- blue/5G/daedalus/daedalus.py | 2 +- blue/5G/daedalus/validators.py | 117 +++++++++++++-------------------- 2 files changed, 47 insertions(+), 72 deletions(-) diff --git a/blue/5G/daedalus/daedalus.py b/blue/5G/daedalus/daedalus.py index 54eec0cc..b0382126 100644 --- a/blue/5G/daedalus/daedalus.py +++ b/blue/5G/daedalus/daedalus.py @@ -31,7 +31,7 @@ from plumbum.cmd import rm # pytype: disable=import-error from plumbum.cmd import sudo # pytype: disable=import-error from plumbum.cmd import tar # pytype: disable=import-error -from inquirer import prompt, Checkbox, Editor +from inquirer import prompt, Checkbox, Editor, List level_int = {'CRITICAL': 50, 'ERROR': 40, 'WARNING': 30, 'INFO': 20, diff --git a/blue/5G/daedalus/validators.py b/blue/5G/daedalus/validators.py index 28a590b4..ace5a80c 100644 --- a/blue/5G/daedalus/validators.py +++ b/blue/5G/daedalus/validators.py @@ -3,74 +3,49 @@ """ import json -from prompt_toolkit.validation import ValidationError -from prompt_toolkit.validation import Validator - - -class NumberValidator(Validator): - """Validate strings are numbers""" - - def validate(self, document): - """Specifically validate the string is a number between 0 and 66535""" - try: - int(document.text) - except ValueError as value_error: # pragma: no cover - raise ValidationError( - message='Please enter a number', - cursor_position=len(document.text)) from value_error # pragma: no cover - if int(document.text) < 0 or int(document.text) > 65535: - raise ValidationError( - message='Please enter a number between 0 and 65535', - cursor_position=len(document.text)) # pragma: no cover - - -class MCCValidator(Validator): - """Validate string is a MCC code""" - - def validate(self, document): - """Specifically validate the string is a number between 000 and 999""" - try: - int(document.text.lstrip('0')) - except ValueError as value_error: # pragma: no cover - raise ValidationError( - message='Please enter a number', - cursor_position=len(document.text)) from value_error # pragma: no cover - if int(document.text.lstrip('0')) < 0 or int(document.text.lstrip('0')) > 999 or len(document.text) != 3: - raise ValidationError( - message='Please enter a number between 000 and 999', - cursor_position=len(document.text)) # pragma: no cover - - -class MNCValidator(Validator): - """Validate string is a MNC code""" - - def validate(self, document): - """Specifically validate the string is a number between 00 and 99""" - try: - int(document.text.lstrip('0')) - except ValueError as value_error: # pragma: no cover - raise ValidationError( - message='Please enter a number', - cursor_position=len(document.text)) from value_error # pragma: no cover - if int(document.text.lstrip('0')) < 0 or int(document.text.lstrip('0')) > 99 or len(document.text) != 2: - raise ValidationError( - message='Please enter a number between 00 and 99', - cursor_position=len(document.text)) # pragma: no cover - - -class IMSIValidator(Validator): - """Validate string is a list of IMSIs""" - - def validate(self, document): - """Specifically validate the string is a JSON parsable list of records""" - imsi = None - try: - imsi = json.loads(document.text) - except Exception as err: # pragma: no cover - raise ValidationError( - message='Not valid JSON', - cursor_position=len(document.text)) from err # pragma: no cover - if not isinstance(imsi, list): - raise ValidationError( - message='Must be a list of IMSI records', - cursor_position=len(document.text)) # pragma: no cover +from inquirer.errors import ValidationError + +def validate_number (answers, current): + """Specifically validate the string is a number between 0 and 66535""" + try: + int(current) + except ValueError as value_error: # pragma: no cover + raise ValidationError( "", + reason='Please enter a number') from value_error # pragma: no cover + if int(current) < 0 or int(current) > 65535: + raise ValidationError( "", + reason='Please enter a number between 0 and 65535') # pragma: no cover + +def validate_mcc(answers, current): + """Specifically validate the string is a number between 000 and 999""" + try: + int(current.lstrip('0')) + except ValueError as value_error: # pragma: no cover + raise ValidationError("", + reason='Please enter a number') from value_error # pragma: no cover + if int(current.lstrip('0')) < 0 or int(current.lstrip('0')) > 999 or len(current) != 3: + raise ValidationError("", + reason='Please enter a number between 000 and 999') # pragma: no cover + +def validate_mnc(answers, current): + """Specifically validate the string is a number between 00 and 99""" + try: + int(current.lstrip('0')) + except ValueError as value_error: # pragma: no cover + raise ValidationError("", + reason='Please enter a number') from value_error # pragma: no cover + if int(current.lstrip('0')) < 0 or int(current.lstrip('0')) > 99 or len(current) != 2: + raise ValidationError("", + reason='Please enter a number between 00 and 99') # pragma: no cover + +def validate_imsi(answers, current): + """Specifically validate the string is a JSON parsable list of records""" + imsi = None + try: + imsi = json.loads(current) + except Exception as err: # pragma: no cover + raise ValidationError("", + reason='Not valid JSON') from err # pragma: no cover + if not isinstance(imsi, list): + raise ValidationError("", + reason='Must be a list of IMSI records') # pragma: no cover From 32dea6694306e4c42619646bfdc5c8abb17dd531 Mon Sep 17 00:00:00 2001 From: Ryan Date: Fri, 22 Jul 2022 15:25:45 -0400 Subject: [PATCH 04/11] convert questions --- blue/5G/daedalus/daedalus.py | 135 ++++++++++++++++------------------- 1 file changed, 63 insertions(+), 72 deletions(-) diff --git a/blue/5G/daedalus/daedalus.py b/blue/5G/daedalus/daedalus.py index b0382126..cab81282 100644 --- a/blue/5G/daedalus/daedalus.py +++ b/blue/5G/daedalus/daedalus.py @@ -12,10 +12,10 @@ import docker as dclient from daedalus import __file__ from daedalus import __version__ -from daedalus.validators import IMSIValidator -from daedalus.validators import MCCValidator -from daedalus.validators import MNCValidator -from daedalus.validators import NumberValidator +from daedalus.validators import validate_imsi +from daedalus.validators import validate_mcc +from daedalus.validators import validate_mnc +from daedalus.validators import validate_number from daedalus.styles import custom_style from plumbum import FG # pytype: disable=import-error from plumbum import local # pytype: disable=import-error @@ -31,7 +31,7 @@ from plumbum.cmd import rm # pytype: disable=import-error from plumbum.cmd import sudo # pytype: disable=import-error from plumbum.cmd import tar # pytype: disable=import-error -from inquirer import prompt, Checkbox, Editor, List +from inquirer import prompt, Checkbox, Editor, List, Text level_int = {'CRITICAL': 50, 'ERROR': 40, 'WARNING': 30, 'INFO': 20, @@ -308,56 +308,50 @@ def main_questions(): def global_number_questions(enb): """Ask which codes to use""" return [ - { - 'type': 'input', - 'name': 'mcc', - 'message': f'What MCC code for {enb} would you like?', - 'default': '001', - 'validate': MCCValidator(), - }, - { - 'type': 'input', - 'name': 'mnc', - 'message': f'What MNC code for {enb} would you like?', - 'default': '01', - 'validate': MNCValidator(), - }, + Text( + 'mcc', + message = f'What MCC code for {enb} would you like?', + default = '001', + validate = validate_mcc, + ), + Text( + 'mnc', + message = f'What MNC code for {enb} would you like?', + default = '01', + validate = validate_mnc, + ), ] @staticmethod def sdr_questions(enb): """Ask SDR specific questions""" return [ - { - 'type': 'list', - 'name': 'prb', - 'message': f'Number of Physical Resource Blocks (PRB) for {enb}', - 'choices': ['6', '15', '25', '50', '75', '100'], - 'default': '50', - }, - { - 'type': 'input', - 'name': 'earfcn', - 'message': f'What EARFCN code for DL for {enb} would you like?', - 'default': '3400', + List( + 'prb', + message = f'Number of Physical Resource Blocks (PRB) for {enb}', + choices = ['6', '15', '25', '50', '75', '100'], + default = '50', + ), + Text( + 'earfcn', + message = f'What EARFCN code for DL for {enb} would you like?', + default = '3400', # TODO should also validate the EARFCN wasn't already used - 'validate': NumberValidator(), - 'filter': lambda val: int(val), - }, - { - 'type': 'input', - 'name': 'txgain', - 'message': f'What TX gain value for {enb} would you like?', - 'default': '80', - 'validate': NumberValidator(), - }, - { + validate = validate_number, + ), + Text( + 'txgain', + message = f'What TX gain value for {enb} would you like?', + default = '80', + validate = validate_number, + ), + Text( 'type': 'input', 'name': 'rxgain', - 'message': f'What RX gain value for {enb} would you like?', - 'default': '40', - 'validate': NumberValidator(), - }, + message = f'What RX gain value for {enb} would you like?', + default = '40', + validate = validate_number, + ), ] @staticmethod @@ -420,39 +414,36 @@ def imsi_questions(): }]''') return [ - { - 'type': 'editor', - 'name': 'imsi', - 'message': 'Add a new IMSI (an example will be prepopulated to get you started)', - 'default': f'{json.dumps(example_imsi, indent=2)}', - 'eargs': { - 'editor': 'nano', - 'ext': '.json', - }, - 'validate': IMSIValidator(), - }, - { - 'type': 'confirm', - 'message': 'Would you like to add another IMSI?', - 'name': 'add_imsi', - 'default': False, - }, + Editor( + 'imsi', + message = 'Add a new IMSI (an example will be prepopulated to get you started)', + default = f'{json.dumps(example_imsi, indent=2)}', + # 'eargs': { + # 'editor': 'nano', + # 'ext': '.json', + # }, + validate = validate_imsi, + ), + Confirm( + 'add_imsi', + message = 'Would you like to add another IMSI?', + default = False, + ), ] @staticmethod def running_questions(): """Once services are running, ask questions of what to do next""" return [ - { - 'type': 'list', - 'name': 'actions', - 'message': 'Services have started, what would you like to do?', - 'choices': [ - {'name': 'Follow logs (Ctrl-c to return to this menu)', 'value': 'Follow logs (Ctrl-c to return to this menu)'}, - {'name': 'Remove services', 'value': 'Remove services'}, - {'name': 'Quit (services that were not removed will continue to run)', 'value': 'Quit (services that were not removed will continue to run)'}, + List( + 'actions', + message = 'Services have started, what would you like to do?', + choices = [ + 'Follow logs (Ctrl-c to return to this menu)', + 'Remove services', + 'Quit (services that were not removed will continue to run)', ], - }, + ), ] def cleanup(self): From d4426dd7745d0fe86aa211b358c6a81b1bea4542 Mon Sep 17 00:00:00 2001 From: Ryan Date: Fri, 22 Jul 2022 15:55:08 -0400 Subject: [PATCH 05/11] working except editor --- blue/5G/daedalus/daedalus.py | 7 +++---- blue/5G/daedalus/validators.py | 4 ++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/blue/5G/daedalus/daedalus.py b/blue/5G/daedalus/daedalus.py index cab81282..edf27348 100644 --- a/blue/5G/daedalus/daedalus.py +++ b/blue/5G/daedalus/daedalus.py @@ -31,7 +31,7 @@ from plumbum.cmd import rm # pytype: disable=import-error from plumbum.cmd import sudo # pytype: disable=import-error from plumbum.cmd import tar # pytype: disable=import-error -from inquirer import prompt, Checkbox, Editor, List, Text +from inquirer import prompt, Checkbox, Confirm, Editor, List, Text level_int = {'CRITICAL': 50, 'ERROR': 40, 'WARNING': 30, 'INFO': 20, @@ -285,7 +285,7 @@ def main_questions(): '5G Open5GS Core (NRF, AUSF, NSSF, UDM, BSF, PCF, UDR, AMF)', '5G UERANSIM gNodeB (gNB)', '4G srsRAN eNodeB (eNB)', - '5G srsRAN NSA gNodeB (gNB)' + '5G srsRAN NSA gNodeB (gNB)', '4G BladeRF eNodeB (eNB)', '4G Ettus USRP B2xx eNodeB (eNB)', '5G Ettus USRP B2xx NSA gNodeB (gNB)', @@ -346,8 +346,7 @@ def sdr_questions(enb): validate = validate_number, ), Text( - 'type': 'input', - 'name': 'rxgain', + 'rxgain', message = f'What RX gain value for {enb} would you like?', default = '40', validate = validate_number, diff --git a/blue/5G/daedalus/validators.py b/blue/5G/daedalus/validators.py index ace5a80c..b2cfe81f 100644 --- a/blue/5G/daedalus/validators.py +++ b/blue/5G/daedalus/validators.py @@ -15,6 +15,7 @@ def validate_number (answers, current): if int(current) < 0 or int(current) > 65535: raise ValidationError( "", reason='Please enter a number between 0 and 65535') # pragma: no cover + return True def validate_mcc(answers, current): """Specifically validate the string is a number between 000 and 999""" @@ -26,6 +27,7 @@ def validate_mcc(answers, current): if int(current.lstrip('0')) < 0 or int(current.lstrip('0')) > 999 or len(current) != 3: raise ValidationError("", reason='Please enter a number between 000 and 999') # pragma: no cover + return True def validate_mnc(answers, current): """Specifically validate the string is a number between 00 and 99""" @@ -37,6 +39,7 @@ def validate_mnc(answers, current): if int(current.lstrip('0')) < 0 or int(current.lstrip('0')) > 99 or len(current) != 2: raise ValidationError("", reason='Please enter a number between 00 and 99') # pragma: no cover + return True def validate_imsi(answers, current): """Specifically validate the string is a JSON parsable list of records""" @@ -49,3 +52,4 @@ def validate_imsi(answers, current): if not isinstance(imsi, list): raise ValidationError("", reason='Must be a list of IMSI records') # pragma: no cover + return True From 7df72da42655fdc14ccd2fe00e9c7372555242e6 Mon Sep 17 00:00:00 2001 From: Ryan Date: Fri, 22 Jul 2022 15:57:48 -0400 Subject: [PATCH 06/11] try without loading as json --- blue/5G/daedalus/daedalus.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/blue/5G/daedalus/daedalus.py b/blue/5G/daedalus/daedalus.py index edf27348..07958eaf 100644 --- a/blue/5G/daedalus/daedalus.py +++ b/blue/5G/daedalus/daedalus.py @@ -356,7 +356,7 @@ def sdr_questions(enb): @staticmethod def imsi_questions(): """Ask IMSI specific questions""" - example_imsi = json.loads('''[{ + example_imsi = '''[{ "access_restriction_data": 32, "ambr": { "downlink": { @@ -410,7 +410,7 @@ def imsi_questions(): ], "subscribed_rau_tau_timer": 12, "subscriber_status": 0 - }]''') + }]''' return [ Editor( From 2745606cefc18d7a14c3dbdc74efdee3112cc687 Mon Sep 17 00:00:00 2001 From: Ryan Date: Sat, 23 Jul 2022 08:22:09 -0400 Subject: [PATCH 07/11] editor working properly --- blue/5G/daedalus/daedalus.py | 51 ++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/blue/5G/daedalus/daedalus.py b/blue/5G/daedalus/daedalus.py index 07958eaf..479d0146 100644 --- a/blue/5G/daedalus/daedalus.py +++ b/blue/5G/daedalus/daedalus.py @@ -356,67 +356,68 @@ def sdr_questions(enb): @staticmethod def imsi_questions(): """Ask IMSI specific questions""" - example_imsi = '''[{ + example_imsi = '''[{{ "access_restriction_data": 32, - "ambr": { - "downlink": { + "ambr": {{ + "downlink": {{ "unit": 3, "value": 1 - }, - "uplink": { + }}, + "uplink": {{ "unit": 3, "value": 1 - } - }, + }} + }}, "imsi": "001010000000012", "network_access_mode": 2, - "security": { + "security": {{ "amf": "8000", "k": "c8eba87c1074edd06885cb0486718341", "op": null, "opc": "17b6c0157895bcaa1efc1cef55033f5f" - }, + }}, "slice": [ - { + {{ "default_indicator": true, "sd": "000000", "session": [ - { - "ambr": { - "downlink": { + {{ + "ambr": {{ + "downlink": {{ "unit": 3, "value": 1 - }, - "uplink": { + }}, + "uplink": {{ "unit": 3, "value": 1 - } - }, + }} + }}, "name": "internet", "pcc_rule": [], - "qos": { - "arp": { + "qos": {{ + "arp": {{ "pre_emption_capability": 1, "pre_emption_vulnerability": 1, "priority_level": 8 - }, + }}, "index": 9 - }, + }}, "type": 1 - } + }} ], "sst": 1 - } + }} ], "subscribed_rau_tau_timer": 12, "subscriber_status": 0 - }]''' + }}]''' return [ Editor( 'imsi', message = 'Add a new IMSI (an example will be prepopulated to get you started)', - default = f'{json.dumps(example_imsi, indent=2)}', + default = example_imsi, + #default = f'{json.dumps(json.dumps(example_imsi, indent=2))}', # 'eargs': { # 'editor': 'nano', # 'ext': '.json', From e9a627202d7946b7d076bbe781d3bc5d64794209 Mon Sep 17 00:00:00 2001 From: Ryan Date: Sat, 23 Jul 2022 09:35:56 -0400 Subject: [PATCH 08/11] first shot at themeing --- blue/5G/daedalus/daedalus.py | 2 +- blue/5G/daedalus/styles.py | 37 +++++++++++++++++++++++++++--------- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/blue/5G/daedalus/daedalus.py b/blue/5G/daedalus/daedalus.py index 479d0146..cdb6b67c 100644 --- a/blue/5G/daedalus/daedalus.py +++ b/blue/5G/daedalus/daedalus.py @@ -269,7 +269,7 @@ def execute_prompt(questions): Run end user prompt with supplied questions and return the selected answers """ - answers = prompt(questions) #, theme=custom_style) + answers = prompt(questions theme=custom_style) return answers @staticmethod diff --git a/blue/5G/daedalus/styles.py b/blue/5G/daedalus/styles.py index a189b0da..beebe742 100644 --- a/blue/5G/daedalus/styles.py +++ b/blue/5G/daedalus/styles.py @@ -1,9 +1,28 @@ -custom_style = { #get_style({ - "separator": '#6C6C6C', - "questionmark": '#FF9D00 bold', - "selected": '#5F819D', - "pointer": '#FF9D00 bold', - #"instruction": '', # default - "answer": '#5F819D bold', - #"question": '', -} #, style_override=False) +# custom_style = { #get_style({ +# "separator": '#6C6C6C', +# "questionmark": '#FF9D00 bold', +# "selected": '#5F819D', +# "pointer": '#FF9D00 bold', +# #"instruction": '', # default +# "answer": '#5F819D bold', +# #"question": '', +# } #, style_override=False) + +custom_style = { + "Question": { + "mark_color": "orange bold", + "brackets_color": "orange bold", + }, + "Checkbox": { + "selection_color": "lightskyblue3", + "selection_icon": "❯" + "selected_icon": "◉" + "selected_color": "lightskyblue3" + "unselected_color": "normal" + "unselected_icon": "◯" + }, + "List"{ + "selection_cursor": "❯" + "selection_color": "lightskyblue3" + } +} \ No newline at end of file From e0bb43e08722ac8081eaf7feef1a9d46e196c6b7 Mon Sep 17 00:00:00 2001 From: Ryan Date: Sat, 23 Jul 2022 10:45:01 -0400 Subject: [PATCH 09/11] styles working but not the right colors --- blue/5G/daedalus/daedalus.py | 2 +- blue/5G/daedalus/styles.py | 28 +++++++++++++++------------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/blue/5G/daedalus/daedalus.py b/blue/5G/daedalus/daedalus.py index cdb6b67c..5a7dc157 100644 --- a/blue/5G/daedalus/daedalus.py +++ b/blue/5G/daedalus/daedalus.py @@ -269,7 +269,7 @@ def execute_prompt(questions): Run end user prompt with supplied questions and return the selected answers """ - answers = prompt(questions theme=custom_style) + answers = prompt(questions, theme=custom_style) return answers @staticmethod diff --git a/blue/5G/daedalus/styles.py b/blue/5G/daedalus/styles.py index beebe742..499630a8 100644 --- a/blue/5G/daedalus/styles.py +++ b/blue/5G/daedalus/styles.py @@ -1,3 +1,4 @@ +from inquirer.themes import load_theme_from_dict # custom_style = { #get_style({ # "separator": '#6C6C6C', # "questionmark": '#FF9D00 bold', @@ -8,21 +9,22 @@ # #"question": '', # } #, style_override=False) -custom_style = { +custom_style = load_theme_from_dict({ "Question": { - "mark_color": "orange bold", - "brackets_color": "orange bold", + "mark_color": "darkorange_bold", + "brackets_color": "darkorange_bold", + "default_color": "darkorange" }, "Checkbox": { - "selection_color": "lightskyblue3", - "selection_icon": "❯" - "selected_icon": "◉" - "selected_color": "lightskyblue3" - "unselected_color": "normal" - "unselected_icon": "◯" + "selection_color": "bright_black", + "selection_icon": "❯", + "selected_icon": "◉", + "selected_color": "bright_black", + "unselected_color": "normal", + "unselected_icon": "◯", }, - "List"{ - "selection_cursor": "❯" - "selection_color": "lightskyblue3" + "List": { + "selection_cursor": "❯", + "selection_color": "lightblue", } -} \ No newline at end of file +}) From 1aa826e95088cfa97a16e1cc73a53fc93e6d510a Mon Sep 17 00:00:00 2001 From: Ryan Date: Sun, 24 Jul 2022 08:11:45 -0400 Subject: [PATCH 10/11] move theme from dict to class --- blue/5G/daedalus/styles.py | 61 +++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 20 deletions(-) diff --git a/blue/5G/daedalus/styles.py b/blue/5G/daedalus/styles.py index 499630a8..3f768a84 100644 --- a/blue/5G/daedalus/styles.py +++ b/blue/5G/daedalus/styles.py @@ -1,4 +1,9 @@ -from inquirer.themes import load_theme_from_dict +from blessed import Terminal +from inquirer.themes import Theme + +term = Terminal() + +# from inquirer.themes import load_theme_from_dict # custom_style = { #get_style({ # "separator": '#6C6C6C', # "questionmark": '#FF9D00 bold', @@ -9,22 +14,38 @@ # #"question": '', # } #, style_override=False) -custom_style = load_theme_from_dict({ - "Question": { - "mark_color": "darkorange_bold", - "brackets_color": "darkorange_bold", - "default_color": "darkorange" - }, - "Checkbox": { - "selection_color": "bright_black", - "selection_icon": "❯", - "selected_icon": "◉", - "selected_color": "bright_black", - "unselected_color": "normal", - "unselected_icon": "◯", - }, - "List": { - "selection_cursor": "❯", - "selection_color": "lightblue", - } -}) +# custom_style = load_theme_from_dict({ +# "Question": { +# "mark_color": "darkorange_bold", +# "brackets_color": "darkorange_bold", +# "default_color": "darkorange" +# }, +# "Checkbox": { +# "selection_color": "bright_black", +# "selection_icon": "❯", +# "selected_icon": "◉", +# "selected_color": "bright_black", +# "unselected_color": "normal", +# "unselected_icon": "◯", +# }, +# "List": { +# "selection_cursor": "❯", +# "selection_color": "lightblue", +# } +# }) + +class custom_style(Theme): + def __init__(self): + super().__init__() + self.Question.mark_color = term.darkorange_bold + self.Question.brackets_color = term.darkorange_bold + self.Question.default_color = term.darkorange_bold + self.Checkbox.selection_color = term.bold_black_on_bright_green + self.Checkbox.selection_icon = "❯" + self.Checkbox.selected_icon = "◉" + self.Checkbox.selected_color = term.lightskyblue4 + self.Checkbox.unselected_color = term.normal + self.Checkbox.unselected_icon = "◯" + self.List.selection_color = term.lightskyblue4: + self.List.selection_cursor = "❯" + self.List.unselected_color = term.normal From d08d4bb4863d83a856d3792dfb26996acde0d25e Mon Sep 17 00:00:00 2001 From: Ryan Date: Sun, 24 Jul 2022 08:50:37 -0400 Subject: [PATCH 11/11] styles looking right now --- blue/5G/daedalus/daedalus.py | 2 +- blue/5G/daedalus/styles.py | 42 ++++++------------------------------ 2 files changed, 7 insertions(+), 37 deletions(-) diff --git a/blue/5G/daedalus/daedalus.py b/blue/5G/daedalus/daedalus.py index 5a7dc157..9879cd4b 100644 --- a/blue/5G/daedalus/daedalus.py +++ b/blue/5G/daedalus/daedalus.py @@ -269,7 +269,7 @@ def execute_prompt(questions): Run end user prompt with supplied questions and return the selected answers """ - answers = prompt(questions, theme=custom_style) + answers = prompt(questions, theme=custom_style()) return answers @staticmethod diff --git a/blue/5G/daedalus/styles.py b/blue/5G/daedalus/styles.py index 3f768a84..ba8cc98c 100644 --- a/blue/5G/daedalus/styles.py +++ b/blue/5G/daedalus/styles.py @@ -3,49 +3,19 @@ term = Terminal() -# from inquirer.themes import load_theme_from_dict -# custom_style = { #get_style({ -# "separator": '#6C6C6C', -# "questionmark": '#FF9D00 bold', -# "selected": '#5F819D', -# "pointer": '#FF9D00 bold', -# #"instruction": '', # default -# "answer": '#5F819D bold', -# #"question": '', -# } #, style_override=False) - -# custom_style = load_theme_from_dict({ -# "Question": { -# "mark_color": "darkorange_bold", -# "brackets_color": "darkorange_bold", -# "default_color": "darkorange" -# }, -# "Checkbox": { -# "selection_color": "bright_black", -# "selection_icon": "❯", -# "selected_icon": "◉", -# "selected_color": "bright_black", -# "unselected_color": "normal", -# "unselected_icon": "◯", -# }, -# "List": { -# "selection_cursor": "❯", -# "selection_color": "lightblue", -# } -# }) - class custom_style(Theme): def __init__(self): super().__init__() - self.Question.mark_color = term.darkorange_bold - self.Question.brackets_color = term.darkorange_bold - self.Question.default_color = term.darkorange_bold - self.Checkbox.selection_color = term.bold_black_on_bright_green + self.Question.mark_color = term.darkorange + term.bold + self.Question.brackets_color = term.darkorange + term.bold + self.Question.default_color = term.darkorange + term.bold + self.Checkbox.selection_color = term.lightskyblue4 self.Checkbox.selection_icon = "❯" self.Checkbox.selected_icon = "◉" self.Checkbox.selected_color = term.lightskyblue4 self.Checkbox.unselected_color = term.normal self.Checkbox.unselected_icon = "◯" - self.List.selection_color = term.lightskyblue4: + self.List.selection_color = term.lightskyblue4 self.List.selection_cursor = "❯" self.List.unselected_color = term.normal + self.Editor.opening_prompt_color = term.lightskyblue4