Skip to content

Commit 6b5fe8b

Browse files
committed
refactor: modify the console output to avoid cropped output
Signed-off-by: Demolus13 <parth.govale@oracle.com>
1 parent 8bb02d9 commit 6b5fe8b

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
@@ -720,6 +720,7 @@ def main(argv: list[str] | None = None) -> None:
720720
st_handler.close()
721721
else:
722722
rich_handler.mark_failed()
723+
rich_handler.modify_layout(True)
723724
rich_handler.close()
724725

725726

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[/]"),
@@ -619,49 +620,94 @@ def make_layout(self) -> Group:
619620
)
620621
layout = layout + [error_log_panel]
621622
if self.command == "analyze":
622-
if self.description_table.row_count > 0:
623-
layout = layout + [
624-
Rule(" DESCRIPTION", align="left"),
625-
"",
626-
self.description_table,
627-
]
628-
if self.progress_table.row_count > 0:
629-
layout = layout + ["", self.progress, "", self.progress_table]
630-
if self.failed_checks_table.row_count > 0:
631-
layout = layout + [
632-
"",
633-
Rule(" SUMMARY", align="left"),
634-
"",
635-
self.failed_checks_table,
636-
]
637-
if self.summary_table.row_count > 0:
638-
layout = layout + ["", self.summary_table]
639-
if self.report_table.row_count > 0:
623+
if self.show_full_layout:
624+
if self.description_table.row_count > 0:
640625
layout = layout + [
641-
self.report_table,
626+
Rule(" DESCRIPTION", align="left"),
627+
"",
628+
self.description_table,
642629
]
643-
elif self.summary_table.row_count > 0:
644-
layout = layout + [
645-
"",
646-
Rule(" SUMMARY", align="left"),
647-
"",
648-
self.summary_table,
649-
]
650-
if self.report_table.row_count > 0:
630+
if self.progress_table.row_count > 0:
631+
layout = layout + ["", self.progress, "", self.progress_table]
632+
if self.failed_checks_table.row_count > 0:
651633
layout = layout + [
652-
self.report_table,
634+
"",
635+
Rule(" SUMMARY", align="left"),
636+
"",
637+
self.failed_checks_table,
653638
]
654-
if self.if_dependency and self.dependency_analysis_list:
655-
for idx, dependency in enumerate(self.dependency_analysis_list, start=1):
656-
dependency_layout = dependency.make_layout()
657-
layout = (
658-
layout
659-
+ [
660-
"",
661-
Rule(f" DEPENDENCY {idx}", align="left"),
639+
if self.summary_table.row_count > 0:
640+
layout = layout + ["", self.summary_table]
641+
if self.report_table.row_count > 0:
642+
layout = layout + [
643+
self.report_table,
644+
]
645+
elif self.summary_table.row_count > 0:
646+
layout = layout + [
647+
"",
648+
Rule(" SUMMARY", align="left"),
649+
"",
650+
self.summary_table,
651+
]
652+
if self.report_table.row_count > 0:
653+
layout = layout + [
654+
self.report_table,
655+
]
656+
if self.if_dependency and self.dependency_analysis_list:
657+
for idx, dependency in enumerate(self.dependency_analysis_list, start=1):
658+
dependency_layout = dependency.make_layout()
659+
layout = (
660+
layout
661+
+ [
662+
"",
663+
Rule(f" DEPENDENCY {idx}", align="left"),
664+
]
665+
+ dependency_layout
666+
)
667+
elif self.if_dependency and self.dependency_analysis_list:
668+
dependency = self.dependency_analysis_list[-1]
669+
dependency_layout = dependency.make_layout()
670+
layout = (
671+
layout
672+
+ [
673+
"",
674+
Rule(f" DEPENDENCY {len(self.dependency_analysis_list)}", align="left"),
675+
]
676+
+ dependency_layout
677+
)
678+
else:
679+
if self.description_table.row_count > 0:
680+
layout = layout + [
681+
Rule(" DESCRIPTION", align="left"),
682+
"",
683+
self.description_table,
684+
]
685+
if self.progress_table.row_count > 0:
686+
layout = layout + ["", self.progress, "", self.progress_table]
687+
if self.failed_checks_table.row_count > 0:
688+
layout = layout + [
689+
"",
690+
Rule(" SUMMARY", align="left"),
691+
"",
692+
self.failed_checks_table,
693+
]
694+
if self.summary_table.row_count > 0:
695+
layout = layout + ["", self.summary_table]
696+
if self.report_table.row_count > 0:
697+
layout = layout + [
698+
self.report_table,
699+
]
700+
elif self.summary_table.row_count > 0:
701+
layout = layout + [
702+
"",
703+
Rule(" SUMMARY", align="left"),
704+
"",
705+
self.summary_table,
706+
]
707+
if self.report_table.row_count > 0:
708+
layout = layout + [
709+
self.report_table,
662710
]
663-
+ dependency_layout
664-
)
665711
elif self.command == "verify-policy":
666712
if self.policy_summary_table.row_count > 0:
667713
if self.components_satisfy_table.row_count > 0:
@@ -736,6 +782,17 @@ def error(self, message: str) -> None:
736782
"""
737783
self.error_message = message
738784

785+
def modify_layout(self, value: bool) -> None:
786+
"""
787+
Modify the layout to show full or only analysis segments.
788+
789+
Parameters
790+
----------
791+
value : bool
792+
If True then it shows the full layout.
793+
"""
794+
self.show_full_layout = value
795+
739796
def start(self, command: str) -> None:
740797
"""
741798
Start the live console display.

0 commit comments

Comments
 (0)