Overview
TheUI class (core/ui.py:31) provides a beautiful, consistent terminal interface using the Rich library. It handles all visual output including headers, menus, tables, progress bars, and formatted messages with custom theming.
Class Definition
core/ui.py
- A global
uiinstance is created at module level:ui = UI() - Use the global instance throughout your application
Constructor
__init__()
Initializes the UI with system information and status tracking.
Attributes:
console: Rich Console instance with custom theme_status: Dictionary tracking application state:device: Connected device identifiermode: Operation mode (“ADB” or “Termux”)os: Operating system and versionpython: Python versionkey: Encryption key status
Status Management
update_status()
Updates a status field displayed in the header.
Status field name (“device”, “mode”, “os”, “python”, “key”)
New value for the status field
Display Methods
print_header()
Displays the application header with title and system information panel.
- Clears screen automatically
- Shows “WhatsApp Backup Forensic Tool v2.0” title
- Displays system info panel with:
- OS and Python version
- Operation mode (ADB/Termux)
- Connected device
- Encryption key status with color coding
print_menu()
Displays a formatted menu with numbered options in a Rich table.
Menu title displayed in panel border
List of menu option descriptions (auto-numbered starting from 1)
print_table()
Displays data in a formatted Rich table.
Table title
Column header names
List of row data (each row is a list of strings)
Message Output
print_info()
Displays an informational message with cyan “[INFO]” prefix.
Information message to display
print_success()
Displays a success message with green “[SUCCESS]” prefix.
Success message to display
print_warning()
Displays a warning message with yellow “[WARNING]” prefix.
Warning message to display
print_error()
Displays an error message in a prominent red panel.
Error message to display
Interactive Input
ask()
Prompts the user for text input with optional default value and choices.
Question prompt displayed to user
Default value if user presses Enter without input
List of valid choices. User input will be validated against this list.
User’s input string
confirm()
Prompts the user for a yes/no confirmation.
Confirmation question
Default answer if user presses Enter
True if user confirmed, False otherwise
Progress Indicators
create_progress()
Creates a Rich Progress bar for tracking long-running operations.
Description displayed next to progress bar
Total number of items (None for indeterminate progress)
Rich Progress instance with spinner, bar, percentage, and time remaining
spinner()
Creates a spinner context manager for operations without progress tracking.
Status text displayed with spinner
Chat Display
print_message()
Displays a WhatsApp message with formatted timestamp and sender.
Message dictionary containing:
from_me(bool): Whether message was sent by usertimestamp(int): Unix timestampsender(str): Sender nametext(str): Message content
- Sent messages: Green color, right-aligned
- Received messages: Cyan sender name, left-aligned
- Timestamp automatically formatted as “HH:MM DD/MM”
print_session_summary()
Displays a summary panel with session statistics.
Summary dictionary containing:
dumped(int): Number of files dumpeddecrypted(int): Number of databases decryptedexports(int): Number of exports created
Utility Methods
clear()
Clears the terminal screen.
Custom Theme
The UI uses a custom Rich theme with predefined styles:Complete Usage Example
Related
Main Application
See the UI in action in main.py
Viewer
Display chat data using the Viewer class
Rich Documentation
Learn more about Rich library features
Custom Themes
Customize the UI theme
