2021.4.1 #11
@ -1,4 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
from collections import Callable
|
from collections import Callable
|
||||||
from typing import Union, Optional
|
from typing import Union, Optional
|
||||||
|
|
||||||
@ -148,7 +150,7 @@ class Console:
|
|||||||
"""
|
"""
|
||||||
if not cls._is_first_select_menu_output:
|
if not cls._is_first_select_menu_output:
|
||||||
for _ in range(0, len(cls._select_menu_items) + 1):
|
for _ in range(0, len(cls._select_menu_items) + 1):
|
||||||
print('\b', end="\r")
|
sys.stdout.write('\x1b[1A\x1b[2K')
|
||||||
else:
|
else:
|
||||||
cls._is_first_select_menu_output = False
|
cls._is_first_select_menu_output = False
|
||||||
|
|
||||||
@ -159,7 +161,8 @@ class Console:
|
|||||||
for _ in cls._selected_menu_item_char:
|
for _ in cls._selected_menu_item_char:
|
||||||
placeholder += ' '
|
placeholder += ' '
|
||||||
|
|
||||||
Console.write_line(f'{cls._selected_menu_item_char if cls._selected_menu_item_index == i else placeholder} ')
|
Console.write_line(
|
||||||
|
f'{cls._selected_menu_item_char if cls._selected_menu_item_index == i else placeholder} ')
|
||||||
Console.set_foreground_color(cls._selected_menu_option_foreground_color)
|
Console.set_foreground_color(cls._selected_menu_option_foreground_color)
|
||||||
Console.set_background_color(cls._selected_menu_option_background_color)
|
Console.set_background_color(cls._selected_menu_option_background_color)
|
||||||
Console.write(f'{cls._select_menu_items[i]}')
|
Console.write(f'{cls._select_menu_items[i]}')
|
||||||
@ -373,7 +376,7 @@ class Console:
|
|||||||
|
|
||||||
Console.set_foreground_color(header_foreground_color)
|
Console.set_foreground_color(header_foreground_color)
|
||||||
Console.set_background_color(header_background_color)
|
Console.set_background_color(header_background_color)
|
||||||
Console.write_line(message)
|
Console.write_line(message, '\n')
|
||||||
cls._show_select_menu()
|
cls._show_select_menu()
|
||||||
|
|
||||||
with keyboard.Listener(
|
with keyboard.Listener(
|
||||||
@ -434,10 +437,11 @@ class Console:
|
|||||||
return return_value
|
return return_value
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def write(cls, *args):
|
def write(cls, *args, end=''):
|
||||||
"""
|
"""
|
||||||
Prints in active line
|
Prints in active line
|
||||||
:param args:
|
:param args:
|
||||||
|
:param end:
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
if cls._disabled:
|
if cls._disabled:
|
||||||
@ -448,7 +452,7 @@ class Console:
|
|||||||
return
|
return
|
||||||
|
|
||||||
string = ' '.join(map(str, args))
|
string = ' '.join(map(str, args))
|
||||||
cls._output(string, end='')
|
cls._output(string, end=end)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def write_at(cls, x: int, y: int, *args):
|
def write_at(cls, x: int, y: int, *args):
|
||||||
|
@ -58,7 +58,10 @@ class SpinnerThread(threading.Thread):
|
|||||||
rows, columns = os.popen('stty size', 'r').read().split()
|
rows, columns = os.popen('stty size', 'r').read().split()
|
||||||
end_msg = 'done'
|
end_msg = 'done'
|
||||||
columns = int(columns) - self._msg_len - len(end_msg)
|
columns = int(columns) - self._msg_len - len(end_msg)
|
||||||
|
if columns > 0:
|
||||||
print(f'{"" : >{columns}}', end='')
|
print(f'{"" : >{columns}}', end='')
|
||||||
|
else:
|
||||||
|
print('', end='')
|
||||||
spinner = self._spinner()
|
spinner = self._spinner()
|
||||||
while self._is_spinning:
|
while self._is_spinning:
|
||||||
print(colored(f'{next(spinner): >{len(end_msg)}}', *self._get_color_args()), end='')
|
print(colored(f'{next(spinner): >{len(end_msg)}}', *self._get_color_args()), end='')
|
||||||
|
@ -7,7 +7,7 @@ def test_spinner():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
Console.write_line('Hello World')
|
Console.write_line('Hello World\n')
|
||||||
Console.spinner('Test:', test_spinner, spinner_foreground_color=ForegroundColorEnum.cyan, text_foreground_color='green')
|
Console.spinner('Test:', test_spinner, spinner_foreground_color=ForegroundColorEnum.cyan, text_foreground_color='green')
|
||||||
opts = [
|
opts = [
|
||||||
'Option 1',
|
'Option 1',
|
||||||
@ -23,4 +23,4 @@ if __name__ == '__main__':
|
|||||||
option_foreground_color=ForegroundColorEnum.green,
|
option_foreground_color=ForegroundColorEnum.green,
|
||||||
cursor_foreground_color=ForegroundColorEnum.red
|
cursor_foreground_color=ForegroundColorEnum.red
|
||||||
)
|
)
|
||||||
Console.write_line(f'You selected: {selected}')
|
Console.write_line(f'You selected: {selected}\n')
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
"LicenseName": "",
|
"LicenseName": "",
|
||||||
"LicenseDescription": "",
|
"LicenseDescription": "",
|
||||||
"Dependencies": [
|
"Dependencies": [
|
||||||
"sh_cpl==2021.4.1.post5"
|
"sh_cpl==2021.4.1.post7"
|
||||||
],
|
],
|
||||||
"PythonVersion": ">=3.9.2",
|
"PythonVersion": ">=3.9.2",
|
||||||
"Classifiers": []
|
"Classifiers": []
|
||||||
|
Loading…
Reference in New Issue
Block a user