



'''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


__lowerCAmelCase		     =  False
try:
							__lowerCAmelCase		     =  _is_package_available('''google.colab''')
except ModuleNotFoundError:
							pass

@input.register
class       __magic_name__		:







							def __init__(				self   :			List[str]      ,_UpperCAmelCase   :			str = None      ,_UpperCAmelCase   :			list = []						):
									_a	: Tuple								=				0
									_a	: List[Any]								=				choices
									_a	: Union[str, Any]								=				prompt
									if sys.platform == "win32":
											_a	: int								=				'*'
									else:
											_a	: Dict								=				'➔ '







							def 				__lowercase     (				self   :			Union[str, Any]      ,_UpperCAmelCase   :			Any      ,_UpperCAmelCase   :			str = ""						):
									if sys.platform != "win32":
											writeColor(self.choices[index]      ,32      ,_UpperCAmelCase						)
									else:
											forceWrite(self.choices[index]      ,_UpperCAmelCase						)







							def 				__lowercase     (				self   :			List[Any]      ,_UpperCAmelCase   :			int						):
									if index == self.position:
											forceWrite(F""" {self.arrow_char} """						)
											self.write_choice(_UpperCAmelCase						)
									else:
											forceWrite(F"""    {self.choices[index]}"""						)
									reset_cursor()







							def 				__lowercase     (				self   :			List[str]      ,_UpperCAmelCase   :			Direction      ,_UpperCAmelCase   :			int = 1						):
									_a	: str								=				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(_UpperCAmelCase						)
									move_cursor(_UpperCAmelCase      ,direction.name						)
									self.print_choice(self.position						)







							@input.mark(KEYMAP['up']						)
							def 				__lowercase     (				self   :			Optional[int]						):
									self.move_direction(Direction.UP						)







							@input.mark(KEYMAP['down']						)
							def 				__lowercase     (				self   :			Optional[Any]						):
									self.move_direction(Direction.DOWN						)







							@input.mark(KEYMAP['newline']						)
							def 				__lowercase     (				self   :			Optional[Any]						):
									move_cursor(len(self.choices						) - self.position      ,'DOWN'						)
									return self.position







							@input.mark(KEYMAP['interrupt']						)
							def 				__lowercase     (				self   :			Tuple						):
									move_cursor(len(self.choices						) - self.position      ,'DOWN'						)
									raise KeyboardInterrupt







							@input.mark_multiple(*[KEYMAP[str(_UpperCAmelCase						)] for number in range(10						)]						)
							def 				__lowercase     (				self   :			Any						):
									_a	: Dict								=				int(chr(self.current_selection						)						)
									_a	: str								=				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      ,_UpperCAmelCase						)
											else:
													return
									else:
											return







							def 				__lowercase     (				self   :			Optional[int]      ,_UpperCAmelCase   :			int = 0						):
									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'						)
									_a	: Union[str, Any]								=				default_choice
									for i in range(len(self.choices						)						):
											self.print_choice(_UpperCAmelCase						)
											forceWrite('\n'						)
									move_cursor(len(self.choices						) - self.position      ,'UP'						)
									with cursor.hide():
											while True:
													if in_colab:
															try:
																	_a	: Union[str, Any]								=				int(builtins.input()						)
															except ValueError:
																	_a	: Optional[Any]								=				default_choice
													else:
															_a	: Union[str, 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(_UpperCAmelCase      ,'\n'						)
															return choice









'''simple docstring'''

from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tensorflow_text_available, is_torch_available


__lowerCAmelCase		     =  {
    '''configuration_ernie''': ['''ERNIE_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''ErnieConfig''', '''ErnieOnnxConfig'''],
}

try:
							if not is_torch_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							__lowerCAmelCase		     =  [
							    '''ERNIE_PRETRAINED_MODEL_ARCHIVE_LIST''',
							    '''ErnieForCausalLM''',
							    '''ErnieForMaskedLM''',
							    '''ErnieForMultipleChoice''',
							    '''ErnieForNextSentencePrediction''',
							    '''ErnieForPreTraining''',
							    '''ErnieForQuestionAnswering''',
							    '''ErnieForSequenceClassification''',
							    '''ErnieForTokenClassification''',
							    '''ErnieModel''',
							    '''ErniePreTrainedModel''',
							]

if TYPE_CHECKING:
							from .configuration_ernie import ERNIE_PRETRAINED_CONFIG_ARCHIVE_MAP, ErnieConfig, ErnieOnnxConfig

							try:
														if not is_torch_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_ernie import (
														    ERNIE_PRETRAINED_MODEL_ARCHIVE_LIST,
														    ErnieForCausalLM,
														    ErnieForMaskedLM,
														    ErnieForMultipleChoice,
														    ErnieForNextSentencePrediction,
														    ErnieForPreTraining,
														    ErnieForQuestionAnswering,
														    ErnieForSequenceClassification,
														    ErnieForTokenClassification,
														    ErnieModel,
														    ErniePreTrainedModel,
														)

else:
							import sys

							__lowerCAmelCase		     =  _LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)




