Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy button in the terminal #177 #186

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 57 additions & 2 deletions dynamic/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Fixed Show fixed Hide fixed
width = os.get_terminal_size().columns
console = Console(width=width - 4)
markdown = Markdown(body_markdown, hyperlinks=False)
Expand Down Expand Up @@ -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]
Expand All @@ -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 + "'''"
Fixed Show fixed Hide fixed
# to avoid situstion where text break due to any other colons in the middle
while i <len(self.dbmd):
counter = 0
if self.dbmd[i] == " ":
while i<len(self.dbmd) :
if self.dbmd[i] == " ":
if counter == 4:
break
counter +=1
i += 1
else:
break
# checks if there are 4 spaces, the basic format for a markdown code input
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)):
code += self.dbmd[i]
#the word attach to the code variable
i += 1
while True:
while(self.dbmd[i] == '\n' or self.dbmd[i] == '\r'):
code += self.dbmd[i]
i+=1
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
else:
break
i += 1
if flag:

Check notice

Code scanning

Trailing whitespace

Trailing whitespace
#breaks if code is finished
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]
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
pytest==7.1.1
pyperclip==1.8.2