






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							:   Optional[int]							=  False
try:
	__UpperCAmelCase							:   str							=  _is_package_available("google.colab")
except ModuleNotFoundError:
	pass


@input.register
class 					_snake_case						:






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






	def    lowerCAmelCase_							(		self					,UpperCamelCase					,UpperCamelCase = ""       )						->    Optional[Any]:
					if sys.platform != "win32":
									writeColor(self.choices[index]					,32					,UpperCamelCase       )
					else:
									forceWrite(self.choices[index]					,UpperCamelCase       )






	def    lowerCAmelCase_							(		self					,UpperCamelCase       )						->    int:
					if index == self.position:
									forceWrite(f' {self.arrow_char} '       )
									self.write_choice(UpperCamelCase       )
					else:
									forceWrite(f'    {self.choices[index]}'       )
					reset_cursor()






	def    lowerCAmelCase_							(		self					,UpperCamelCase					,UpperCamelCase = 1       )						->    Tuple:
					snake_case__      :Tuple         =   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(UpperCamelCase       )
					move_cursor(UpperCamelCase					,direction.name       )
					self.print_choice(self.position       )






	@input.mark(KEYMAP["up"]       )
	def    lowerCAmelCase_							(		self       )						->    int:
					self.move_direction(Direction.UP       )






	@input.mark(KEYMAP["down"]       )
	def    lowerCAmelCase_							(		self       )						->    int:
					self.move_direction(Direction.DOWN       )






	@input.mark(KEYMAP["newline"]       )
	def    lowerCAmelCase_							(		self       )						->    Any:
					move_cursor(len(self.choices       ) - self.position					,"DOWN"       )
					return self.position






	@input.mark(KEYMAP["interrupt"]       )
	def    lowerCAmelCase_							(		self       )						->    Any:
					move_cursor(len(self.choices       ) - self.position					,"DOWN"       )
					raise KeyboardInterrupt






	@input.mark_multiple(*[KEYMAP[str(UpperCamelCase       )] for number in range(10       )]       )
	def    lowerCAmelCase_							(		self       )						->    Union[str, Any]:
					snake_case__      :List[Any]         =   int(chr(self.current_selection       )       )
					snake_case__      :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					,UpperCamelCase       )
									else:
													return
					else:
									return






	def    lowerCAmelCase_							(		self					,UpperCamelCase = 0       )						->    int:
					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(UpperCamelCase       )
									forceWrite("\n"       )
					move_cursor(len(self.choices       ) - self.position					,"UP"       )
					with cursor.hide():
									while True:
													if in_colab:
																	try:
																					snake_case__      :Dict         =   int(builtins.input()       )
																	except ValueError:
																					snake_case__      :Dict         =   default_choice
													else:
																	snake_case__      :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(UpperCamelCase					,"\n"       )
																	return choice







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


try:
	if not (is_transformers_available() and is_torch_available()):
		raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
	from ...utils.dummy_torch_and_transformers_objects import *  # noqa F403
else:
	from .multicontrolnet import MultiControlNetModel
	from .pipeline_controlnet import StableDiffusionControlNetPipeline
	from .pipeline_controlnet_imgaimg import StableDiffusionControlNetImgaImgPipeline
	from .pipeline_controlnet_inpaint import StableDiffusionControlNetInpaintPipeline


if is_transformers_available() and is_flax_available():
	from .pipeline_flax_controlnet import FlaxStableDiffusionControlNetPipeline