Skip to main content

Module utils

Module utils 

Source
Expand description

Utility functions for permissions, formatting, and error handling.

Functions§

check_root
Check if the program is running with root privileges (Unix) or an elevated/Administrator token (Windows).
confirm
Ask for user confirmation
elevate_if_needed
Prompt for sudo elevation if not already root Returns true if elevation succeeded or already root, false otherwise
execute_with_sudo
Execute a command with sudo if not already root This function handles terminal raw mode properly for TUI applications It assumes sudo credentials are already cached (via password dialog or sudo -v)
format_size
Format bytes into human-readable sizes
get_size
Get the size of a directory or file in bytes.
print_error
Print an error message
print_header
Print a header with a colorful banner
print_success
Print a success message
print_warning
Print a warning message
supports_sudo_prompt
Whether this platform’s elevation model matches the interactive sudo-password-prompt flow (Unix: sudo -S). Windows uses UAC/Administrator tokens instead, which front-ends should present very differently (there is no password to type — the user must relaunch the process elevated).