@@ -103,20 +103,27 @@ class StdoutPrinter(PrinterBase):
103103 FOREGROUND_COLORATED : List [str ] = ["percentage" , "simple" ]
104104
105105 _allow_coloration : bool = True
106+ _allow_background_coloration : bool = True
106107
107108 def __init__ (
108109 self ,
109110 template_to_use : Optional [str ] = None ,
110111 * ,
111112 dataset : Optional [Dict [str , str ]] = None ,
112113 allow_coloration : Optional [bool ] = None ,
114+ allow_background_coloration : Optional [bool ] = None ,
113115 ** kwargs ,
114116 ) -> None :
115117 if allow_coloration is not None :
116118 self .allow_coloration = allow_coloration
117119 else :
118120 self .guess_allow_coloration ()
119121
122+ if allow_background_coloration is not None :
123+ self .allow_background_coloration = allow_background_coloration
124+ else :
125+ self .guess_allow_background_coloration ()
126+
120127 super ().__init__ (template_to_use = template_to_use , dataset = dataset , ** kwargs )
121128
122129 @property
@@ -170,6 +177,63 @@ def guess_allow_coloration(self) -> "StdoutPrinter":
170177 else :
171178 self .allow_coloration = self .STD_ALLOW_COLORATION
172179
180+ return self
181+
182+ @property
183+ def allow_background_coloration (self ) -> bool :
184+ """
185+ Provides the current state of the :code:`_allow_background_coloration`
186+ attribute.
187+ """
188+
189+ return self ._allow_background_coloration
190+
191+ @allow_background_coloration .setter
192+ def allow_background_coloration (self , value : bool ) -> Optional [bool ]:
193+ """
194+ Sets the authorization to use the coloration.
195+
196+ :param value:
197+ The value to set.
198+
199+ :raise TypeError:
200+ When the given :code:`value` is not a :py:class:`str`.
201+ :raise ValueError:
202+ When teh given :code:`value` is empty.
203+ """
204+
205+ if not isinstance (value , bool ):
206+ raise TypeError (f"<value> should be { bool } , { type (value )} given." )
207+
208+ self ._allow_background_coloration = value
209+
210+ def set_allow_background_coloration (self , value : bool ) -> "StdoutPrinter" :
211+ """
212+ Sets the authorization to use the coloration.
213+
214+ :param value:
215+ The value to set.
216+ """
217+
218+ self .allow_background_coloration = value
219+
220+ return self
221+
222+ def guess_allow_background_coloration (self ) -> "StdoutPrinter" :
223+ """
224+ Try to guess and set the :code:`disable_background_coloration` attribute.
225+ """
226+
227+ if PyFunceble .facility .ConfigLoader .is_already_loaded ():
228+ # pylint: disable=line-too-long
229+ self .allow_background_coloration = (
230+ PyFunceble .storage .CONFIGURATION .cli_testing .display_mode .background_colour
231+ )
232+ else :
233+ self .allow_background_coloration = True
234+
235+ return self
236+
173237 def print_interpolated_line (self ):
174238 """
175239 Prints the interpolated line into the destination.
@@ -186,10 +250,16 @@ def print_interpolated_line(self):
186250
187251 if self .allow_coloration :
188252 if self .template_to_use in self .BACKGROUND_COLORATED :
189- print (
190- f"{ self .STATUS2BACKGROUND_COLOR [status_to_compare ]} "
191- f"{ line_to_print } "
192- )
253+ if self .allow_background_coloration :
254+ print (
255+ f"{ self .STATUS2BACKGROUND_COLOR [status_to_compare ]} "
256+ f"{ line_to_print } "
257+ )
258+ else :
259+ print (
260+ f"{ self .STATUS2FORGROUND_COLOR [status_to_compare ]} "
261+ f"{ line_to_print } "
262+ )
193263 elif self .template_to_use in self .FOREGROUND_COLORATED :
194264 print (
195265 f"{ self .STATUS2FORGROUND_COLOR [status_to_compare ]} "
0 commit comments