Skip to content

Add --no-color flag to disable ANSI color output#562

Merged
Chemaclass merged 2 commits intomainfrom
feat/no-color
Dec 14, 2025
Merged

Add --no-color flag to disable ANSI color output#562
Chemaclass merged 2 commits intomainfrom
feat/no-color

Conversation

@Chemaclass
Copy link
Copy Markdown
Member

@Chemaclass Chemaclass commented Dec 14, 2025

📚 Description

Add support for disabling colored output in bashunit, following the NO_COLOR standard. This allows users to run tests in environments where ANSI escape codes are problematic, such as:

  • CI/CD pipelines that log output to files
  • Terminals that don't support colors
  • When piping output to other tools
  • Accessibility tools that work better with plain text

The feature can be enabled via:

  1. Command-line flag: --no-color
  2. Environment variable: NO_COLOR=1 (following the standard)

Example usage

# Using the flag
./bashunit tests/ --no-color

# Using the environment variable (NO_COLOR standard)
NO_COLOR=1 ./bashunit tests/

# Useful for logging to files without escape sequences
./bashunit tests/ --no-color > test_results.txt

🔖 Changes

  • Add --no-color command-line option to disable terminal colors
  • Add support for the NO_COLOR environment variable (https://no-color.org standard)
  • Add bashunit::env::is_no_color_enabled helper function
  • Add BASHUNIT_NO_COLOR environment variable for configuration
  • Update src/colors.sh to conditionally set color variables to empty strings when no-color mode is enabled
  • Update help text in both test and benchmark modes to document the new option
  • Add acceptance tests to verify both the flag and env var disable colors correctly
  • Fix existing tests to propagate no-color setting when running nested bashunit calls

🖼️ Demo

Screenshot 2025-12-14 at 13 20 02

✅ To-do list

  • I updated the CHANGELOG.md to reflect the new feature or fix
  • I updated the documentation to reflect the changes

  Support disabling ANSI color output via --no-color flag or NO_COLOR
  environment variable (no-color.org standard). Colors are disabled at
  initialization time with zero runtime overhead.

  The flag does not leak to child processes, so tests that spawn bashunit
  subprocesses work correctly.
@Chemaclass Chemaclass added the enhancement New feature or request label Dec 14, 2025
@Chemaclass Chemaclass self-assigned this Dec 14, 2025
@Chemaclass Chemaclass mentioned this pull request Dec 14, 2025
2 tasks
@Chemaclass Chemaclass changed the title No color Add --no-color flag to disable ANSI color output Dec 14, 2025
@Chemaclass Chemaclass enabled auto-merge December 14, 2025 12:28
@Chemaclass Chemaclass merged commit 70bbb02 into main Dec 14, 2025
16 checks passed
@Chemaclass Chemaclass deleted the feat/no-color branch December 14, 2025 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants