feat: display layers if actived

This commit is contained in:
egarette@silique.fr 2025-11-07 08:38:48 +01:00
parent ae8760ffc0
commit 0b69b3d812

View file

@ -49,6 +49,7 @@ class RougailOutputConsole:
user_data_errors: Optional[list] = None, user_data_errors: Optional[list] = None,
user_data_warnings: Optional[list] = None, user_data_warnings: Optional[list] = None,
config_owner_is_path: bool = False, config_owner_is_path: bool = False,
layer_datas = None,
**kwargs **kwargs
) -> None: ) -> None:
if rougailconfig is None: if rougailconfig is None:
@ -58,6 +59,7 @@ class RougailOutputConsole:
self.rougailconfig = rougailconfig self.rougailconfig = rougailconfig
self.config = config self.config = config
self.metaconfig = metaconfig self.metaconfig = metaconfig
self.layer_datas = layer_datas
self.config_owner_is_path = config_owner_is_path self.config_owner_is_path = config_owner_is_path
self.is_mandatory = self.rougailconfig["console.mandatory"] self.is_mandatory = self.rougailconfig["console.mandatory"]
self.show_secrets = self.rougailconfig["console.show_secrets"] self.show_secrets = self.rougailconfig["console.show_secrets"]
@ -102,7 +104,10 @@ class RougailOutputConsole:
current_options = options current_options = options
for child_path in option.path().split('.'): for child_path in option.path().split('.'):
child = parent.option(child_path) child = parent.option(child_path)
if self.key_is_description:
description = child.description(uncalculated=True) description = child.description(uncalculated=True)
else:
description = child.path(uncalculated=True)
if child.isdynamic() and "{{ identifier }}" in description: if child.isdynamic() and "{{ identifier }}" in description:
description = description.replace('{{ identifier }}', child.identifiers()[-1]) description = description.replace('{{ identifier }}', child.identifiers()[-1])
@ -114,9 +119,13 @@ class RougailOutputConsole:
if options: if options:
self.errors.append({_("The following variables are mandatory but have no value:"): options}) self.errors.append({_("The following variables are mandatory but have no value:"): options})
elif options_with_error: elif options_with_error:
if self.key_is_description:
variables = [option.description() for option in options_with_error]
else:
variables = [option.path() for option in options_with_error]
self.errors.append({_( self.errors.append({_(
"The following variables are inaccessible but are empty and mandatory:" "The following variables are inaccessible but are empty and mandatory:"
): [option.description() for option in options_with_error]}) ): variables})
def exporter(self) -> bool: def exporter(self) -> bool:
if self.is_mandatory: if self.is_mandatory:
@ -197,15 +206,15 @@ class RougailOutputConsole:
leader_obj.add_variable(follower) leader_obj.add_variable(follower)
def header(self): def header(self):
header_variable = "" caption_line = ""
if self.variable_default_enable: if self.variable_default_enable:
header_variable += _("Variable") + "\n" caption_line += _("Variable") + "\n"
if self.variable_advanced_enable: if self.variable_advanced_enable:
header_variable += f'[{self.variable_advanced_color}]{_("Undocumented variable")}[/{self.variable_advanced_color}]\n' caption_line += f'[{self.variable_advanced_color}]{_("Undocumented variable")}[/{self.variable_advanced_color}]\n'
if self.variable_advanced_and_modified_enable: if self.variable_advanced_and_modified_enable:
header_variable += f'[{self.variable_advanced_and_modified_color}]{_("Undocumented but modified variable")}[/{self.variable_advanced_and_modified_color}]\n' caption_line += f'[{self.variable_advanced_and_modified_color}]{_("Undocumented but modified variable")}[/{self.variable_advanced_and_modified_color}]\n'
if self.variable_hidden_enable: if self.variable_hidden_enable:
header_variable += f'[{self.variable_hidden_color}]{_("Unmodifiable variable")}[/{self.variable_hidden_color}]\n' caption_line += f'[{self.variable_hidden_color}]{_("Unmodifiable variable")}[/{self.variable_hidden_color}]\n'
header_value = "" header_value = ""
if self.value_unmodified_enable: if self.value_unmodified_enable:
header_value = f'[{self.value_unmodified_color}]{_("Default value")}[/{self.value_unmodified_color}]\n' header_value = f'[{self.value_unmodified_color}]{_("Default value")}[/{self.value_unmodified_color}]\n'
@ -213,10 +222,29 @@ class RougailOutputConsole:
header_value += _("Modified value") + "\n" header_value += _("Modified value") + "\n"
if self.value_default_enable: if self.value_default_enable:
header_value += f'([{self.value_default_color}]:hourglass_flowing_sand: {_("Original default value")}[/{self.value_default_color}])\n' header_value += f'([{self.value_default_color}]:hourglass_flowing_sand: {_("Original default value")}[/{self.value_default_color}])\n'
header = Table.grid(padding=1, collapse_padding=True) caption = Table.grid(padding=1, collapse_padding=True)
header.pad_edge = False caption.pad_edge = False
header.add_row(header_variable[:-1], header_value[:-1]) caption.add_row(caption_line[:-1], header_value[:-1])
self.out.append(Panel.fit(header, title=_("Caption"))) self.out.append(Panel.fit(caption, title=_("Caption")))
#
layers = Table.grid(padding=1, collapse_padding=True)
caption.pad_edge = False
if self.layer_datas:
max_len = 0
for datas in self.layer_datas.values():
for data in datas.values():
max_len = max(max_len, len(data))
display_layers = ["" for i in range(max_len)]
for datas in self.layer_datas.values():
for data in datas.values():
last_index = len(data) - 1
for idx in range(max_len):
if last_index < idx:
display_layers[idx] += "\n"
else:
display_layers[idx] += data[idx] + "\n"
layers.add_row(*[layer[:-1] for layer in display_layers])
self.out.append(Panel.fit(layers, title=_("Layers")))
def display_errors( def display_errors(
self, self,