How Holehe Handles Colorized Terminal Output and the `--no-color` Flag
Holehe uses the termcolor library to colorize terminal output and checks the --no-color CLI flag before applying any ANSI color codes, falling back to plain text when the flag is set.
The megadose/holehe repository is an OSINT tool for checking if an email address is registered on various websites. Colorized output helps users quickly parse results, but the tool also provides a way to disable colors for environments that don't support them or when piping output to other programs.
How Color Handling Works in Holehe
Color Library Import
Holehe relies on the termcolor library for all terminal colorization. At the top of holehe/core.py, the colored function is imported:
from termcolor import colored
This single import provides the colored(text, color) function used throughout the codebase to apply ANSI color codes to status messages and results.
The --no-color CLI Flag
The argument parser in holehe/core.py defines a boolean flag that lets users disable color output:
parser.add_argument("--no-color", action="store_true", dest="nocolor",
help="disable colored output")
When this flag is passed, args.nocolor is set to True. By default, when the flag is omitted, args.nocolor remains False.
Conditional Color Application
The core logic that determines whether to apply colors appears in the output formatting code. Holehe checks args.nocolor before calling colored():
if args.nocolor == False:
# apply colored() wrapper to output strings
formatted = colored(message, color)
else:
# bypass colorization, use plain strings
formatted = message
This conditional appears at line 108 in holehe/core.py, ensuring that every piece of output respects the user's preference.
Practical Usage Examples
Default Colored Output
Run Holehe normally to see color-coded results:
holehe -e test@example.com
This produces output with colors like green for found accounts, red for errors, and yellow for rate-limited services.
Disable Colors with --no-color
For scripts, CI pipelines, or terminals without color support:
holehe -e test@example.com --no-color
The same information prints without ANSI escape sequences, making it safe to pipe to grep, awk, or log files.
Environment Variables Alternative
Some users prefer environment-based toggles. While Holehe doesn't natively support NO_COLOR or FORCE_COLOR environment variables, you can achieve similar behavior with shell wrapping:
# Force plain output via alias
alias holehe='holehe --no-color'
# Or conditionally
[ -t 1 ] || holehe -e test@example.com --no-color
Key Files and Dependencies
-
holehe/core.py— Contains the import ofcolored, the--no-colorargument definition at line 186, and the conditional check at line 108 that guards all colorized output. -
requirements.txt/setup.py— Both listtermcoloras a dependency, ensuring it's installed with the package.
Summary
- Holehe uses
termcolor.colored()fromholehe/core.pyfor all terminal colorization. - The
--no-colorflag setsargs.nocolor = True, which bypasses color wrapping. - The check condition evaluates to
Truewhen colors are enabled (args.nocolor == False), callingcolored()on output strings. - When
--no-coloris passed, the same strings print without ANSI codes for compatibility with pipes and plain terminals.
Frequently Asked Questions
Does Holehe respect the NO_COLOR environment variable?
No. As implemented in megadose/holehe, only the explicit --no-color CLI flag controls color output. The code checks args.nocolor directly and does not query environment variables. Users who need this behavior must wrap the command or alias it.
What happens if termcolor is not installed?
The termcolor package is declared as a dependency in setup.py and requirements.txt, so it installs automatically with Holehe. If somehow missing, the import at the top of holehe/core.py would raise an ImportError on startup.
Does --no-color affect JSON or CSV output formats?
The --no-color flag only controls ANSI escape sequences in terminal output. If Holehe supports structured output formats (like JSON), those formats typically omit color codes regardless of the flag since they're meant for programmatic consumption. Check the specific module's output logic in holehe/core.py for format-specific behavior.
Can I force color output even when piping?
The current implementation in megadose/holehe does not include a --color=always option. The --no-color flag is strictly opt-out; there's no opt-in override for non-TTY destinations. The colored() calls execute based solely on the args.nocolor boolean.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →