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      lowerCAmelCase						:



     def __init__(					self				,      lowerCAmelCase__ = None				,      lowerCAmelCase__ = []       ):
            _A=	0
            _A=	choices
            _A=	prompt
            if sys.platform == "win32":
                   _A=	'*'
            else:
                   _A=	'➔ '



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



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



     def 			a__  (					self				,      lowerCAmelCase__				,      lowerCAmelCase__ = 1       ):
            _A=	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 			a__  (					self       ):
            self.move_direction(Direction.UP       )



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



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



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



     @input.mark_multiple(*[KEYMAP[str(lowerCAmelCase__       )] for number in range(10       )]       )
     def 			a__  (					self       ):
            _A=	int(chr(self.current_selection       )       )
            _A=	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 			a__  (					self				,      lowerCAmelCase__ = 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=	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:
                                        _A=	int(builtins.input()       )
                                 except ValueError:
                                        _A=	default_choice
                          else:
                                 _A=	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
from typing import TYPE_CHECKING

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


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

try:
      if not is_torch_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      UpperCAmelCase_								=							[
          '''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

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