Skip to content

Commit b0a32e3

Browse files
committed
Introduction of a way to remove background coloration.
This patch fixes #396. Indeed, before this patch, one couldn't remove the coloured background.
1 parent 93d8cb4 commit b0a32e3

File tree

7 files changed

+97
-7
lines changed

7 files changed

+97
-7
lines changed

PyFunceble/cli/entry_points/pyfunceble/cli.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,16 @@ def get_output_control_group_data() -> List[Tuple[List[str], dict]]:
835835
% get_configured_value("cli_testing.display_mode.colour"),
836836
},
837837
),
838+
(
839+
["--background-colour", "--background-color"],
840+
{
841+
"dest": "cli_testing.display_mode.background_colour",
842+
"action": "store_true",
843+
"help": "Activates or disables the background coloration to\n"
844+
"STDOUT. %s"
845+
% get_configured_value("cli_testing.display_mode.background_colour"),
846+
},
847+
),
838848
(
839849
["--display-status"],
840850
{

PyFunceble/cli/filesystem/printer/stdout.py

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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]}"

PyFunceble/cli/system/launcher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ def __init__(self, args: Optional[argparse.Namespace] = None) -> None:
194194
if self.continuous_integration.authorized:
195195
self.continuous_integration.init()
196196

197-
self.stdout_printer.guess_allow_coloration()
197+
self.stdout_printer.guess_allow_coloration().guess_allow_background_coloration()
198198

199199
self.manager = multiprocessing.Manager()
200200

PyFunceble/data/infrastructure/.PyFunceble_production.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,11 @@ cli_testing:
358358
# CLI Argument: --colour | --color
359359
colour: yes
360360

361+
# Enable/Disable the printing of background colors.
362+
#
363+
# CLI Argument: --background-colour | --background-color
364+
background_colour: yes
365+
361366
# Set the status to display to STDOUT.
362367
#
363368
# WARNING:

PyFunceble/storage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
from PyFunceble.storage_facility import get_config_directory
6161

6262
PROJECT_NAME: str = "PyFunceble"
63-
PROJECT_VERSION: str = "4.3.0a19.dev (Blue Duckling: Tulip)"
63+
PROJECT_VERSION: str = "4.3.0a20.dev (Blue Duckling: Tulip)"
6464

6565
DISTRIBUTED_CONFIGURATION_FILENAME: str = ".PyFunceble_production.yaml"
6666

docs/use/configuration/parameters/cli-testing.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,11 @@ cli_testing:
281281
# CLI Argument: --colour | --color
282282
colour: yes
283283

284+
# Enable/Disable the printing of background colors.
285+
#
286+
# CLI Argument: --background-colour | --background-color
287+
background_colour: yes
288+
284289
# Set the status to display to STDOUT.
285290
#
286291
# WARNING:

version.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
current_version: '4.3.0a19.dev (Blue Duckling: Tulip)'
1+
current_version: '4.3.0a20.dev (Blue Duckling: Tulip)'
22
deprecated:
33
- 3.0.21
44
- 3.1.20

0 commit comments

Comments
 (0)