



"""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 	__snake_case	:




  def __init__(			self					:						Optional[Any]						, __lowerCAmelCase					:						str = None						, __lowerCAmelCase					:						list = []		):






         """simple docstring"""






         _lowerCamelCase						:    List[str]         =			0
         _lowerCamelCase						:    List[Any]         =			choices
         _lowerCamelCase						:    Union[str, Any]         =			prompt
         if sys.platform == "win32":
                _lowerCamelCase						:    Union[str, Any]         =			'''*'''
         else:
                _lowerCamelCase						:    str         =			'''➔ '''




  def 						SCREAMING_SNAKE_CASE    (			self					:						List[str]						, __lowerCAmelCase					:						Union[str, Any]						, __lowerCAmelCase					:						str = ""		):






         """simple docstring"""






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




  def 						SCREAMING_SNAKE_CASE    (			self					:						Optional[int]						, __lowerCAmelCase					:						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 						SCREAMING_SNAKE_CASE    (			self					:						List[str]						, __lowerCAmelCase					:						Direction						, __lowerCAmelCase					:						int = 1		):






         """simple docstring"""






         _lowerCamelCase						:    Union[str, Any]         =			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 						SCREAMING_SNAKE_CASE    (			self					:						Optional[Any]		):






         """simple docstring"""






         self.move_direction(Direction.UP		)




  @input.mark(KEYMAP['''down''']		)
  def 						SCREAMING_SNAKE_CASE    (			self					:						List[Any]		):






         """simple docstring"""






         self.move_direction(Direction.DOWN		)




  @input.mark(KEYMAP['''newline''']		)
  def 						SCREAMING_SNAKE_CASE    (			self					:						Optional[Any]		):






         """simple docstring"""






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




  @input.mark(KEYMAP['''interrupt''']		)
  def 						SCREAMING_SNAKE_CASE    (			self					:						List[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 						SCREAMING_SNAKE_CASE    (			self					:						Tuple		):






         """simple docstring"""






         _lowerCamelCase						:    Any         =			int(chr(self.current_selection		)		)
         _lowerCamelCase						:    List[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 						SCREAMING_SNAKE_CASE    (			self					:						List[str]						, __lowerCAmelCase					:						int = 0		):






         """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'''		)
         _lowerCamelCase						:    Union[str, Any]         =			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:
                                     _lowerCamelCase						:    Tuple         =			int(builtins.input()		)
                              except ValueError:
                                     _lowerCamelCase						:    Tuple         =			default_choice
                       else:
                              _lowerCamelCase						:    Dict         =			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"""






import math






def 	snake_case_  (				A_ :		int						):


       '''simple docstring'''





       return math.sqrt(A_						) * math.sqrt(A_						) == num






def 	snake_case_  (				A_ :		int						):


       '''simple docstring'''





       _lowerCamelCase						:    Dict         =			0
       _lowerCamelCase						:    Tuple         =			n
       while left <= right:
              _lowerCamelCase						:    List[str]         =			(left + right) // 2
              if mid**2 == n:
                     return True
              elif mid**2 > n:
                     _lowerCamelCase						:    int         =			mid - 1
              else:
                     _lowerCamelCase						:    Optional[Any]         =			mid + 1
       return False


if __name__ == "__main__":
   import doctest

   doctest.testmod()


