Skip to content

Commit 0f4cdc8

Browse files
committed
refactor: modify the console output to avoid cropped output
Signed-off-by: Demolus13 <parth.govale@oracle.com>
1 parent 2ea80c6 commit 0f4cdc8

File tree

2 files changed

+96
-38
lines changed

2 files changed

+96
-38
lines changed

src/macaron/__main__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,7 @@ def main(argv: list[str] | None = None) -> None:
722722
st_handler.close()
723723
else:
724724
rich_handler.mark_failed()
725+
rich_handler.modify_layout(True)
725726
rich_handler.close()
726727

727728

src/macaron/console.py

Lines changed: 95 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ def __init__(self, *args: Any, verbose: bool = False, **kwargs: Any) -> None:
256256
self.command = ""
257257
self.logs: list[str] = []
258258
self.error_logs: list[str] = []
259+
self.show_full_layout: bool = False
259260
self.description_table = Table(show_header=False, box=None)
260261
self.description_table_content: dict[str, str | Status] = {
261262
"Package URL:": Status("[green]Processing[/]"),
@@ -615,49 +616,94 @@ def make_layout(self) -> Group:
615616
)
616617
layout = layout + [error_log_panel]
617618
if self.command == "analyze":
618-
if self.description_table.row_count > 0:
619-
layout = layout + [
620-
Rule(" DESCRIPTION", align="left"),
621-
"",
622-
self.description_table,
623-
]
624-
if self.progress_table.row_count > 0:
625-
layout = layout + ["", self.progress, "", self.progress_table]
626-
if self.failed_checks_table.row_count > 0:
627-
layout = layout + [
628-
"",
629-
Rule(" SUMMARY", align="left"),
630-
"",
631-
self.failed_checks_table,
632-
]
633-
if self.summary_table.row_count > 0:
634-
layout = layout + ["", self.summary_table]
635-
if self.report_table.row_count > 0:
619+
if self.show_full_layout:
620+
if self.description_table.row_count > 0:
636621
layout = layout + [
637-
self.report_table,
622+
Rule(" DESCRIPTION", align="left"),
623+
"",
624+
self.description_table,
638625
]
639-
elif self.summary_table.row_count > 0:
640-
layout = layout + [
641-
"",
642-
Rule(" SUMMARY", align="left"),
643-
"",
644-
self.summary_table,
645-
]
646-
if self.report_table.row_count > 0:
626+
if self.progress_table.row_count > 0:
627+
layout = layout + ["", self.progress, "", self.progress_table]
628+
if self.failed_checks_table.row_count > 0:
647629
layout = layout + [
648-
self.report_table,
630+
"",
631+
Rule(" SUMMARY", align="left"),
632+
"",
633+
self.failed_checks_table,
649634
]
650-
if self.if_dependency and self.dependency_analysis_list:
651-
for idx, dependency in enumerate(self.dependency_analysis_list, start=1):
652-
dependency_layout = dependency.make_layout()
653-
layout = (
654-
layout
655-
+ [
656-
"",
657-
Rule(f" DEPENDENCY {idx}", align="left"),
635+
if self.summary_table.row_count > 0:
636+
layout = layout + ["", self.summary_table]
637+
if self.report_table.row_count > 0:
638+
layout = layout + [
639+
self.report_table,
640+
]
641+
elif self.summary_table.row_count > 0:
642+
layout = layout + [
643+
"",
644+
Rule(" SUMMARY", align="left"),
645+
"",
646+
self.summary_table,
647+
]
648+
if self.report_table.row_count > 0:
649+
layout = layout + [
650+
self.report_table,
651+
]
652+
if self.if_dependency and self.dependency_analysis_list:
653+
for idx, dependency in enumerate(self.dependency_analysis_list, start=1):
654+
dependency_layout = dependency.make_layout()
655+
layout = (
656+
layout
657+
+ [
658+
"",
659+
Rule(f" DEPENDENCY {idx}", align="left"),
660+
]
661+
+ dependency_layout
662+
)
663+
elif self.if_dependency and self.dependency_analysis_list:
664+
dependency = self.dependency_analysis_list[-1]
665+
dependency_layout = dependency.make_layout()
666+
layout = (
667+
layout
668+
+ [
669+
"",
670+
Rule(f" DEPENDENCY {len(self.dependency_analysis_list)}", align="left"),
671+
]
672+
+ dependency_layout
673+
)
674+
else:
675+
if self.description_table.row_count > 0:
676+
layout = layout + [
677+
Rule(" DESCRIPTION", align="left"),
678+
"",
679+
self.description_table,
680+
]
681+
if self.progress_table.row_count > 0:
682+
layout = layout + ["", self.progress, "", self.progress_table]
683+
if self.failed_checks_table.row_count > 0:
684+
layout = layout + [
685+
"",
686+
Rule(" SUMMARY", align="left"),
687+
"",
688+
self.failed_checks_table,
689+
]
690+
if self.summary_table.row_count > 0:
691+
layout = layout + ["", self.summary_table]
692+
if self.report_table.row_count > 0:
693+
layout = layout + [
694+
self.report_table,
695+
]
696+
elif self.summary_table.row_count > 0:
697+
layout = layout + [
698+
"",
699+
Rule(" SUMMARY", align="left"),
700+
"",
701+
self.summary_table,
702+
]
703+
if self.report_table.row_count > 0:
704+
layout = layout + [
705+
self.report_table,
658706
]
659-
+ dependency_layout
660-
)
661707
elif self.command == "verify-policy":
662708
if self.policy_summary_table.row_count > 0:
663709
if self.components_satisfy_table.row_count > 0:
@@ -732,6 +778,17 @@ def error(self, message: str) -> None:
732778
"""
733779
self.error_message = message
734780

781+
def modify_layout(self, value: bool) -> None:
782+
"""
783+
Modify the layout to show full or only analysis segments.
784+
785+
Parameters
786+
----------
787+
value : bool
788+
If True then it shows the full layout.
789+
"""
790+
self.show_full_layout = value
791+
735792
def start(self, command: str) -> None:
736793
"""
737794
Start the live console display.

0 commit comments

Comments
 (0)