Add header clearing with notifications

This commit is contained in:
thePR0M3TH3AN
2025-07-14 15:23:37 -04:00
parent 9d0338de63
commit b8a5ed9f66
5 changed files with 80 additions and 34 deletions

View File

@@ -28,7 +28,12 @@ try:
from .input_utils import timed_input
from .memory_protection import InMemorySecret
from .clipboard import copy_to_clipboard
from .terminal_utils import clear_screen, pause, clear_and_print_fingerprint
from .terminal_utils import (
clear_screen,
pause,
clear_and_print_fingerprint,
clear_header_with_notification,
)
if logger.isEnabledFor(logging.DEBUG):
logger.info("Modules imported successfully.")
@@ -58,5 +63,6 @@ __all__ = [
"copy_to_clipboard",
"clear_screen",
"clear_and_print_fingerprint",
"clear_header_with_notification",
"pause",
]

View File

@@ -5,6 +5,8 @@ import sys
from termcolor import colored
from utils.color_scheme import color_text
def clear_screen() -> None:
"""Clear the terminal screen using an ANSI escape code."""
@@ -49,6 +51,44 @@ def clear_and_print_profile_chain(
print(colored(header, "green"))
def clear_header_with_notification(
pm,
fingerprint: str | None = None,
breadcrumb: str | None = None,
parent_fingerprint: str | None = None,
child_fingerprint: str | None = None,
) -> None:
"""Clear the screen, print the header, then show the current notification."""
clear_screen()
header_fp = None
if parent_fingerprint and child_fingerprint:
header_fp = f"{parent_fingerprint} > Managed Account > {child_fingerprint}"
elif fingerprint:
header_fp = fingerprint
elif parent_fingerprint or child_fingerprint:
header_fp = parent_fingerprint or child_fingerprint
if header_fp:
header = f"Seed Profile: {header_fp}"
if breadcrumb:
header += f" > {breadcrumb}"
print(colored(header, "green"))
note = None
if hasattr(pm, "get_current_notification"):
try:
note = pm.get_current_notification()
except Exception:
note = None
if note:
category = getattr(note, "level", "info").lower()
if category not in ("info", "warning", "error"):
category = "info"
print(color_text(getattr(note, "message", ""), category))
else:
print()
def pause(message: str = "Press Enter to continue...") -> None:
"""Wait for the user to press Enter before proceeding."""
if not sys.stdin or not sys.stdin.isatty():