Python prompt_toolkit.HTML Examples
The following are 30
code examples of prompt_toolkit.HTML().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
prompt_toolkit
, or try the search function
.
Example #1
Source File: device.py From Facedancer with BSD 3-Clause "New" or "Revised" License | 6 votes |
def print_suggested_additions(self): """ Prints a collection of suggested additions to the stdout. """ sys.stdout.flush() sys.stderr.flush() # Create a quick printing shortcut. print_html = lambda data : print_formatted_text(HTML(data)) # Header. print_html("") print_html("<b><u>Automatic Suggestions</u></b>") print_html("These suggestions are based on simple observed behavior;") print_html("not all of these suggestions may be useful / desireable.") print_html("") self._print_suggested_requests() print_html("") # # Backend helpers. #
Example #2
Source File: qr_reader.py From HomePWN with GNU General Public License v3.0 | 6 votes |
def display_qr(qr_read, verbose): """QR util method to display Args: qr_read ([Reg]): Data of the qr read verbose (Boolean): To display mor info """ color = ColorSelected().theme.confirm print(color) print_ok_raw(f"Found {len(qr_read)} registries") for idx, reg in enumerate(qr_read): print_info(f"==== Reg {idx} ====") print_formatted_text(HTML(f"<{color}>Data:</{color}> {reg.data}")) if(verbose): print_formatted_text(HTML(f"<{color}>Type:</{color}> {reg.type}")) print_formatted_text(HTML(f"<{color}>Rect:</{color}> {reg.rect}")) print_formatted_text(HTML(f"<{color}>Polygon:</{color}> {reg.polygon}"))
Example #3
Source File: read-pcap.py From HomePWN with GNU General Public License v3.0 | 6 votes |
def _show_range_packets(self, packets, limit): msg = "--show more-- (press q to exit)" count = 0 for p in packets: count += 1 if count == limit: count = 0 print_formatted_text(HTML(f"<jj bg='ansiyellow'>{msg}</jj>"), end="") res = readchar.readchar() # Deletes the last line print("\033[A") print(" "*len(msg)) print("\033[A") if res.lower() == "q": print("") return p.show()
Example #4
Source File: _module.py From HomePWN with GNU General Public License v3.0 | 6 votes |
def _print_options(self): print_formatted_text(HTML(f"<{ColorSelected().theme.accent}> Options (Field = Value)</{ColorSelected().theme.accent}>")) print (" -----------------------") flag = True options_aux = self.get_options() if not len(options_aux): print_info(" No options to configure") return for key, option in options_aux.items(): if flag: print (" |") flag = False # Parameter is mandataroy if option.required: self._print_mandatory_option(key, option) # Parameter is optional else: self._print_optional_option(key, option) print ("\n")
Example #5
Source File: tasks.py From HomePWN with GNU General Public License v3.0 | 6 votes |
def show_tasks(self): if not len(self.tasks): print_info("There are no running tasks at this time") return print_formatted_text(HTML(f''' <ansiyellow> Index (Thread)</ansiyellow> -------------------------''')) flag = 0 for key, value in self.tasks.items(): pid = value.get("pid", "") if not pid: pid = "" flag += 1 alive = "Alive" if value['thread'].is_alive() else "Death" if flag > 1: print (" |") print(f" |_ {key} = {value['thread'].name} {pid} ({alive})") print("")
Example #6
Source File: prompt.py From HomePWN with GNU General Public License v3.0 | 6 votes |
def prompt(commands, module=None): """Launch the prompt with the given commands Args: commands ([str]): List of commands to autocomplete module (str, optional): Name of the module. Defaults to None. Returns: prompt session: Session of the promt """ default_prompt = "homePwn" color_default_prompt = ColorSelected().theme.primary warn = ColorSelected().theme.warn confirm = ColorSelected().theme.confirm html = HTML(f"<bold><{color_default_prompt}>{default_prompt} >></{color_default_prompt}></bold>") if module: html = HTML(f"<bold><{color_default_prompt}>{default_prompt}</{color_default_prompt}> (<{warn}>{module}</{warn}>) <{confirm}>>></{confirm}></bold> ") data = session.prompt( html, completer= CustomCompleter(commands), complete_style=CompleteStyle.READLINE_LIKE, auto_suggest=AutoSuggestFromHistory(), enable_history_search=True) return data
Example #7
Source File: __init__.py From dndme with MIT License | 5 votes |
def print(self, content): print_formatted_text(HTML(content), style=self.style)
Example #8
Source File: many-parallel-tasks.py From python-prompt-toolkit with BSD 3-Clause "New" or "Revised" License | 5 votes |
def main(): with ProgressBar( title=HTML("<b>Example of many parallel tasks.</b>"), bottom_toolbar=HTML("<b>[Control-L]</b> clear <b>[Control-C]</b> abort"), ) as pb: def run_task(label, total, sleep_time): for i in pb(range(total), label=label): time.sleep(sleep_time) threads = [ threading.Thread(target=run_task, args=("First task", 50, 0.1)), threading.Thread(target=run_task, args=("Second task", 100, 0.1)), threading.Thread(target=run_task, args=("Third task", 8, 3)), threading.Thread(target=run_task, args=("Fourth task", 200, 0.1)), threading.Thread(target=run_task, args=("Fifth task", 40, 0.2)), threading.Thread(target=run_task, args=("Sixth task", 220, 0.1)), threading.Thread(target=run_task, args=("Seventh task", 85, 0.05)), threading.Thread(target=run_task, args=("Eight task", 200, 0.05)), ] for t in threads: t.daemon = True t.start() # Wait for the threads to finish. We use a timeout for the join() call, # because on Windows, join cannot be interrupted by Control-C or any other # signal. for t in threads: while t.is_alive(): t.join(timeout=0.5)
Example #9
Source File: custom-key-bindings.py From python-prompt-toolkit with BSD 3-Clause "New" or "Revised" License | 5 votes |
def main(): bottom_toolbar = HTML( ' <b>[f]</b> Print "f" <b>[q]</b> Abort <b>[x]</b> Send Control-C.' ) # Create custom key bindings first. kb = KeyBindings() cancel = [False] @kb.add("f") def _(event): print("You pressed `f`.") @kb.add("q") def _(event): " Quit by setting cancel flag. " cancel[0] = True @kb.add("x") def _(event): " Quit by sending SIGINT to the main thread. " os.kill(os.getpid(), signal.SIGINT) # Use `patch_stdout`, to make sure that prints go above the # application. with patch_stdout(): with ProgressBar(key_bindings=kb, bottom_toolbar=bottom_toolbar) as pb: for i in pb(range(800)): time.sleep(0.01) if cancel[0]: break
Example #10
Source File: nested-progress-bars.py From python-prompt-toolkit with BSD 3-Clause "New" or "Revised" License | 5 votes |
def main(): with ProgressBar( title=HTML('<b fg="#aa00ff">Nested progress bars</b>'), bottom_toolbar=HTML(" <b>[Control-L]</b> clear <b>[Control-C]</b> abort"), ) as pb: for i in pb(range(6), label="Main task"): for j in pb( range(200), label="Subtask <%s>" % (i + 1,), remove_when_done=True ): time.sleep(0.01)
Example #11
Source File: rng.py From hermit with Apache License 2.0 | 5 votes |
def enter_randomness(chunks: int) -> bytes: """Enter a specified amount of random data The total number of bits of randomness is equal to `chunks * 256`. """ print_formatted_text(HTML(""" <b>Enter at least {} bits worth of random data.</b> Hit <b>CTRL-D</b> when done. """.format(chunks * 256))) lines: List = [] input_entropy = 0.0 output = bytes() target = 256 while True: try: prompt_msg = ( "Collected {0:5.1f} bits>:" .format(input_entropy)) line = prompt(prompt_msg).strip() except EOFError: break lines += line input_entropy = entropy(''.join(lines)) if input_entropy > target: output += hashlib.sha256(''.join(lines).encode('utf-8')).digest() target += 256 return output
Example #12
Source File: base.py From hermit with Apache License 2.0 | 5 votes |
def _confirm_create_signature(self) -> bool: self.display_request() prompt_msg = "Sign the above transaction? [y/N] " if self.session is not None: response = self.session.prompt(HTML("<b>{}</b>".format(prompt_msg))) else: response = input(prompt_msg) return response.strip().lower().startswith('y')
Example #13
Source File: base.py From hermit with Apache License 2.0 | 5 votes |
def _show_signature(self) -> None: name = self._signature_label() print_formatted_text(HTML("<i>Signature Data:</i> ")) print(json.dumps(self.signature, indent=2)) displayer.display_qr_code(self._serialized_signature(), name=name)
Example #14
Source File: shard_set.py From hermit with Apache License 2.0 | 5 votes |
def reveal_shard(self, shard_name: str) -> None: self._ensure_shards(shards_expected=True) shard = self.shards[shard_name] words = shard.encrypted_mnemonic print_formatted_text(HTML( "Encrypted SLIP39 phrase for shard <i>{}</i>:\n".format(shard_name))) print_formatted_text("\n".join(textwrap.wrap(words, 80)), "\n") self.interface.get_line_then_clear()
Example #15
Source File: interface.py From hermit with Apache License 2.0 | 5 votes |
def get_password(self, name: str) -> bytes: print_formatted_text(HTML("\nEnter password for shard {}".format(name))) pass_msg = "password> ".format(name) password = prompt(pass_msg, is_password=True).strip().encode('ascii') # Empty string means do not encrypt with a password if len(password) == 0: return None return password
Example #16
Source File: html.py From python-prompt-toolkit with BSD 3-Clause "New" or "Revised" License | 5 votes |
def title(text): print(HTML("\n<u><b>{}</b></u>").format(text))
Example #17
Source File: helpers.py From fuzzowski with GNU General Public License v2.0 | 5 votes |
def color_html(data, msg_type): if msg_type in constants.STYLE: return HTML('<{}>{}</{}>'.format(msg_type, data, msg_type)) else: return HTML(data)
Example #18
Source File: prompt.py From fuzzowski with GNU General Public License v2.0 | 5 votes |
def get_prompt(self): return HTML('<b>> </b>') # --------------------------------------------------------------- #
Example #19
Source File: prompt.py From fuzzowski with GNU General Public License v2.0 | 5 votes |
def intro_message(self): print_formatted_text(HTML('<b>Starting prompt...</b>')) # --------------------------------------------------------------- #
Example #20
Source File: prompt.py From fuzzowski with GNU General Public License v2.0 | 5 votes |
def exit_message(self): print_formatted_text(HTML('<b>Exiting prompt...</b>')) # --------------------------------------------------------------- #
Example #21
Source File: session_prompt.py From fuzzowski with GNU General Public License v2.0 | 5 votes |
def get_prompt(self): host = self.session.target.target_connection.host port = str(self.session.target.target_connection.port) return HTML('[<testn>{} of {}</testn>] ' '<b>➜</b> <host>{}</host>:<port>{}</port> $ ' .format(self.session.mutant_index, self.session.total_mutations, host, port)) # --------------------------------------------------------------- #
Example #22
Source File: session_prompt.py From fuzzowski with GNU General Public License v2.0 | 5 votes |
def _signal_handler(self, _signal, frame): self.session.is_paused = True try: print_formatted_text(HTML(' <testn>SIGINT received. Pausing fuzzing after this test case...</testn>'), style=self.get_style()) #self.logger.log_info("SIGINT received. Pausing fuzzing after this test case...") except RuntimeError: # prints are not safe in signal handlers. # This happens if the signal is catch while printing pass # --------------------------------------------------------------- #
Example #23
Source File: session_prompt.py From fuzzowski with GNU General Public License v2.0 | 5 votes |
def _print_color(self, color, message): print_formatted_text(HTML(f'<{color}>{message}</{color}>'), style=self.get_style()) # --------------------------------------------------------------- #
Example #24
Source File: session_prompt.py From fuzzowski with GNU General Public License v2.0 | 5 votes |
def _cmd_addcrash(self, tokens): try: test_case_index = int(tokens[0]) except IndexError: # No index specified, Show crashes? self._print_error('Usage: crash [TEST_ID]') return except ValueError: self._print_error('Usage: crash [TEST_ID]') return session_state = self.session.save_session_state() self.session.goto(test_case_index) if self.session.test_case is not None: poc_code = self.session.test_case.get_poc() # TODO: host,port,proto may be not available, call public functions host = self.session.target._target_connection.host port = self.session.target._target_connection.port proto = self.session.target._target_connection.proto name = self.session.test_case.short_name poc_filename = os.path.join(constants.RESULTS_DIR, f'poc_{host}_{port}_{proto}_{test_case_index}_{name}.py') print_formatted_text(HTML(f'Writing PoC to file: <testn>{poc_filename}</testn>'), style=self.get_style()) with open(poc_filename, 'w') as f: f.write(poc_code) self.session.load_session_state(session_state) # --------------------------------------------------------------- #
Example #25
Source File: session_prompt.py From fuzzowski with GNU General Public License v2.0 | 5 votes |
def intro_message(self): print_formatted_text(HTML('Fuzzing paused! Welcome to the <b>Fuzzowski Shell</b>')) # --------------------------------------------------------------- #
Example #26
Source File: session_prompt.py From fuzzowski with GNU General Public License v2.0 | 5 votes |
def exit_message(self): print_formatted_text(HTML('<b>Exiting prompt...</b>')) # --------------------------------------------------------------- #
Example #27
Source File: _module.py From HomePWN with GNU General Public License v3.0 | 5 votes |
def _print_info(self): print_formatted_text(HTML(f"<{ColorSelected().theme.accent}>Module Info</{ColorSelected().theme.accent}>")) print("===========") for key, value in self.get_info().items(): print_formatted_text(HTML(f"<{ColorSelected().theme.accent}> {key}</{ColorSelected().theme.accent}>")) print (' ' + '-' * len(key)) print (f" |_{value}\n")
Example #28
Source File: app.py From openconnect-sso with GNU General Public License v3.0 | 5 votes |
def select_profile(profile_list): selection = await radiolist_dialog( title="Select AnyConnect profile", text=HTML( "The following AnyConnect profiles are detected.\n" "The selection will be <b>saved</b> and not asked again unless the <pre>--profile-selector</pre> command line option is used" ), values=[(p, p.name) for i, p in enumerate(profile_list)], ).run_async() asyncio.get_event_loop().remove_signal_handler(signal.SIGWINCH) if not selection: return selection logger.info("Selected profile", profile=selection.name) return selection
Example #29
Source File: panctl.py From pantalaimon with Apache License 2.0 | 5 votes |
def list_servers(self): """List the daemons users.""" servers = self.ctl.ListServers() print("pantalaimon servers:") for server, server_users in servers.items(): server_c = get_color(server) print_formatted_text(HTML(f" - Name: <{server_c}>{server}</{server_c}>")) user_list = [] for user, device in server_users: user_c = get_color(user) device_c = get_color(device) user_list.append( f" - <{user_c}>{user}</{user_c}> " f"<{device_c}>{device}</{device_c}>" ) if user_list: print(" - Pan users:") user_string = "\n".join(user_list) print_formatted_text(HTML(user_string))
Example #30
Source File: panctl.py From pantalaimon with Apache License 2.0 | 5 votes |
def list_devices(self, args): devices = self.devices.ListUserDevices(args.pan_user, args.user_id) print_formatted_text(HTML(f"Devices for user <b>{args.user_id}</b>:")) for device in devices: if device["trust_state"] == "verified": trust_state = "<ansigreen>Verified</ansigreen>" elif device["trust_state"] == "blacklisted": trust_state = "<ansired>Blacklisted</ansired>" elif device["trust_state"] == "ignored": trust_state = "Ignored" else: trust_state = "Unset" key = partition_key(device["ed25519"]) color = get_color(device["device_id"]) print_formatted_text( HTML( f" - Display name: " f"{device['device_display_name']}\n" f" - Device id: " f"<{color}>{device['device_id']}</{color}>\n" f" - Device key: " f"<ansiyellow>{key}</ansiyellow>\n" f" - Trust state: " f"{trust_state}" ) )