diff --git a/credsweeper/app.py b/credsweeper/app.py index 99e296cfc..dfa8f3782 100644 --- a/credsweeper/app.py +++ b/credsweeper/app.py @@ -5,8 +5,7 @@ from typing import Any, List, Optional, Union, Dict, Sequence, Tuple import pandas as pd -from colorama import Fore -from colorama.ansi import Style +from colorama import Style # Directory of credsweeper sources MUST be placed before imports to avoid circular import error APP_PATH = Path(__file__).resolve().parent @@ -436,15 +435,10 @@ def export_results(self) -> None: is_exported = True for credential in credentials: for line_data in credential.line_data_list: - print(Style.BRIGHT + credential.rule_name \ - + f" {line_data.info or line_data.path}:{line_data.line_num}" - + Style.RESET_ALL) - if self.hashed: - print(Fore.LIGHTGREEN_EX \ - + line_data.get_hash_or_subtext(line_data.line, self.hashed) \ - + Style.RESET_ALL) - else: - print(f"{line_data.get_colored_line(self.subtext)}") + # bright rule name and path or info + print(Style.BRIGHT + credential.rule_name + + f" {line_data.info or line_data.path}:{line_data.line_num}" + Style.RESET_ALL) + print(line_data.get_colored_line(hashed=self.hashed, subtext=self.subtext)) if is_exported is False: for credential in credentials: diff --git a/credsweeper/credentials/line_data.py b/credsweeper/credentials/line_data.py index 41a0bb5ac..3180c9f98 100644 --- a/credsweeper/credentials/line_data.py +++ b/credsweeper/credentials/line_data.py @@ -417,7 +417,13 @@ def to_json(self, hashed: bool, subtext: bool) -> Dict: reported_output = {k: v for k, v in full_output.items() if k in self.config.line_data_output} return reported_output - def get_colored_line(self, subtext: bool = False) -> str: + def get_colored_line(self, hashed: bool, subtext: bool = False) -> str: + """Represents the LineData with a value, separator, and variable color formatting""" + if hashed: + # return colored hash + return Fore.LIGHTGREEN_EX \ + + self.get_hash_or_subtext(self.line, hashed, self.value_start if subtext else None) \ + + Style.RESET_ALL # at least, value must present line = self.line[:self.value_start] \ + Fore.LIGHTYELLOW_EX \