11import copy
2- from typing import TYPE_CHECKING , Any , cast
2+ from typing import TYPE_CHECKING , cast
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 [ValueT ]:
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 [ValueT | str ](
8180 group ,
82- header = header ,
81+ header = prompt ,
8382 search_enabled = False ,
8483 allow_skip = False ,
8584 alignment = Alignment .CENTER
@@ -109,25 +108,6 @@ def run(self) -> list[ValueT]:
109108 else :
110109 return self ._data
111110
112- def _get_header (self , data_formatted : dict [str , Any ]) -> str :
113- table_header = [key for key , val in data_formatted .items () if val is None ]
114- header = '\n ' .join (table_header )
115- return header
116-
117- def _prepare_selection (self , data_formatted : dict [str , Any ]) -> list [tuple [str , str | ValueT ]]:
118- # header rows are mapped to None so make sure
119- # to exclude those from the selectable data
120- options = [(key , val ) for key , val in data_formatted .items () if val is not None ]
121-
122- if len (options ) > 0 :
123- options .append ((self ._separator , None ))
124-
125- additional_options = self ._base_actions + self ._terminate_actions
126- for o in additional_options :
127- options .append ((o , o ))
128-
129- return options
130-
131111 def _run_actions_on_entry (self , entry : ValueT ) -> None :
132112 options = self .filter_options (entry , self ._sub_menu_actions ) + [self ._cancel_action ]
133113
@@ -153,27 +133,6 @@ def _run_actions_on_entry(self, entry: ValueT) -> None:
153133 if value != self ._cancel_action :
154134 self ._data = self .handle_action (value , entry , self ._data )
155135
156- def reformat (self , data : list [Any ]) -> dict [str , Any | None ]:
157- """
158- Default implementation of the table to be displayed.
159- Override if any custom formatting is needed
160- """
161- display_data : dict [str , Any | None ] = {}
162-
163- if data :
164- table = FormattedOutput .as_table (data )
165- rows = table .split ('\n ' )
166-
167- # these are the header rows of the table and do not map to any User obviously
168- # we're adding 2 spaces as prefix because the menu selector '> ' will be put before
169- # the selectable rows so the header has to be aligned
170- display_data = {f'{ rows [0 ]} ' : None , f'{ rows [1 ]} ' : None }
171-
172- for row , entry in zip (rows [2 :], data ):
173- display_data [row ] = entry
174-
175- return display_data
176-
177136 def selected_action_display (self , selection : ValueT ) -> str :
178137 """
179138 this will return the value to be displayed in the
0 commit comments