11import re
2+ import os
23import sys
34from shutil import get_terminal_size
45from dataclasses import dataclass
5556OK = '\u2713 '
5657NOK = '\u2717 '
5758
59+ TTY_COLORS = bool (os .environ .get ("AURA_FORCE_COLORS" , False )) or None
60+
5861
5962
6063class PrettyReport :
@@ -81,7 +84,7 @@ def ansi_length(cls, line:str):
8184 return len (cls .ANSI_RE .sub ("" , line ))
8285
8386 def print_separator (self , sep = "\u2504 " , left = "\u251C " , right = "\u2524 " ):
84- secho (f"{ left } { sep * (self .width - 2 )} { right } " , file = self .fd )
87+ secho (f"{ left } { sep * (self .width - 2 )} { right } " , file = self .fd , color = TTY_COLORS )
8588
8689 def print_thick_separator (self ):
8790 self .print_separator (left = "\u255E " , sep = "\u2550 " , right = "\u2561 " )
@@ -96,11 +99,11 @@ def print_heading(self, text, left="\u251C", right="\u2524", infill="\u2591"):
9699 text_len = self .ansi_length (text )
97100 ljust = (self .width - 4 - text_len )// 2
98101 rjust = self .width - 4 - text_len - ljust
99- secho (f"{ left } { infill * ljust } { text } { infill * rjust } { right } " , file = self .fd )
102+ secho (f"{ left } { infill * ljust } { text } { infill * rjust } { right } " , file = self .fd , color = TTY_COLORS )
100103
101104 def align (self , line , pos = - 1 , left = "\u2502 " , right = " \u2502 " ):
102105 line = self ._align_text (line , self .width - len (left ) - len (right ), pos = pos )
103- secho (f"{ left } { line } { right } " , file = self .fd )
106+ secho (f"{ left } { line } { right } " , file = self .fd , color = TTY_COLORS )
104107
105108 def wrap (self , text , left = "\u2502 " , right = " \u2502 " ):
106109 remaining_len = self .width - len (left ) - len (right )
@@ -271,7 +274,7 @@ def output(self, hits, scan_metadata: dict):
271274 if score < self .min_score :
272275 return
273276
274- secho ("\n " , file = self ._fd ) # Empty line for readability
277+ secho ("\n " , file = self ._fd , color = TTY_COLORS ) # Empty line for readability
275278 self ._formatter .print_top_separator ()
276279 self ._formatter .print_heading (style (f"Scan results for { scan_metadata .get ('name' , 'N/A' )} " , fg = "bright_green" ))
277280 score_color = "bright_green" if score == 0 else "bright_red"
0 commit comments