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


				'''simple docstring'''






				def __init__(						self		,     lowercase = None		,     lowercase = [] ):



						"""simple docstring"""





						A_		:    Optional[int]         =				0
						A_		:    str         =				choices
						A_		:    Union[str, Any]         =				prompt
						if sys.platform == "win32":
								A_		:    Any         =				'*'
						else:
								A_		:    Any         =				'➔ '
				def   lowerCAmelCase_       (						self		,     lowercase		,     lowercase = "" ):



						"""simple docstring"""





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



						"""simple docstring"""





						if index == self.position:
								forceWrite(F''' {self.arrow_char} ''' )
								self.write_choice(lowercase )
						else:
								forceWrite(F'''    {self.choices[index]}''' )
						reset_cursor()
				def   lowerCAmelCase_       (						self		,     lowercase		,     lowercase = 1 ):



						"""simple docstring"""





						A_		:    Optional[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(lowercase )
						move_cursor(lowercase		,     direction.name )
						self.print_choice(self.position )
				@input.mark(KEYMAP['up'] )
				def   lowerCAmelCase_       (						self ):



						"""simple docstring"""





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



						"""simple docstring"""





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



						"""simple docstring"""





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



						"""simple docstring"""





						move_cursor(len(self.choices ) - self.position		,     'DOWN' )
						raise KeyboardInterrupt
				@input.mark_multiple(*[KEYMAP[str(lowercase )] for number in range(1_0 )] )
				def   lowerCAmelCase_       (						self ):



						"""simple docstring"""





						A_		:    int         =				int(chr(self.current_selection ) )
						A_		:    List[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		,     lowercase )
								else:
										return
						else:
								return







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







from ...utils import (
    OptionalDependencyNotAvailable,
    is_torch_available,
    is_transformers_available,
    is_transformers_version,
)


try:
	if not (is_transformers_available() and is_torch_available() and is_transformers_version(""">=""", """4.25.0""")):
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	from ...utils.dummy_torch_and_transformers_objects import UnCLIPImageVariationPipeline, UnCLIPPipeline
else:
	from .pipeline_unclip import UnCLIPPipeline
	from .pipeline_unclip_image_variation import UnCLIPImageVariationPipeline
	from .text_proj import UnCLIPTextProjModel






