diff --git a/dynamic/utility.py b/dynamic/utility.py index 9faf891..9c6cacf 100644 --- a/dynamic/utility.py +++ b/dynamic/utility.py @@ -3,6 +3,7 @@ from rich.console import Console from rich.markdown import Markdown import sys as sys +import pyperclip as pc # Required for Questions Panel import os @@ -183,6 +184,9 @@ def __init__(self): self.utility = Utility() self.playbook = Playbook() + # setting default value of variable dbmd + self.dbmd = "" + def populate_question_data(self, questions_list): """ Function to populate question data property @@ -246,6 +250,7 @@ def return_formatted_ans(self, ques_id): ] for convert_from, convert_to in xml_markup_replacement: body_markdown = body_markdown.replace(convert_from, convert_to) + self.dbmd = body_markdown width = os.get_terminal_size().columns console = Console(width=width - 4) markdown = Markdown(body_markdown, hyperlinks=False) @@ -277,16 +282,17 @@ def navigate_questions_panel(self, playbook=False): if playbook: message = "Playbook Questions" instructions = ". Press 'd' to delete from playbook" - keys = ("enter", "d") + keys = ("enter", "d", "c") else: message = "Relevant Questions" instructions = ". Press 'p' to save in playbook" - keys = ("enter", "p") + keys = ("enter", "p", "c") console.rule("[bold blue] {}".format(message), style="bold red") console.print( "[yellow] Use arrow keys to navigate." + "'q' or 'Esc' to quit. 'Enter' to open in a browser" + instructions + +". Press 'c' to Copy Code" ) console.print() options = ["|".join(map(str, question)) for question in self.questions_data] @@ -310,6 +316,55 @@ def navigate_questions_panel(self, playbook=False): self.playbook.add_to_playbook( self, self.questions_data[options_index][1] ) + elif question_menu.chosen_accept_key == "c": + code = "" # "code" will be edited later + i = 0 + flag = False + self.dbmd = "'''" + self.dbmd + "'''" + # to avoid situstion where text break due to any other colons in the middle + while i