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


_UpperCAmelCase :   Tuple			    =	False
try:
	_UpperCAmelCase :   List[Any]			    =	_is_package_available("""google.colab""")
except ModuleNotFoundError:
	pass

@input.register
class       UpperCAmelCase					:





		"""simple docstring"""





		def __init__(     self	,       _snake_case = None	,       _snake_case = []  )					->     str:
				_UpperCamelCase							:			Union[str, Any]     =   0
				_UpperCamelCase							:			Any     =   choices
				_UpperCamelCase							:			Union[str, Any]     =   prompt
				if sys.platform == "win32":
						_UpperCamelCase							:			Any     =   '''*'''
				else:
						_UpperCamelCase							:			str     =   '''➔ '''
		def _lowercase	(     self	,       _snake_case	,       _snake_case = ""  )					->     Optional[int]:



				if sys.platform != "win32":
						writeColor(self.choices[index]	,       32	,       lowercase__  )
				else:
						forceWrite(self.choices[index]	,       lowercase__  )
		def _lowercase	(     self	,       _snake_case  )					->     int:



				if index == self.position:
						forceWrite(F''' {self.arrow_char} '''  )
						self.write_choice(lowercase__  )
				else:
						forceWrite(F'''    {self.choices[index]}'''  )
				reset_cursor()
		def _lowercase	(     self	,       _snake_case	,       _snake_case = 1  )					->     int:
				_UpperCamelCase							:			int     =   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 _lowercase	(     self  )					->     int:
				self.move_direction(Direction.UP  )
		@input.mark(KEYMAP['''down''']  )
		def _lowercase	(     self  )					->     Optional[int]:
				self.move_direction(Direction.DOWN  )
		@input.mark(KEYMAP['''newline''']  )
		def _lowercase	(     self  )					->     List[Any]:
				move_cursor(len(self.choices  ) - self.position	,       '''DOWN'''  )
				return self.position
		@input.mark(KEYMAP['''interrupt''']  )
		def _lowercase	(     self  )					->     str:
				move_cursor(len(self.choices  ) - self.position	,       '''DOWN'''  )
				raise KeyboardInterrupt
		@input.mark_multiple(*[KEYMAP[str(lowercase__  )] for number in range(10  )]  )
		def _lowercase	(     self  )					->     Optional[int]:
				_UpperCamelCase							:			List[str]     =   int(chr(self.current_selection  )  )
				_UpperCamelCase							:			Dict     =   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 _lowercase	(     self	,       _snake_case = 0  )					->     Optional[Any]:



				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'''  )
				_UpperCamelCase							:			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:
												_UpperCamelCase							:			Optional[int]     =   int(builtins.input()  )
										except ValueError:
												_UpperCamelCase							:			List[Any]     =   default_choice
								else:
										_UpperCamelCase							:			List[str]     =   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 (
       VersatileDiffusionDualGuidedPipeline,
       VersatileDiffusionImageVariationPipeline,
       VersatileDiffusionPipeline,
       VersatileDiffusionTextToImagePipeline,
   )
else:
   from .modeling_text_unet import UNetFlatConditionModel
   from .pipeline_versatile_diffusion import VersatileDiffusionPipeline
   from .pipeline_versatile_diffusion_dual_guided import VersatileDiffusionDualGuidedPipeline
   from .pipeline_versatile_diffusion_image_variation import VersatileDiffusionImageVariationPipeline
   from .pipeline_versatile_diffusion_text_to_image import VersatileDiffusionTextToImagePipeline


