2222# Controls when ANSI style style sequences are allowed in output
2323allow_style = STYLE_TERMINAL
2424
25- # Regular expression to match ANSI style sequences
26- # This matches: colorama.ansi.CSI + 0 or more digits + m
27- ANSI_STYLE_RE = re .compile (r'\033\[[0-9]*m' )
25+ # Regular expression to match ANSI style sequences (including 8-bit and 24-bit colors)
26+ ANSI_STYLE_RE = re .compile (r'\x1b\[[^m]*m' )
2827
2928# Foreground color presets
3029FG_COLORS = {
7271BG_RESET = BG_COLORS ['reset' ]
7372RESET_ALL = Style .RESET_ALL
7473
75- BRIGHT = Style .BRIGHT
76- NORMAL = Style .NORMAL
74+ # Text intensities
75+ INTENSITY_BRIGHT = Style .BRIGHT
76+ INTENSITY_DIM = Style .DIM
77+ INTENSITY_NORMAL = Style .NORMAL
7778
7879# ANSI style sequences not provided by colorama
7980UNDERLINE_ENABLE = colorama .ansi .code_to_chars (4 )
@@ -139,7 +140,8 @@ def bg_lookup(bg_name: str) -> str:
139140 return ansi_escape
140141
141142
142- def style (text : Any , * , fg : str = '' , bg : str = '' , bold : bool = False , underline : bool = False ) -> str :
143+ def style (text : Any , * , fg : str = '' , bg : str = '' , bold : bool = False ,
144+ dim : bool = False , underline : bool = False ) -> str :
143145 """
144146 Apply ANSI colors and/or styles to a string and return it.
145147 The styling is self contained which means that at the end of the string reset code(s) are issued
@@ -148,7 +150,8 @@ def style(text: Any, *, fg: str = '', bg: str = '', bold: bool = False, underlin
148150 :param text: Any object compatible with str.format()
149151 :param fg: foreground color. Relies on `fg_lookup()` to retrieve ANSI escape based on name. Defaults to no color.
150152 :param bg: background color. Relies on `bg_lookup()` to retrieve ANSI escape based on name. Defaults to no color.
151- :param bold: apply the bold style if True. Defaults to False.
153+ :param bold: apply the bold style if True. Can be combined with dim. Defaults to False.
154+ :param dim: apply the dim style if True. Can be combined with bold. Defaults to False.
152155 :param underline: apply the underline style if True. Defaults to False.
153156 :return: the stylized string
154157 """
@@ -171,8 +174,12 @@ def style(text: Any, *, fg: str = '', bg: str = '', bold: bool = False, underlin
171174 removals .append (BG_RESET )
172175
173176 if bold :
174- additions .append (Style .BRIGHT )
175- removals .append (Style .NORMAL )
177+ additions .append (INTENSITY_BRIGHT )
178+ removals .append (INTENSITY_NORMAL )
179+
180+ if dim :
181+ additions .append (INTENSITY_DIM )
182+ removals .append (INTENSITY_NORMAL )
176183
177184 if underline :
178185 additions .append (UNDERLINE_ENABLE )
0 commit comments