6 from typing
import Dict, List, Set, Tuple
8 from AthenaConfiguration.iconfTool.models.element
import (
12 from AthenaConfiguration.iconfTool.models.structure
import ComponentsStructure
14 logger = logging.getLogger(__name__)
19 "Can not init textGUI, probably wrong terminal. Try setting export TERM=xterm-256color"
27 data_structure: ComponentsStructure,
32 self.
structure: ComponentsStructure = data_structure
37 self.width: int = width
38 self.start_x: int = start_x
39 self.MAX_PAD_HEIGHT: int = 32000
40 self.
pad = curses.newpad(self.MAX_PAD_HEIGHT, width)
42 self.pad_height: int = height - 1
44 self.mark_character: str =
" "
46 self.
lines: List[Element] = []
62 1, curses.COLOR_BLACK, curses.COLOR_WHITE
64 highlighted = curses.color_pair(1)
65 normal = curses.A_NORMAL
66 curses.init_pair(3, curses.COLOR_GREEN, curses.COLOR_BLACK)
67 marked = curses.color_pair(3)
70 "highlighted": highlighted,
74 def reload_data(self, data_structure: ComponentsStructure) ->
None:
89 curses.setsyx(self.
actual_y, element.x_pos + 1)
93 element.get_mark_character(),
94 self.
styles[
"highlighted"],
102 """start_y - starting vertical position where elements will be drawn"""
103 style = self.
styles[
"marked" if structure.is_marked()
else "normal"]
105 f
"Adding str: x:{structure.x_pos}, y:{start_y}/{self.MAX_PAD_HEIGHT}"
111 structure.get_line(),
114 except Exception
as e:
116 f
"Error {e} loading str y:{start_y}, x: {structure.x_pos}"
118 self.
lines.insert(start_y, structure)
120 if isinstance(structure, GroupingElement)
and structure.show_children:
121 for child
in structure.children:
122 if start_y < self.MAX_PAD_HEIGHT:
126 f
"Too many structures: {start_y}. Max count: {self.MAX_PAD_HEIGHT}"
134 if start_y >= self.MAX_PAD_HEIGHT:
146 self.width + self.start_x - 2,
148 cursor_pos = curses.getsyx()
149 curses.setsyx(cursor_pos[0],
int(cursor_pos[1] - self.start_x))
152 return len(self.
lines) == 0
158 def redraw(self, reinit_cursor: bool =
False) ->
None:
159 cursor_pos = curses.getsyx()
164 if reinit_cursor
or cursor_pos[1] == 0:
170 f
"y: {self.actual_y}, lines length: {len(self.lines)}"
177 element.get_mark_character(),
178 self.
styles[
"highlighted"],
190 for element
in self.
lines:
191 if text
in element.get_name()
and not element.is_checked():
192 element.set_as_checked()
200 current_character = chr(
201 int(self.
pad.inch(y, x)) & 0xFF
203 return current_character
214 cursor_pos = curses.getsyx()
227 cursor_pos = curses.getsyx()
235 self.
styles[
"highlighted"],
241 cursor_pos = curses.getsyx()
249 self.
styles[
"highlighted"],
274 for index, element
in enumerate(self.
lines):
275 if element.parent
is None and element.name == name:
282 cursor_pos = curses.getsyx()
283 if cursor_pos[0] > self.pad_height - 4:
287 if len(self.
lines) == 0:
291 cursor_pos = curses.getsyx()
299 if isinstance(element, GroupingElement):
300 self.
structure.replace_references(element)
301 element.show_children =
True
313 and element.get_reference_name()
314 not in self.
structure.filter.comps_to_save
315 and element.get_reference_name()
in self.
structure.roots_dict
318 f
"Skipped expanding for: {element.get_reference_name()}"
321 if isinstance(element, GroupingElement):
322 self.
structure.replace_references(element)
323 element.show_children =
True
324 for child
in element.children:
331 if isinstance(element, GroupingElement):
332 element.show_children =
False
342 if isinstance(element, GroupingElement):
343 element.show_children =
False
344 for child
in element.children:
350 element.set_as_unchecked()
351 self.
structure.remove_from_checked(element)
353 element.set_as_checked()
358 if event == curses.KEY_DOWN:
360 elif event == curses.KEY_UP:
362 elif event == curses.KEY_RIGHT:
364 elif event == curses.KEY_LEFT:
366 elif event == ord(
" "):