diff --git a/main.py b/main.py index 76ffcd7..8cdd9c2 100644 --- a/main.py +++ b/main.py @@ -227,6 +227,11 @@ def build_parser(): parser.add_argument( "-o", "--output-file", type=str, help="Output file for wordlist utilities" ) + parser.add_argument( + "--no-color", + action="store_true", + help="Disable colored output", + ) return parser @@ -266,6 +271,9 @@ def main(): parser = build_parser() args = parser.parse_args() + if args.no_color: + Formatter.no_color = True + if args.version: print(f"Password Cracking & Analysis Toolkit v{VERSION}") print("For educational and authorized security testing only.") diff --git a/tests/test_comprehensive.py b/tests/test_comprehensive.py index e14777c..3c81dce 100644 --- a/tests/test_comprehensive.py +++ b/tests/test_comprehensive.py @@ -558,5 +558,45 @@ def test_cisco7_decode_format(self): self.assertIsNotNone(result) +class TestFormatter(unittest.TestCase): + def test_format_text_color(self): + from utils.formatter import Formatter + Formatter.no_color = False + result = Formatter.format_text("hello", "red") + self.assertIn("\033[91m", result) + self.assertIn("hello", result) + self.assertIn("\033[0m", result) + + def test_format_text_no_color(self): + from utils.formatter import Formatter + Formatter.no_color = True + result = Formatter.format_text("hello", "red") + self.assertEqual(result, "hello") + + def test_format_text_bold(self): + from utils.formatter import Formatter + Formatter.no_color = False + result = Formatter.format_text("hello", bold=True) + self.assertIn("\033[1m", result) + + def test_print_methods_respect_no_color(self): + import io, sys + from utils.formatter import Formatter + Formatter.no_color = True + captured = io.StringIO() + old = sys.stdout + sys.stdout = captured + try: + Formatter.print_success("test") + Formatter.print_error("test") + Formatter.print_warning("test") + Formatter.print_info("test") + finally: + sys.stdout = old + output = captured.getvalue() + self.assertNotIn("\033", output) + self.assertEqual(output.count("test"), 4) + + if __name__ == "__main__": unittest.main() diff --git a/utils/formatter.py b/utils/formatter.py index 22edc10..440be6c 100644 --- a/utils/formatter.py +++ b/utils/formatter.py @@ -1,6 +1,8 @@ class Formatter: """Utility for formatting output messages with colors and styles.""" + no_color = False + # ANSI color codes COLORS = { 'red': '\033[91m', @@ -37,6 +39,9 @@ def format_text(cls, text, color=None, bold=False, underline=False): Returns: str: Formatted text """ + if cls.no_color: + return text + formatted = '' if color and color in cls.COLORS: formatted += cls.COLORS[color]