# How Holehe Handles Colorized Terminal Output and the `--no-color` Flag

> Learn how Holehe uses termcolor for terminal output and respects the --no-color flag. See how it disables ANSI codes for plain text display.

- Repository: [Palenath/holehe](https://github.com/megadose/holehe)
- Tags: internals
- Published: 2026-08-15

---

**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`](https://github.com/megadose/holehe/blob/main/holehe/core.py), the `colored` function is imported:

```python
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`](https://github.com/megadose/holehe/blob/main/holehe/core.py) defines a boolean flag that lets users disable color output:

```python
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()`:

```python
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`](https://github.com/megadose/holehe/blob/main/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:

```bash
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:

```bash
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:

```bash

# 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`](https://github.com/megadose/holehe/blob/main/holehe/core.py)** — Contains the import of `colored`, the `--no-color` argument definition at line 186, and the conditional check at line 108 that guards all colorized output.

- **[`requirements.txt`](https://github.com/megadose/holehe/blob/main/requirements.txt)** / **[`setup.py`](https://github.com/megadose/holehe/blob/main/setup.py)** — Both list `termcolor` as a dependency, ensuring it's installed with the package.

## Summary

- Holehe uses **`termcolor.colored()`** from [`holehe/core.py`](https://github.com/megadose/holehe/blob/main/holehe/core.py) for all terminal colorization.
- The **`--no-color`** flag sets `args.nocolor = True`, which bypasses color wrapping.
- The check **condition evaluates to `True`** when colors are enabled (`args.nocolor == False`), calling `colored()` on output strings.
- When **`--no-color` is 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`](https://github.com/megadose/holehe/blob/main/setup.py) and [`requirements.txt`](https://github.com/megadose/holehe/blob/main/requirements.txt), so it installs automatically with Holehe. If somehow missing, the import at the top of [`holehe/core.py`](https://github.com/megadose/holehe/blob/main/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`](https://github.com/megadose/holehe/blob/main/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.