11import copy
22from typing import TYPE_CHECKING , Any
33
4+ from archinstall .lib .menu .menu_helper import MenuHelper
45from archinstall .tui .curses_menu import SelectMenu
56from archinstall .tui .menu_item import MenuItem , MenuItemGroup
67from archinstall .tui .result import ResultType
78from archinstall .tui .types import Alignment
89
9- from ..output import FormattedOutput
10-
1110if TYPE_CHECKING :
1211 from collections .abc import Callable
1312
@@ -63,23 +62,23 @@ def is_last_choice_cancel(self) -> bool:
6362 return False
6463
6564 def run (self ) -> list [Any ]:
66- while True :
67- # this will return a dictionary with the key as the menu entry to be displayed
68- # and the value is the original value from the self._data container
69- data_formatted = self .reformat (self ._data )
70- options = self ._prepare_selection (data_formatted )
65+ additional_options = self ._base_actions + self ._terminate_actions
7166
72- header = self ._get_header (data_formatted )
67+ while True :
68+ group = MenuHelper (
69+ data = self ._data ,
70+ additional_options = additional_options
71+ ).create_menu_group ()
7372
73+ prompt = None
7474 if self ._prompt is not None :
75- header = f'{ self ._prompt } \n \n { header } '
75+ prompt = f'{ self ._prompt } \n \n '
7676
77- items = [MenuItem (o [0 ], value = o [1 ]) for o in options ]
78- group = MenuItemGroup (items , sort_items = False )
77+ prompt = None
7978
8079 result = SelectMenu (
8180 group ,
82- header = header ,
81+ header = prompt ,
8382 search_enabled = False ,
8483 allow_skip = False ,
8584 alignment = Alignment .CENTER
@@ -106,25 +105,6 @@ def run(self) -> list[Any]:
106105 else :
107106 return self ._data
108107
109- def _get_header (self , data_formatted : dict [str , Any ]) -> str :
110- table_header = [key for key , val in data_formatted .items () if val is None ]
111- header = '\n ' .join (table_header )
112- return header
113-
114- def _prepare_selection (self , data_formatted : dict [str , Any ]) -> list [tuple [str , Any ]]:
115- # header rows are mapped to None so make sure
116- # to exclude those from the selectable data
117- options = [(key , val ) for key , val in data_formatted .items () if val is not None ]
118-
119- if len (options ) > 0 :
120- options .append ((self ._separator , None ))
121-
122- additional_options = self ._base_actions + self ._terminate_actions
123- for o in additional_options :
124- options .append ((o , o ))
125-
126- return options
127-
128108 def _run_actions_on_entry (self , entry : Any ) -> None :
129109 options = self .filter_options (entry , self ._sub_menu_actions ) + [self ._cancel_action ]
130110
@@ -150,27 +130,6 @@ def _run_actions_on_entry(self, entry: Any) -> None:
150130 if value != self ._cancel_action :
151131 self ._data = self .handle_action (value , entry , self ._data )
152132
153- def reformat (self , data : list [Any ]) -> dict [str , Any | None ]:
154- """
155- Default implementation of the table to be displayed.
156- Override if any custom formatting is needed
157- """
158- display_data : dict [str , Any | None ] = {}
159-
160- if data :
161- table = FormattedOutput .as_table (data )
162- rows = table .split ('\n ' )
163-
164- # these are the header rows of the table and do not map to any User obviously
165- # we're adding 2 spaces as prefix because the menu selector '> ' will be put before
166- # the selectable rows so the header has to be aligned
167- display_data = {f'{ rows [0 ]} ' : None , f'{ rows [1 ]} ' : None }
168-
169- for row , entry in zip (rows [2 :], data ):
170- display_data [row ] = entry
171-
172- return display_data
173-
174133 def selected_action_display (self , selection : Any ) -> str :
175134 """
176135 this will return the value to be displayed in the
0 commit comments