add: menu doesn't clear the terminal now
This commit is contained in:
parent
2ce33db8e2
commit
a76c484116
18
Menu.py
18
Menu.py
@ -19,6 +19,7 @@ class Menu():
|
|||||||
self.skip_empty_option = skip_empty_option;
|
self.skip_empty_option = skip_empty_option;
|
||||||
self.size = len(options)
|
self.size = len(options)
|
||||||
self.preview_ratio = preview_ratio;
|
self.preview_ratio = preview_ratio;
|
||||||
|
self._nb_printed_lines = 0;
|
||||||
|
|
||||||
def _up(self):
|
def _up(self):
|
||||||
if (self.circular == False):
|
if (self.circular == False):
|
||||||
@ -65,9 +66,11 @@ class Menu():
|
|||||||
elif (key == "right"):
|
elif (key == "right"):
|
||||||
self._right()
|
self._right()
|
||||||
elif (key == "enter"):
|
elif (key == "enter"):
|
||||||
|
self._clear();
|
||||||
return (self.cursor_pos)
|
return (self.cursor_pos)
|
||||||
|
|
||||||
def _display_menu(self):
|
def _display_menu(self):
|
||||||
|
menu: str = "";
|
||||||
self._clear();
|
self._clear();
|
||||||
size = os.get_terminal_size();
|
size = os.get_terminal_size();
|
||||||
size_x = size.columns;
|
size_x = size.columns;
|
||||||
@ -93,8 +96,9 @@ class Menu():
|
|||||||
line = self.cursor + element[min_x:max_x]
|
line = self.cursor + element[min_x:max_x]
|
||||||
else:
|
else:
|
||||||
line = " " * len(self.cursor) + element
|
line = " " * len(self.cursor) + element
|
||||||
print(line)
|
line = line + "\n"
|
||||||
print(preview)
|
menu = menu + line;
|
||||||
|
self._display_screen(menu + preview)
|
||||||
|
|
||||||
def _preview(self):
|
def _preview(self):
|
||||||
if (len(self.preview_args) < self.cursor_pos):
|
if (len(self.preview_args) < self.cursor_pos):
|
||||||
@ -108,7 +112,15 @@ class Menu():
|
|||||||
|
|
||||||
|
|
||||||
def _clear(self):
|
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:
|
def _get_input(self) -> str:
|
||||||
flag_have_getch = False
|
flag_have_getch = False
|
||||||
|
Loading…
Reference in New Issue
Block a user