Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.")
Expand Down
40 changes: 40 additions & 0 deletions tests/test_comprehensive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
5 changes: 5 additions & 0 deletions utils/formatter.py
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -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]
Expand Down