add: menu doesn't clear the terminal now

This commit is contained in:
starnakin 2023-05-27 16:03:10 +02:00
parent 2ce33db8e2
commit a76c484116

18
Menu.py
View File

@ -19,6 +19,7 @@ class Menu():
self.skip_empty_option = skip_empty_option;
self.size = len(options)
self.preview_ratio = preview_ratio;
self._nb_printed_lines = 0;
def _up(self):
if (self.circular == False):
@ -65,9 +66,11 @@ class Menu():
elif (key == "right"):
self._right()
elif (key == "enter"):
self._clear();
return (self.cursor_pos)
def _display_menu(self):
menu: str = "";
self._clear();
size = os.get_terminal_size();
size_x = size.columns;
@ -93,8 +96,9 @@ class Menu():
line = self.cursor + element[min_x:max_x]
else:
line = " " * len(self.cursor) + element
print(line)
print(preview)
line = line + "\n"
menu = menu + line;
self._display_screen(menu + preview)
def _preview(self):
if (len(self.preview_args) < self.cursor_pos):
@ -108,7 +112,15 @@ class Menu():
def _clear(self):
os.system("clear")
UP = "\x1B[3A"
CLR = "\x1B[0K"
for i in range(self._nb_printed_lines):
print(CLR)
print(UP)
def _display_screen(self, screen: str):
print(screen)
self._nb_printed_lines = screen.count("\n") + 1
def _get_input(self) -> str:
flag_have_getch = False