





"""simple docstring"""




import builtins
import sys

from ...utils.imports import _is_package_available
from . import cursor, input
from .helpers import Direction, clear_line, forceWrite, linebreak, move_cursor, reset_cursor, writeColor
from .keymap import KEYMAP


UpperCamelCase_									=False
try:
						UpperCamelCase_									=_is_package_available("""google.colab""")
except ModuleNotFoundError:
						pass




@input.register
class 			_a						:






				def __init__(			self		:   int,			lowerCAmelCase__		:   str = None,			lowerCAmelCase__		:   list = []							)     ->				Optional[int]:




										'''simple docstring'''



										_UpperCamelCase      : List[Any]         =   0
										_UpperCamelCase      : Optional[Any]         =   choices
										_UpperCamelCase      : Optional[Any]         =   prompt
										if sys.platform == "win32":
																_UpperCamelCase      : Tuple         =   '''*'''
										else:
																_UpperCamelCase      : Tuple         =   '''➔ '''






				def     snake_case     (			self		:   Tuple,			lowerCAmelCase__		:   List[Any],			lowerCAmelCase__		:   str = ""							)     ->				Tuple:




										'''simple docstring'''



										if sys.platform != "win32":
																writeColor(self.choices[index],			3_2,			lowerCAmelCase__							)
										else:
																forceWrite(self.choices[index],			lowerCAmelCase__							)






				def     snake_case     (			self		:   Union[str, Any],			lowerCAmelCase__		:   int							)     ->				int:




										'''simple docstring'''



										if index == self.position:
																forceWrite(f""" {self.arrow_char} """							)
																self.write_choice(lowerCAmelCase__							)
										else:
																forceWrite(f"""    {self.choices[index]}"""							)
										reset_cursor()






				def     snake_case     (			self		:   Dict,			lowerCAmelCase__		:   Direction,			lowerCAmelCase__		:   int = 1							)     ->				str:




										'''simple docstring'''



										_UpperCamelCase      : int         =   self.position
										if direction == Direction.DOWN:
																if self.position + 1 >= len(self.choices							):
																						return
																self.position += num_spaces
										else:
																if self.position - 1 < 0:
																						return
																self.position -= num_spaces
										clear_line()
										self.print_choice(lowerCAmelCase__							)
										move_cursor(lowerCAmelCase__,			direction.name							)
										self.print_choice(self.position							)






				@input.mark(KEYMAP['''up''']							)
				def     snake_case     (			self		:   Optional[int]							)     ->				List[str]:




										'''simple docstring'''



										self.move_direction(Direction.UP							)






				@input.mark(KEYMAP['''down''']							)
				def     snake_case     (			self		:   Optional[int]							)     ->				List[Any]:




										'''simple docstring'''



										self.move_direction(Direction.DOWN							)






				@input.mark(KEYMAP['''newline''']							)
				def     snake_case     (			self		:   Union[str, Any]							)     ->				str:




										'''simple docstring'''



										move_cursor(len(self.choices							) - self.position,			'''DOWN'''							)
										return self.position






				@input.mark(KEYMAP['''interrupt''']							)
				def     snake_case     (			self		:   List[str]							)     ->				Optional[Any]:




										'''simple docstring'''



										move_cursor(len(self.choices							) - self.position,			'''DOWN'''							)
										raise KeyboardInterrupt






				@input.mark_multiple(*[KEYMAP[str(lowerCAmelCase__							)] for number in range(1_0							)]							)
				def     snake_case     (			self		:   List[str]							)     ->				Any:




										'''simple docstring'''



										_UpperCamelCase      : Any         =   int(chr(self.current_selection							)							)
										_UpperCamelCase      : Any         =   index - self.position
										if index == self.position:
																return
										if index < len(self.choices							):
																if self.position > index:
																						self.move_direction(Direction.UP,			-movement							)
																elif self.position < index:
																						self.move_direction(Direction.DOWN,			lowerCAmelCase__							)
																else:
																						return
										else:
																return






				def     snake_case     (			self		:   Optional[Any],			lowerCAmelCase__		:   int = 0							)     ->				Union[str, Any]:




										'''simple docstring'''



										if self.prompt:
																linebreak()
																forceWrite(self.prompt,			'''\n'''							)
																if in_colab:
																						forceWrite('''Please input a choice index (starting from 0), and press enter''',			'''\n'''							)
																else:
																						forceWrite('''Please select a choice using the arrow or number keys, and selecting with enter''',			'''\n'''							)
										_UpperCamelCase      : List[str]         =   default_choice
										for i in range(len(self.choices							)							):
																self.print_choice(lowerCAmelCase__							)
																forceWrite('''\n'''							)
										move_cursor(len(self.choices							) - self.position,			'''UP'''							)
										with cursor.hide():
																while True:
																						if in_colab:
																												try:
																																		_UpperCamelCase      : str         =   int(builtins.input()							)
																												except ValueError:
																																		_UpperCamelCase      : List[str]         =   default_choice
																						else:
																												_UpperCamelCase      : Optional[Any]         =   self.handle_input()
																						if choice is not None:
																												reset_cursor()
																												for _ in range(len(self.choices							) + 1							):
																																		move_cursor(1,			'''UP'''							)
																																		clear_line()
																												self.write_choice(lowerCAmelCase__,			'''\n'''							)
																												return choice













"""simple docstring"""




UpperCamelCase_									=[
    """DownloadConfig""",
    """DownloadManager""",
    """DownloadMode""",
    """StreamingDownloadManager""",
]

from .download_config import DownloadConfig
from .download_manager import DownloadManager, DownloadMode
from .streaming_download_manager import StreamingDownloadManager



