




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


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






@input.register
class       lowercase:







 '''simple docstring'''





 def __init__(       self:	Dict,   a_:	str = None,   a_:	list = []	):




   '''simple docstring'''



   _snake_case							:	Optional[int]			=						0
   _snake_case							:	int			=						choices
   _snake_case							:	Optional[int]			=						prompt
   if sys.platform == "win32":
     _snake_case							:	Any			=						"""*"""
   else:
     _snake_case							:	List[str]			=						"""➔ """


 def 				UpperCamelCase_     (       self:	List[str],   a_:	Optional[int],   a_:	str = ""	):




   '''simple docstring'''



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


 def 				UpperCamelCase_     (       self:	List[str],   a_:	int	):




   '''simple docstring'''



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


 def 				UpperCamelCase_     (       self:	Optional[Any],   a_:	Direction,   a_:	int = 1	):




   '''simple docstring'''



   _snake_case							:	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(a_	)
   move_cursor(a_,   direction.name	)
   self.print_choice(self.position	)


 @input.mark(KEYMAP["""up"""]	)
 def 				UpperCamelCase_     (       self:	Dict	):




   '''simple docstring'''



   self.move_direction(Direction.UP	)


 @input.mark(KEYMAP["""down"""]	)
 def 				UpperCamelCase_     (       self:	Optional[int]	):




   '''simple docstring'''



   self.move_direction(Direction.DOWN	)


 @input.mark(KEYMAP["""newline"""]	)
 def 				UpperCamelCase_     (       self:	Tuple	):




   '''simple docstring'''



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


 @input.mark(KEYMAP["""interrupt"""]	)
 def 				UpperCamelCase_     (       self:	Optional[Any]	):




   '''simple docstring'''



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


 @input.mark_multiple(*[KEYMAP[str(a_	)] for number in range(10	)]	)
 def 				UpperCamelCase_     (       self:	Any	):




   '''simple docstring'''



   _snake_case							:	Any			=						int(chr(self.current_selection	)	)
   _snake_case							:	Optional[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,   a_	)
     else:
       return
   else:
     return


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








"""simple docstring"""


from typing import Any


def       UpperCAmelCase__ (snake_case__							:      list					):
  """simple docstring"""

  if not input_list:
    return []
  _snake_case							:	List[Any]			=						[input_list.count(snake_case__					) for value in input_list]
  _snake_case							:	Optional[int]			=						max(snake_case__					)  # Gets the maximum count in the input list.
  # Gets values of modes
  return sorted({input_list[i] for i, value in enumerate(snake_case__					) if value == y}					)


if __name__ == "__main__":
     import doctest

     doctest.testmod()


