From cf21b69a8572010cd6054a96774c1dc0545f8dbf Mon Sep 17 00:00:00 2001 From: Steve Date: Sat, 30 Jul 2022 16:12:04 +0530 Subject: [PATCH 1/9] Copy button in the terminal #177 --- dynamic/utility.py | 47 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/dynamic/utility.py b/dynamic/utility.py index 9faf891..1f31330 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 @@ -14,7 +15,7 @@ from error import SearchError from save import SaveSearchResults -from markdown import MarkdownRenderer +# from markdown import MarkdownRenderer from settings import PLAYBOOK_FILE # Required for OAuth @@ -246,6 +247,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 +279,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 +313,44 @@ 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 = "" + i = 0 + flag = False + self.dbmd = "'''" + self.dbmd + "'''" + while i 0) and (counter % 4 == 0): + flag = True + while((self.dbmd[i] != '\n' and self.dbmd[i] != '\r') and i+1 < len(self.dbmd) ): + code += self.dbmd[i] + i += 1 + while(True): + b = self.dbmd[i] + while(self.dbmd[i] == '\n' or self.dbmd[i] == '\r'): + code += self.dbmd[i] + i+=1 + b = self.dbmd[i] + if self.dbmd[i] == " " and self.dbmd[i+1] == " " and self.dbmd[i+2] == " " and self.dbmd[i+3] == " ": + i += 4 + while((self.dbmd[i] != '\n' and self.dbmd[i] != '\r') and i+1 < len(self.dbmd) ): + code += self.dbmd[i] + i += 1 + else: + break + i += 1 + if flag: + break + pc.copy(code) + console.print("\nCopied Sucessfully !!\n") elif question_menu.chosen_accept_key == "d" and playbook: self.playbook.delete_from_playbook( self, self.questions_data[options_index][1] From 9cea8ec19def2da73f490eaa45b1ef257d54925a Mon Sep 17 00:00:00 2001 From: Steve Date: Sat, 30 Jul 2022 16:14:10 +0530 Subject: [PATCH 2/9] Copy button in the terminal #177 (update) --- dynamic/utility.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dynamic/utility.py b/dynamic/utility.py index 1f31330..6a072b5 100644 --- a/dynamic/utility.py +++ b/dynamic/utility.py @@ -15,7 +15,7 @@ from error import SearchError from save import SaveSearchResults -# from markdown import MarkdownRenderer +from markdown import MarkdownRenderer from settings import PLAYBOOK_FILE # Required for OAuth From bafd9555acc0840f4735f4308e0230a0b1cc979f Mon Sep 17 00:00:00 2001 From: Steve Date: Sat, 30 Jul 2022 16:22:20 +0530 Subject: [PATCH 3/9] Copy button in the terminal #177 (Update_2) --- requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 789cf30..4ba1654 100644 --- a/requirements.txt +++ b/requirements.txt @@ -13,4 +13,5 @@ crayons==0.4.0 selenium==3.141.0 webdriver-manager==3.3.0 simple-term-menu==1.0.1 -pytest==7.1.1 \ No newline at end of file +pytest==7.1.1 +pyperclip==1.8.2 \ No newline at end of file From 19063e2242c1de88c317b83bd69c0eff11cfe3d0 Mon Sep 17 00:00:00 2001 From: Steve Date: Sat, 30 Jul 2022 16:32:10 +0530 Subject: [PATCH 4/9] Copy button in the terminal #177 (Update_3) --- dynamic/utility.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/dynamic/utility.py b/dynamic/utility.py index 6a072b5..51f03c2 100644 --- a/dynamic/utility.py +++ b/dynamic/utility.py @@ -314,12 +314,12 @@ def navigate_questions_panel(self, playbook=False): self, self.questions_data[options_index][1] ) elif question_menu.chosen_accept_key == "c": - code = "" + code = "" # "code" will be edited later i = 0 flag = False - self.dbmd = "'''" + self.dbmd + "'''" + self.dbmd = "'''" + self.dbmd + "'''" + #to avoid situstion where text break due to any other colons in the middle while i 0) and (counter % 4 == 0): flag = True + # once code beginning is found we go till the end of that code only and stop where that snippet stops while((self.dbmd[i] != '\n' and self.dbmd[i] != '\r') and i+1 < len(self.dbmd) ): code += self.dbmd[i] + #the word attach to the code variable i += 1 while(True): - b = self.dbmd[i] while(self.dbmd[i] == '\n' or self.dbmd[i] == '\r'): code += self.dbmd[i] i+=1 - b = self.dbmd[i] if self.dbmd[i] == " " and self.dbmd[i+1] == " " and self.dbmd[i+2] == " " and self.dbmd[i+3] == " ": i += 4 + #checks if the next 4 spots are spaces aswell indicating continuation of snippet while((self.dbmd[i] != '\n' and self.dbmd[i] != '\r') and i+1 < len(self.dbmd) ): code += self.dbmd[i] i += 1 @@ -348,6 +350,7 @@ def navigate_questions_panel(self, playbook=False): break i += 1 if flag: + #breaks if code is finished break pc.copy(code) console.print("\nCopied Sucessfully !!\n") From 502f23010e4d89c01b0248467db5aae11718e2db Mon Sep 17 00:00:00 2001 From: Steve Date: Sat, 30 Jul 2022 16:41:19 +0530 Subject: [PATCH 5/9] Copy button in the terminal #177 (Update_4) --- dynamic/utility.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/dynamic/utility.py b/dynamic/utility.py index 51f03c2..0d0e488 100644 --- a/dynamic/utility.py +++ b/dynamic/utility.py @@ -15,7 +15,7 @@ from error import SearchError from save import SaveSearchResults -from markdown import MarkdownRenderer +# from markdown import MarkdownRenderer from settings import PLAYBOOK_FILE # Required for OAuth @@ -324,12 +324,14 @@ def navigate_questions_panel(self, playbook=False): if self.dbmd[i] == " ": while(i0) and (counter % 4 == 0): + if counter == 4: flag = True # once code beginning is found we go till the end of that code only and stop where that snippet stops while((self.dbmd[i] != '\n' and self.dbmd[i] != '\r') and i+1 < len(self.dbmd) ): From dc1082878c81bae706877d652ea560596876a0f4 Mon Sep 17 00:00:00 2001 From: Steve Date: Sat, 30 Jul 2022 16:45:51 +0530 Subject: [PATCH 6/9] Copy button in the terminal #177 (Update_5) --- dynamic/utility.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dynamic/utility.py b/dynamic/utility.py index 0d0e488..d9d4bc6 100644 --- a/dynamic/utility.py +++ b/dynamic/utility.py @@ -15,7 +15,7 @@ from error import SearchError from save import SaveSearchResults -# from markdown import MarkdownRenderer +from markdown import MarkdownRenderer from settings import PLAYBOOK_FILE # Required for OAuth From c8856614760609c5d65df67ee79acf11c16bd730 Mon Sep 17 00:00:00 2001 From: Steve Date: Sat, 30 Jul 2022 16:55:08 +0530 Subject: [PATCH 7/9] Copy button in the terminal #177 (Update_6) --- dynamic/utility.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dynamic/utility.py b/dynamic/utility.py index d9d4bc6..b49f92b 100644 --- a/dynamic/utility.py +++ b/dynamic/utility.py @@ -317,7 +317,7 @@ def navigate_questions_panel(self, playbook=False): code = "" # "code" will be edited later i = 0 flag = False - self.dbmd = "'''" + self.dbmd + "'''" + self.dbmd = "'''" + self.dbmd + "'''" #to avoid situstion where text break due to any other colons in the middle while i Date: Mon, 1 Aug 2022 17:39:34 +0530 Subject: [PATCH 8/9] dynamic/utility.py -> pylint --- dynamic/utility.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/dynamic/utility.py b/dynamic/utility.py index b49f92b..5876d19 100644 --- a/dynamic/utility.py +++ b/dynamic/utility.py @@ -318,11 +318,11 @@ def navigate_questions_panel(self, playbook=False): i = 0 flag = False self.dbmd = "'''" + self.dbmd + "'''" - #to avoid situstion where text break due to any other colons in the middle + # to avoid situstion where text break due to any other colons in the middle while i Date: Mon, 1 Aug 2022 17:43:09 +0530 Subject: [PATCH 9/9] dynamic/utility.py -> pylint update_1 --- dynamic/utility.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dynamic/utility.py b/dynamic/utility.py index 5876d19..9c6cacf 100644 --- a/dynamic/utility.py +++ b/dynamic/utility.py @@ -184,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